This is a test version of Biostars. For the public version, visit https://www.biostars.org.
biopython translate error

I want to translate a sequence which I have already parsed the translation table from the genbank file.

My code works on some of the files, but in one file I have tranlation table = 24 and I'm getting the following error:

 codon_table = CodonTable.ambiguous_generic_by_id[table_id]
KeyError: 24

The following is my code:

with open(file, 'r') as inF:
    for line in inF:
        if '/transl_table' in line:
            l=line.split('=')
            #I extracted already the gene sequence...
            protein=gene.translate(table=l[1])

What is the cause of this error and how to solve it?

biopython genbank codon translation python

always show the actual error that you get

this is the error :

codon_table = CodonTable.ambiguous_generic_by_id[table_id]
KeyError: 24

1 answer

If you look at the code for CodonTable, there are only tables registered with identifiers <23. I think you'll have to either use another equivalent table (if it exists), or you can register a new one like so:

I've submitted a pull request to add this codon table to Biopython, so hopefully it will be in the next release.

Also not that I've updated the Gist to include the actual codon table you can use.

Log in to answer this question.