Find and print only the first ORF in fasta
<p>How to find only the first start_codon for each frame. In the code below it is giving me all start_codon position.</p>

<pre><code>from Bio.SeqRecord import SeqRecord
from Bio import SeqIO
def test(seq, start, stop):
    start = ["ATG"]
    start_codon_index = 0
    for frame in range(0,3):
        for i in range(frame, len(seq), 3):
            current_codon = seq[i:i+3]                            
            if current_codon in start:
                start_codons.append(start_codon_index)
    return start_codons

f = open("a.fa","r")
start = ["ATG"]
for record in SeqIO.parse(f,"fasta"):
    seq=record.seq
    name=record.id
    start_codons=test(seq, start, stop)
    print name, start_codons
</code></pre>

<p>If you have a DNA string and you want to find the first occurrence of an "ATG" sequence, the easiest is to just do: </p>

<pre><code>DNA = "ACCACACACCATATAATGATATATAGGAAATG"

print(DNA.find("ATG"))
</code></pre>

<p>Prints out <code>15</code>, note that the indexing in python starts from 0</p>

<p>In case you consider nucleotide triplets as well:</p>

<pre><code>DNA = "ACCACACACCATATAATGATATATAGGAAATG"
for i in range(0, len(DNA), 3):
    if DNA[i:i+3] == "ATG":
        print(i)
        break
</code></pre>

<p>Returns <code>15</code> as well.</p>

python