Biopython translation error: TypeError: 'generator' object has no attribute '__getitem__'

Biopython translation error: TypeError: 'generator' object has no attribute '__getitem__'

我的代码有问题,这让我很沮丧。

#!usr/bin/python
import os,sys
import Bio
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Alphabet import IUPAC
fastaname = sys.argv[1]
in_put = open(fastaname,"rU")
out_put = open(fastaname[:-6] + "pro.fa","w")
m_record = SeqIO.parse(in_put, "fasta")
x = str(m_record)
start = x.find("ATG")
n = m_record[start:]
pro_records = (rec.translate(id = rec.id, to_stop = True) for rec in n)
SeqIO.write(pro_records, out_put, "fasta")
in_put.close()
out_put.close()

运行 它与

$ python script test.fasta
Traceback (most recent call last):
File "translation.py", line 14, in <module>
n = m_record[start:]
TypeError: 'generator' object has no attribute '__getitem__'

和测试文件test.fasta

>GRMZM5G800101_T01  
ATGATCTGGCATGTACAGAATTAG

如错误消息所述,m_record 是一个生成器。

如果你想像列表一样使用它,你应该先从它创建一个列表。

m_record = list(SeqIO.parse(in_put, "fasta"))