Skip to content

Instantly share code, notes, and snippets.

@wenliangz
Forked from mcfrank/pubmed.py
Created November 12, 2022 06:07
Show Gist options
  • Select an option

  • Save wenliangz/d0bc9de00e3988a5995b84a3413bc7aa to your computer and use it in GitHub Desktop.

Select an option

Save wenliangz/d0bc9de00e3988a5995b84a3413bc7aa to your computer and use it in GitHub Desktop.

Revisions

  1. @mcfrank mcfrank created this gist Oct 7, 2015.
    53 changes: 53 additions & 0 deletions pubmed.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    ## this little script shows off the use of the pubmed API through bioconductor
    ## requires installing Biopython (using pip)
    ## also requires installing the DTD files for each of the Entrez API calls,
    ## but the instructions for this are given when you run the script

    ## useful list of Entrez databases that can be queried through API
    # pmc_pubmed PubMed citations for these articles
    # pmc_refs_pubmed PubMed article citing PMC article
    # pmc_pmc_cites PMC articles that given PMC article cites
    # pmc_pmc_citedby PMC article citing given PMC article
    # pubmed_pubmed Calculated set of PubMed citations similar to the selected article(s) retrieved using a word weight algorithm.
    # pubmed_pubmed_refs Citation referenced in PubMed article. Only valid for PubMed citations that are also in PMC.


    from Bio import Entrez

    Entrez.email = "[email protected]"

    def get_abstract(pmid):
    handle = Entrez.efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
    return handle.read()

    def get_links_id(pmid):
    link_list = []
    links = Entrez.elink(dbfrom="pubmed", id=pmid, linkname="pubmed_pubmed")
    record = Entrez.read(links)

    records = record[0][u'LinkSetDb'][0][u'Link']

    for link in records:
    link_list.append(link[u'Id'])

    return link_list

    def get_links_term(term):
    links = Entrez.esearch(db="pubmed", retmax = 1000, term=term)
    record = Entrez.read(links)
    link_list = record[u'IdList']

    return link_list


    ### MAIN -----------------------

    print(get_links_term("Saffran JR[Author] "))

    print "----------------------------"

    print(get_abstract("26113833"))

    print "----------------------------"

    print(get_links_id("8943209"))