HyPhy message board | |
http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl
Methodology Questions >> How to >> strcat, strcpy etc? http://www.hyphy.org/cgi-bin/hyphy_forums/YaBB.pl?num=1169582947 Message started by wdelport on Jan 23rd, 2007 at 12:09pm |
Title: strcat, strcpy etc? Post by wdelport on Jan 23rd, 2007 at 12:09pm
Hi, this may seem a little off the topic but does the batch language allow for commands like strcat, strcat, printf etc. For instance I want to parition data according to a consensus amino acid sequence. So I have the consensus amino acid sequence in a {site x amino acid} matrix as follows:
{ { 0, 1, 2, 3, 4}, { 14, 2, 5, 14, 5} } which i can sort by column 1 to: { { 1, 2, 4, 0, 3 }, { 2, 5, 5, 14, 14 } } so using a for and while loop i can identify which sites all have the same consensus amino acid. ie. site 1, sites 2 & 4, sites 0 & 3. Now I want to create filters for each consensus amino acid (each of which will get a separate model). So some way of doing: DataSetFilter myFilter1 = CreateFilter ( myData, 1, "1" ); /* AA 2 */ DataSetFilter myFilter2 = CreateFilter ( myData, 1, "2,4" ); /* AA 5 */ DataSetFilter myFilter3 = CreateFilter ( myData, 1, "0,3" ); /* AA 14 */ So I thought a for loop that will concatenate values in a matrix as a string, where the matrix is only retained for each AA. ie for AA 5 matrix = { 2, 4 } stringVar = ""; for ( i = 0; i < k; i = i + 1 ) { /* k is the number of sites with AA 5 */ strcat ( stringVar, matrix [ i ] ); if ( i != k-1 ) { strcat ( stringVar, ", " ); } } and then theoretically i can call this string with the CreateFilter? DataSetFilter myFilter2 = CreateFilter ( myData, 1, stringVar ); /* AA 5 */ and finally the other problem would be how to index the myFilter in a forward loop...myFilter1, myFilter2, .... for 20 amino acids. i am pretty new to both HyPhy and the batch language so please let me know if i'm completely off the wall with this ?. thanks ./w :o |
Title: Re: strcat, strcpy etc? Post by Sergei on Jan 23rd, 2007 at 12:25pm
For strings, the '+' operation will concatenate the strings. A more efficient way to do this is to create a "buffer" string like this
Code (] stringBuffer = ""; /* declare as string */ stringBuffer * 128; /* mark as buffer string, i.e. it will autogrow as stuff is pushed on it */ stringBuffer * ("some text"); stringBuffer * ("some more text"); ... stringBuffer * 0; /* complete the buffering; free unused memory and such */ [/code):
What this will do is evaluate the expression indexMat[1][siteIndex]==14 for every siteIndex from 0 to myData.sites-1, and put all sites for which the expression is true (>0) into the filter. HTH, Sergei |
Title: Re: strcat, strcpy etc? Post by wdelport on Jan 23rd, 2007 at 6:57pm
thanks Sergei, your reply is once again informative and helpful. your efforts are really appreciated. cheers ./w
|
HyPhy message board » Powered by YaBB 2.5.2! YaBB Forum Software © 2000-2024. All Rights Reserved. |