Skip to content

Entrez.read error w/ url assignment #925

Closed

Description

@chacalle

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

Activity

  1. peterjc commented on Sep 1, 2016

    @peterjc
    Member

    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/

  2. chacalle commented on Sep 2, 2016

    @chacalle
    Author

    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))

  3. peterjc commented on Sep 2, 2016

    @peterjc
    Member

    Did updating Biopython give you a new error message? That ought to be more informative...

  4. chacalle commented on Sep 3, 2016

    @chacalle
    Author

    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.
    
  5. peterjc commented on Sep 3, 2016

    @peterjc
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions