我有一个问题,我需要从Genbank文件打印转换表。我的程序看起来像这样:
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"]
我只需要最后一部分从文件中打印转换表。
答案 0 :(得分:1)
这很容易。首先使用以下命令导入CodonTable:
from Bio.Data import CodonTable
之后你可以使用Genbank文件中的数字来获取CodonTables:
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])]
请注意,您需要一个整数才能使用unambiguous_dna_by_id[]
,而t_t
很可能是['4']
等字符串列表