我的代码有问题。我正在尝试使用 BioPython 遍历 genbank 文件的基因列表。这是它的样子:
class genBank:
gbProtId = str()
gbStart = int()
gbStop = int()
gbStrand = int()
genBankEntries = list()
for seq_record in SeqIO.parse(genBankFile, "genbank"):
for seq_feature in seq_record.features:
genBankEntry = genBank
if seq_feature.type == "CDS":
genBankEntry.gbProtId = seq_feature.qualifiers['protein_id']
genBankEntry.gbStart = seq_feature.location.start # prodigal GFF3 output is 1 based indexing
genBankEntry.gbStop = seq_feature.location.end
genBankEntry.gbStrand = seq_feature.strand
genBankEntries.append(genBankEntry)
看起来它应该可以工作,但是当我运行它时,生成的结构genBankEntries
只是一个巨大的堆栈,大小与 genbank 文件中的基因数量相当,但只有 seq_record.features 中的最终值作为每个列表元素:
00 = {type} <class '__main__.genBank'>
gbProtId = {list} ['BAA31840.1']
gbStart = {ExactPosition} 90649
gbStop = {ExactPosition} 91648
gbStrand = {int} 1
...
82 = {type} <class '__main__.genBank'>
gbProtId = {list} ['BAA31840.1']
gbStart = {ExactPosition} 90649
gbStop = {ExactPosition} 91648
gbStrand = {int} 1
这尤其令人困惑,因为两个 for 循环似乎都可以正常工作:
for seq_record in SeqIO.parse(genBankFile, "genbank"):
for seq_feature in seq_record.features:
print(seq_feature)
为什么是这样?