I have to download a million protein seq from NCBI. I worked on a few line of code using also suggestions from here
When I test my code I get as a result an empty file:
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from Bio import Entrez
>>> Entrez.email ="xxx@example.com"
>>> from urllib2 import HTTPError
>>> import time
>>> data = np.loadtxt('/home/xxx.txt', dtype="string")
>>> x=data[:1000]
>>> x=",".join(x)
>>> x_1=data[1001:2001]
>>> x_1=",".join(x_1)
>>> x_2=data[20002:3001]
>>> x_2=",".join(x_2)
>>> prot=(x, x_1, x_2)
>>> for c in iter(prot):
... try:
... handle = Entrez.efetch(db="protein", id=c, rettype="fasta", retmode="txt")
... except HTTPError:
... time.sleep(20)
... handle = Entrez.efetch(db="protein", id=c, rettype="fasta", retmode="txt")
... time.sleep(1) # to make sure not many requests go per second to ncbi
...
>>> handle.read()
'Supplied id parameter is empty.\n'
Where am I wrong?
biopython
ncbi
sequence