我有一个 refseq ID (keys_list) 列表,用于使用 BioPython Entrez 下拉序列记录。我想只访问返回的 fasta 记录中的序列,但我不想将记录写入文件来这样做。
我正在尝试以下代码
for key in key_list:
Entrez.email = "myemailaddress"
handle = Entrez.efetch(db='nuccore', id=key, rettype='fasta')
record = SeqIO.parse(handle, "fasta")
for seq_record in SeqIO.parse(record, "fasta"):
print seq_record.seq
当我运行它时,我收到了错误:
File "/usr/lib64/python2.6/site-packages/Bio/SeqIO/__init__.py", line 538, in parse
yield r
File "/usr/lib64/python2.6/contextlib.py", line 34, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/lib64/python2.6/site-packages/Bio/File.py", line 59, in as_handle
yield handleish
File "/usr/lib64/python2.6/site-packages/Bio/SeqIO/__init__.py", line 537, in parse
for r in i:
File "/usr/lib64/python2.6/site-packages/Bio/SeqIO/FastaIO.py", line 37, in FastaIterator
line = handle.readline()
AttributeError: 'generator' object has no attribute 'readline'
如果我返回整个记录handle.read()
,我可以获得整个 fasta 记录,但在这个阶段我只想访问核苷酸序列。
谁能帮我解决这个问题?
提前谢谢了。