Dear PerlMonks, I try to find all possible open reading frames in a sequence and print them out. I have already written a working program, but I want an alternative that is more efficient (I currently have two loops). The idea is to store the position of starts, store the position of the stops and then look for pairs that are in frame. The latter point is what makes it difficult to me. How can I look for in-frame pairs? here's the code for my first solution that works:
my $sequence = "sequence.fa"; my @starts; open (FASTA, "$sequence") || die "Cannot open $sequence: $!.\n"; chomp (my @seq = <FASTA>); close FASTA; shift @seq; $sequence = join ('', @seq); @seq = split ('', $sequence); for (my $i=0; $i<=$#seq-5; $i++){ ## -5 könnte man weglassen # start codon: ATG # stopp codon: TAG, TAA, TGA # multiple of 3 between start and stop if ($seq[$i] eq 'A' && $seq[$i+1] eq 'T' && $seq[$i+2] eq 'G') +{ push (@starts, $i); for (my $j=$i+3; $j<=$#seq-2; $j=$j+3){ if (($seq[$j] eq 'T' && $seq[$j+1] eq 'A' && $seq[$j+2 +] eq 'A') || ($seq[$j] eq 'T' && $seq[$j+1] eq 'G' && $seq[$j+2] eq + 'A') || ($seq[$j] eq 'T' && $seq[$j+1] eq 'A' && $seq[$j+2] eq + 'G')){ print "ORF: $i-", ($j+2), "\n"; last; ##lasts the j loop } } } }
I would be very pleased if anyone wrote an alternative algorithm according to my aforementioned demands. Thanks in advance!
In reply to finding open reading frames by ic23oluk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |