Skip to content

Instantly share code, notes, and snippets.

@ehazlett
Created July 25, 2011 16:27
Show Gist options
  • Save ehazlett/1104507 to your computer and use it in GitHub Desktop.
Save ehazlett/1104507 to your computer and use it in GitHub Desktop.
Search PubMed with BioPython
#!/usr/bin/env python
# numpy and biopython are required -- pip install numpy biopython
from Bio import Entrez
from Bio import Medline
MAX_COUNT = 10
TERM = 'Tuberculosis'
print('Getting {0} publications containing {1}...'.format(MAX_COUNT, TERM))
Entrez.email = '[email protected]'
h = Entrez.esearch(db='pubmed', retmax=MAX_COUNT, term=TERM)
result = Entrez.read(h)
print('Total number of publications containing {0}: {1}'.format(TERM, result['Count']))
ids = result['IdList']
h = Entrez.efetch(db='pubmed', id=ids, rettype='medline', retmode='text')
records = Medline.parse(h)
authors = []
for record in records:
au = record.get('AU', '?')
for a in au:
if a not in authors:
authors.append(a)
authors.sort()
print('Authors: {0}'.format(', '.join(authors)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment