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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.