Skip to content

Instantly share code, notes, and snippets.

@yogeek
Last active January 28, 2018 22:52
Show Gist options
  • Select an option

  • Save yogeek/483761052eb9a5fdeee3cc7e34abf206 to your computer and use it in GitHub Desktop.

Select an option

Save yogeek/483761052eb9a5fdeee3cc7e34abf206 to your computer and use it in GitHub Desktop.
PubMed API
Display the source blob
Display the rendered blob
Raw
# To test :
# Go to https://try.jupyter.org/
# Click on "Python 3" in the up-right "New" menu
# Copy the code into a cell
# Modify the search terms in line 32
# Execute with "Ctrl+Enter"
import sys
!{sys.executable} -m pip install biopython
from Bio import Entrez
import json
def search(query):
Entrez.email = '[email protected]'
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 = '[email protected]'
handle = Entrez.efetch(db='pubmed',
retmode='xml',
id=ids)
results = Entrez.read(handle)
return results
if __name__ == '__main__':
results = search('carissa spinarum')
id_list = results['IdList']
papers = fetch_details(id_list)
print("")
print("-------------------------------------------------------------------------------------------------------------------")
print("RESULTS :")
print("-------------------------------------------------------------------------------------------------------------------")
print("")
for i, paper in enumerate(papers['PubmedArticle']):
print("%d) %s" % (i+1, paper['MedlineCitation']['Article']['ArticleTitle']))
print(json.dumps(paper['MedlineCitation']['Article']['Abstract']['AbstractText'], indent=2, separators=(',', ':')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment