i need help.
for example, my input is AAXXXAAXXXAAXX
so i want to count the number of times the AA actually appear in total. that will be 3 times. how to write a program like this?
double-post, see below.........
Last edited by KevinADC; 09-03-2007 at 10:51 PM.
Really mate, this is too simple, next time post some code you have tried.
two ways:
but what is if the input has three or more 'A's in a row? For example:Code:$input = 'AAXXXAAXXXAAXXAXA'; $count = $input =~ s/(AA)/$1/g; print $count; $input = 'AAXXXAAXXXAAXXAXXA'; $count = () = $input =~ /AA/g; print $count;
AAXXXAAXXXAAXXAXAAAXXAAAAAXXAA
as for that, i still have to verify with my teacher in school. to see what he gonna say about that.
btw thanks for helping.
input : AAXXXXAAXXXACXXXACXXX
i would like to count the times AA and AC occurred separately.
i try using your method. but the output is not what i want.
and i try using "if" statement. it's still the same output which is not what i expected.
this is the code for "if" statement.
if($seq =~ AA)
{
$countAA = $seq =~ s/(AA)/$1/g;
print "\nNumbers of AA pairs occurred: $countAA";
}
if($seq =~ AC)
{
$countAC = $seq =~ s/(AC)/$1/g;
print "\nNumbers of AC pairs occurred: $countAC";
}
the "if" conditions are not necessary:
Code:$seq = 'AAXXXXAAXXXACXXXACXXX'; $countAA = $seq =~ s/(AA)/$1/g; print "\nNumbers of AA pairs occurred: $countAA"; $countAC = $seq =~ s/(AC)/$1/g; print "\nNumbers of AC pairs occurred: $countAC";
both substrings (AA and AC) are counted twice, so the code works as expected.
From now on if you post questions I will not reply unless i see the code you have been writing and trying. That is my personal policy for helping students.
ok noted.
btw instead of putting
$count = $seq =~ s/(AA)/$1/g;
print $count;
can i put
$count = $seq =~ s/($codon)/$1/g;
print $count;
as for the $codon, it's a input for the user to type in.
try it and see what happens. This is the kind of thing that is easy to run a test on and see what the results are.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks