我有一个带有 GI 编号的文件,想FASTA
从 ncbi 获取序列。
from Bio import Entrez
import time
Entrez.email ="eigtw59tyjrt403@gmail.com"
f = open("C:\\bioinformatics\\gilist.txt")
for line in iter(f):
handle = Entrez.efetch(db="nucleotide", id=line, retmode="xml")
records = Entrez.read(handle)
print ">GI "+line.rstrip()+" "+records[0]["GBSeq_primary-accession"]+" "+records[0]["GBSeq_definition"]+"\n"+records[0]["GBSeq_sequence"]
time.sleep(1) # to make sure not many requests go per second to ncbi
f.close()
该脚本运行良好,但在几个序列后我突然收到此错误消息。
Traceback (most recent call last):
File "C:/Users/Ankur/PycharmProjects/ncbiseq/getncbiSeq.py", line 7, in <module>
handle = Entrez.efetch(db="nucleotide", id=line, retmode="xml")
File "C:\Python27\lib\site-packages\Bio\Entrez\__init__.py", line 139, in efetch
return _open(cgi, variables)
File "C:\Python27\lib\site-packages\Bio\Entrez\__init__.py", line 455, in _open
raise exception
urllib2.HTTPError: HTTP Error 500: Internal Server Error
当然我可以使用http://www.ncbi.nlm.nih.gov/sites/batchentrez
,但我正在尝试创建一个管道并且想要一些自动化的东西。
如何防止 ncbi “踢我”