Skip to content

Instantly share code, notes, and snippets.

@renaud
Last active August 3, 2019 12:58
Show Gist options
  • Select an option

  • Save renaud/7872024 to your computer and use it in GitHub Desktop.

Select an option

Save renaud/7872024 to your computer and use it in GitHub Desktop.
python NCBI example
from Bio import Entrez
Entrez.email = "[email protected]"
handle = Entrez.esearch(db="pubmed", term="pyramidal cell")
record = Entrez.read(handle)
len(record) # this matches http://www.ncbi.nlm.nih.gov/pubmed/?term=pyramidal%20cell
first = record["IdList"][0]
# from http://stackoverflow.com/a/20149984/125617
def print_abstract(pmid):
handle = Entrez.efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
print handle.read()
print_abstract(first)
def fetch_abstract(pmid):
handle = Entrez.efetch(db='pubmed', id=pmid, retmode='xml')
xml_data = Entrez.read(handle)[0]
try:
article = xml_data['MedlineCitation']['Article']
abstract = article['Abstract']['AbstractText'][0]
return abstract
except IndexError:
return None
fetch_abstract(first) ## some warnings, though...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment