def ncbi_search(self, database, term):
        """
        Submit search to NCBI and return the records.
        """
        self.handle = Entrez.esearch(db=database, term=term, usehistory="y",
                                     retmax=100000000)
        self.record = Entrez.read(self.handle)
        self.handle.close()

        return self.record
Exemple #2
0
    def ncbi_search(self, database, term):
        """
        Submit search to NCBI and return the records.
        """
        self.handle = Entrez.esearch(db=database, term=term, usehistory="y",
                                     retmax=10, idtype="acc")
        self.record = Entrez.read(self.handle)
        self.handle.close()

        return self.record
Exemple #3
0
def validate_and_convert_DOI_or_PMID_to_PMID(lookupID, comments):
    """
    Look up a DOI -- or PMID -- and return a PMID.
    :param lookupID: either a DOI or a PMID.
    :return a PMID
    """

    # Format as string and strip any leading white spaces. Do now so we can reach DOI/PMIDs.
    lookupID = str(lookupID).lstrip()

    # Remove any prefacing text that might've come through. Only if it's at the start of the lookupID.
    preface_tags = ['DOI:', 'doi:', 'PMID:', 'pmid:']
    for tag in preface_tags:
        if lookupID.startswith(tag):
            lookupID = re.sub(tag, '', lookupID)

    # Drop any white spaces that remain.
    lookupID = lookupID.replace(" ", "")

    try:
        Entrez.email = app.config['EMAIL']
        handle = Entrez.esearch(db="pubmed", retmax=10, term=lookupID)
        record = Entrez.read(handle)
        handle.close()
        if int(record['Count']) == 0:
            comments.append("I can't fetch an article with that ID."
                            )  # DOI not on PubMed? Or Bad PMID?
            comments.append(
                "Try looking up the article on www.pubmed.gov. (Note: PubMed may not have the DOI.) If the article is there, copy its PMID and bring it to me. If the article isn't on PubMed, I can't fetch a citation for you. Sorry. :( "
            )
            return '', comments
        elif int(record['Count']) > 1:
            comments.append(
                'I found more than one article. Are there characters missing from the ID?'
            )
            return '', comments
        else:  # Only 1 result, perfect!
            return (record['IdList'][0]), comments
    except IOError:  # Network error
        comments.append(
            "Is there a network problem? Unleash me please!")  # Network error
        return '', comments
    except:
        comments.append("I can't fetch an article with ID " + lookupID +
                        '. Can you double check it?')  # Bad PMID?
        comments.append(
            "Try looking up the article on www.pubmed.gov. (Note: PubMed may not have the DOI.) If the article is there, copy its PMID and bring it to me. If the article isn't on PubMed, I can't fetch a citation for you. Sorry. :( "
        )
        return '', comments