You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a pipeline that 1) takes accession numbers and uses Entrez.esearch and Entrez.read to retrieve GIs, 2) takes the GIs and uses Entrez.epost, Entrez.read and Entrez.efetch to get the corresponding genbank documents. I found today that the first step is failing with the error below. This code has worked for me many times before so not sure exactly what's going on.
from Bio import Entrez
Entrez.email = ""
accessions = ["KX447511", "KX101066"]
retmax = 10**9
query = " ".join(accessions)
handle = Entrez.esearch(db="nuccore", term=query, retmax=retmax)
giList = Entrez.read(handle)['IdList']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/__init__.py", line 376, in read
record = handler.read(handle)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/Parser.py", line 205, in read
self.parser.ParseFile(handle)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/Parser.py", line 513, in externalEntityRefHandler
self.dtd_urls.append(url)
UnboundLocalError: local variable 'url' referenced before assignment
The exception is an old bug in Biopython, fixed in release 1.66 - see #527, can you update and retry please? Our current release is Biopython 1.68 released last week.
Thank you @peterjc. I've realized that I will have to update my script to use accessions instead. Would that just involve passing a comma separated list of accessions to Entrez.epost? Like Entrez.epost(db="nuccore", id=",".join(accession_list))
Updating to Biopython 1.68 fixed the original url bug.
Separately I've been trying to give Entrez.epost accessions in place of gi's and am getting the following error.
from Bio import Entrez
Entrez.email=""
accessions = ["KX447511.1", "KX101066.1"]
search_handle = Entrez.epost(db="nuccore", id=",".join(accessions))
search_results = Entrez.read(search_handle)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/__init__.py", line 450, in read
record = handler.read(handle)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/Parser.py", line 233, in read
self.parser.ParseFile(handle)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Entrez/Parser.py", line 390, in endElementHandler
raise RuntimeError(value)
RuntimeError: IDs contain invalid characters which was treated as delimiters.
Activity
peterjc commentedon Sep 1, 2016
The exception is an old bug in Biopython, fixed in release 1.66 - see #527, can you update and retry please? Our current release is Biopython 1.68 released last week.
However, I suspect the real problem is due to the NCBI retiring the GI numbers - so unfortunately you are going to have to update your script to use accessions instead - see e.g. https://www.ncbi.nlm.nih.gov/news/03-02-2016-phase-out-of-GI-numbers/
chacalle commentedon Sep 2, 2016
Thank you @peterjc. I've realized that I will have to update my script to use accessions instead. Would that just involve passing a comma separated list of accessions to Entrez.epost? Like
Entrez.epost(db="nuccore", id=",".join(accession_list))peterjc commentedon Sep 2, 2016
Did updating Biopython give you a new error message? That ought to be more informative...
chacalle commentedon Sep 3, 2016
Updating to Biopython 1.68 fixed the original url bug.
Separately I've been trying to give
Entrez.epostaccessions in place of gi's and am getting the following error.peterjc commentedon Sep 3, 2016
I'm glad the original issue is resolved, and am therefore closing this issue.
See #926 for the new question about GI numbers and Entrez epost