My question(s) relates to working inline C code: is it necessary to use the inline stack functions (Inline_Stack_Vars) to pass variables in and out, or is it appropriate in this context to just modify a variable in place?
For display of biosequence data, I need to show just differences between two aligned strings; e.g. given these two strings:
ATCAGAAA--GACATGGGCCAAAGATTAA-CAGTGGCCATTGACAGGA--
--CCCCAACTGACAGGGGGCAAAGATTAA-CAGTGGCCATTG---GGA--
I want to get this (the matching chars in the second string replaced with '.'s.
--.CCC..CT....G...G..........-............---...--
I have a lot of sequences (millions of Illumina reads), so have turned to inline::c for the character matching. The following inlined code seems to work just fine (changing the second argument to the add_matchchars function in place):
#!/usr/bin/perl
use Inline C;
my($seq1,$seq2) = qw/ ATCAGAAA--GACATGGGCCAAAGATTAA-CAGTGGCCATTGACAGGA--
--CCCCAACTGACAGGGGGCAAAGATTAA-CAGTGGCCATTG---GGA-- /;
print $seq1,"\n";
print $seq2,"\n";
add_matchchars($seq1,$seq2);
print $seq2,"\n";
__END__
__C__
void add_matchchars(char *seq1, char *seq2) {
int seq1char;
int seq2char;
while(seq1char = *seq1++ , seq2char = *seq2++) {
if (seq1char == seq2char) {
*seq2--;
if (seq1char != '-') {
*seq2 = '.';
}
*seq2++;
}
//printf("%c-%c\n",seq1char,seq2char);
}
// printf("%s\n%s\n",seq1,seq2);
}
But 1) is it reasonably efficient (is there a cleverer/better way)? and 2) will it leak memory?
Inline_Stack_*
is a means of accessing variable-length argument lists. Has nothing to do with memory leaks. – Lazare