[Biopython] Degenerated Codons

Peter Cock p.j.a.cock at googlemail.com
Thu Feb 23 11:29:04 UTC 2012

On Thu, Feb 23, 2012 at 11:00 AM, Matthias Bernt <MatatTHC at gmx.de> wrote:
> Hi,
>> You can probably do that with the codon dictionaries
>> provided in Bio.Data.CodonTable (used for translations).
>> If you could give some specific examples of input and
>> desired output I'm sure we can give you more hints.
> You mean the forward_table?
> The most important function for me is:
> - Input: Codon (sequence of length 3), code table
> - Output: X, number of codons coding for the same
>   amino acid as the given codon

Where table could be ambiguous or unambiguous,
DNA or RNA? Something like this works nicely for
unambiguous tables:

from Bio.Data.CodonTable import unambiguous_dna_by_id
for table in [unambiguous_dna_by_id[1], unambiguous_dna_by_id[2]]:
    print table.id
    for codon in  ["AAA", "ATT"]:
        amino = table.forward_table[codon]
        alt_codons = [k for (k,v) in table.forward_table.iteritems()
if v==amino]
        print "%s -> %s, %i codons for this amino acid" % (codon,
amino, len(alt_codons))


AAA -> K, 2 codons for this amino acid
ATT -> I, 3 codons for this amino acid
AAA -> K, 2 codons for this amino acid
ATT -> I, 2 codons for this amino acid

> But maybe its possible to modify the backward_table such
> that it stores all codons (as list) for a amino acid. For the other
> functions building on it (back translation...) it would be possible
> to take the first element of the list.

We can't change that for backwards compatibility, but we
could add a alt_backward_table or something instead?


More information about the Biopython mailing list