Biopython转换错误:TypeError:'generator'对象没有属性'__getitem__'

时间:2015-07-18 09:16:29

标签: python biopython

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

#!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

1 个答案:

答案 0 :(得分:2)

与错误消息状态类似,awk是生成器。

如果您想将其用作您正在执行的列表,则应首先从列表中创建列表。

m_record