Skip to content

Instantly share code, notes, and snippets.

@reiaoki
Forked from bonzanini/search_biopython.py
Created October 31, 2017 22:18
Show Gist options
  • Select an option

  • Save reiaoki/26dc5fe15b244af1614a8bdbb949b802 to your computer and use it in GitHub Desktop.

Select an option

Save reiaoki/26dc5fe15b244af1614a8bdbb949b802 to your computer and use it in GitHub Desktop.

Revisions

  1. @bonzanini bonzanini revised this gist Jan 18, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions search_biopython.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # you need to install Biopython:
    # pip install biopython

    # Full discussion:
    # https://marcobonzanini.wordpress.com/2015/01/12/searching-pubmed-with-python/

    from Bio import Entrez

    def search(query):
  2. @bonzanini bonzanini created this gist Jan 11, 2015.
    33 changes: 33 additions & 0 deletions search_biopython.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # you need to install Biopython:
    # pip install biopython

    from Bio import Entrez

    def search(query):
    Entrez.email = 'your.email@example.com'
    handle = Entrez.esearch(db='pubmed',
    sort='relevance',
    retmax='20',
    retmode='xml',
    term=query)
    results = Entrez.read(handle)
    return results

    def fetch_details(id_list):
    ids = ','.join(id_list)
    Entrez.email = 'your.email@example.com'
    handle = Entrez.efetch(db='pubmed',
    retmode='xml',
    id=ids)
    results = Entrez.read(handle)
    return results

    if __name__ == '__main__':
    results = search('fever')
    id_list = results['IdList']
    papers = fetch_details(id_list)
    for i, paper in enumerate(papers):
    print("%d) %s" % (i+1, paper['MedlineCitation']['Article']['ArticleTitle']))
    # Pretty print the first paper in full
    #import json
    #print(json.dumps(papers[0], indent=2, separators=(',', ':')))