I have a file with GI numbers and would like to get FASTA
sequences from 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()
This script runs fine but I suddenly get this error message after a few sequences.
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
Of course I can use http://www.ncbi.nlm.nih.gov/sites/batchentrez
but I am trying to create a pipeline and would like something automated.
How can I prevent ncbi from "kicking me out"