Reputation: 1
I have a problem where I need to print the translation table from a Genbank file. My program looks like this:
from Bio import SeqIO
record = SeqIO.read("mycoplasma.gb","genbank")
print record.id
print record.description
print "Number of features:", len(record.features)
ct=0
for f in record.features:
if f.type=="tRNA":
ct+=1
print "There are ", ct, "tRNa features"
ct2 = 0
for f in record.features:
if f.type == "gene":
ct2+=1
print "Therea are", ct2, "gene features"
ct3 = 0
for f in record.features:
if f.type == "CDS":
ct3+=1
print "There are", ct3, "CDS features"
print "The following is feature 4:"
print record.features[4]
print "The following information is about feature 21:"
print "It is a", record.features[21].type, "feature"
print "Its location is", record.features[21].location
for feature in record.features[21]:
print feature.qualifiers["transl_table"]
I just need the last part to print the translation table from the file.
Upvotes: 0
Views: 247
Reputation: 7443
It's easy. You first import the CodonTables with:
from Bio.Data import CodonTable
and after that you can get the CodonTables with the number in the Genbank files:
for feature in record.features:
t_t = feature.qualifiers.get("transl_table")
if t_t:
print CodonTable.unambiguous_dna_by_id[int(t_t[0])]
Take note you need to get an integer to use unambiguous_dna_by_id[]
, and t_t
is most likely a list of strings like ['4']
Upvotes: 1