Welcome, Guest. Please Login
YaBB - Yet another Bulletin Board
 
  HomeHelpSearchLogin  
 
strcat, strcpy etc? (Read 1968 times)
wayne
Global Moderator
*****
Offline


I love YaBB 1G - SP1!

Posts: 57
San Diego, CA
Gender: male
strcat, strcpy etc?
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 Shocked
Back to top
 

Assistant Project Scientist&&Antiviral Research Center&&Department of Pathology&&University of California, San Diego
WWW WWW  
IP Logged
 
Sergei
YaBB Administrator
*****
Offline


Datamonkeys are forever...

Posts: 1658
UCSD
Gender: male
Re: strcat, strcpy etc?
Reply #1 - 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 */

 



Still, for what you do, a more efficient way to create the filter is to use something like this. Suppose 'indexMat' holds the amino-acid value in the consensus at the that position (row 2 in your example).

Then call something like
Code:
indexMat ={{ 0, 1, 2, 3, 4}, { 14, 2, 5, 14, 5} };
DataSetFilter myFilter3 = CreateFilter ( myData, 1, indexMat[1][siteIndex]==14 )
 



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
Back to top
 

Associate Professor
Division of Infectious Diseases
Division of Biomedical Informatics
School of Medicine
University of California San Diego
WWW WWW  
IP Logged
 
wayne
Global Moderator
*****
Offline


I love YaBB 1G - SP1!

Posts: 57
San Diego, CA
Gender: male
Re: strcat, strcpy etc?
Reply #2 - Jan 23rd, 2007 at 6:57pm
 
thanks Sergei, your reply is once again informative and helpful. your efforts are really appreciated. cheers ./w
Back to top
 

Assistant Project Scientist&&Antiviral Research Center&&Department of Pathology&&University of California, San Diego
WWW WWW  
IP Logged