title: How to count the number of codons in a frame using python (biopython)
body: <p>I have the below script to count the number of codons (codon.list.csv) in a gene file (test.fasta), it is however counting all codons irrespective of frame, I would like to count each codon only in frame 0, (ATG,TAT,TAT,TAA). For example:</p>
  
  <pre><code>&gt;test1
  ATGTATTATTAA
  </code></pre>
  
  <p>ATG:1 TAT:2 TAA:1 </p>
  
  <p>At the moment my script is counting TGT,ATT,TTA etc.. which I don't require.</p>
  
  <p>I thought this would be easier but I cannot get it corrected... </p>
  
  <p>Any advice would be great!</p>
  
  <pre><code>from Bio import  SeqIO
  mRNA_sequences = "test.fasta"
  
  in_seq_handle = open(mRNA_sequences)
  seq_dict = SeqIO.to_dict(SeqIO.parse(in_seq_handle, "fasta"))
  in_seq_handle.close()
  seq_dict_keys =  seq_dict.keys()
  
  dict_sequences2={} 
  dict_codons = {}
  
  contig_file = open("codon.list.csv")
  for line in contig_file:
      gene_id = line[0:3]
      for sequence in seq_dict.values():
          seqstring = sequence.seq
  
          if dict_hepts.has_key((line[:-1])):
              dict_codons[(line[:-1])] += seqstring.count(gene_id)
          else:
              dict_codons[(line[:-1])] = seqstring.count(gene_id)
  
  print dict_codons
  </code></pre>