[BioPython] Inverse codon table?

Peter biopython at maubp.freeserve.co.uk
Tue Aug 14 17:17:31 UTC 2007


Sebastian Bassi wrote:
> I am looking for a table in Biopython of amino-acids and its codons. I
> found in Data.CodonTable a table but it should be used in the inverse
> way I need:
> 
>>>> from Bio.Data import CodonTable
>>>> t=CodonTable.standard_dna_table
>>>> t.forward_table["ATG"]
> 'M'
> 
> I need a table that I coulld enter "M" and get the all triples that
> translate into "M". Is this available in Biopyhon?
> 

I'm not sure without a thorough check, but its fairly be trivial to 
build such a dictionary from the CodonTable.standard_dna_table like this:

from Bio.Data import CodonTable
t=CodonTable.standard_dna_table
t.forward_table["ATG"]

#Build a back table dict where the values are lists of codons...
bt = dict()
for a1 in "ATCG" :
     for a2 in "ATCG" :
         for a3 in "ATCG" :
             codon = a1+a2+a3
             try :
                 amino = t.forward_table[codon]
             except KeyError :
                 assert codon in t.stop_codons
                 continue
             try :
                 bt[amino].append(codon)
             except KeyError :
                 bt[amino] = [codon]

for amino in bt :
     print amino, bt[amino]


Peter





More information about the Biopython mailing list