Skip to content

Instantly share code, notes, and snippets.

@informationsea
Created April 16, 2013 06:32
Show Gist options
  • Save informationsea/5393815 to your computer and use it in GitHub Desktop.
Save informationsea/5393815 to your computer and use it in GitHub Desktop.
Generate HTML paper list from PubMed ID list
#!/usr/bin/env python
__author__ = 'OKAMURA Yasunobu'
__license__ = 'GPLv3+'
from Bio import Entrez
import argparse
import re
from xml.sax.saxutils import escape
def make_citation_format(record):
if len(record['AuthorList']) == 1:
authorlist = record['AuthorList'][0]
else:
authorlist = ', '.join(record['AuthorList'][:-1]) + ' and ' + record['AuthorList'][-1]
cite = escape(authorlist) + '. '
cite += escape(record['Title'].strip())
if not record['Title'].endswith('.'):
cite += '.'
cite += ' <span style="font-style: italic;">'
cite += escape(record['Source']) + '</span>, ' + escape(record['SO']) + ' '
cite += '<a href="http://www.ncbi.nlm.nih.gov/pubmed/{}">PubMed</a> '.format(record['Id'])
cite += '<a href="http://dx.doi.org/{}">Journal</a>'.format(record['DOI'])
return cite
def _main():
"""
"""
parser = argparse.ArgumentParser(description='Generate paper list from not formatted list')
parser.add_argument('pubmed', nargs='+')
parser.add_argument('--email', default='', help='Your E-mail address (Required)', required=True)
options = parser.parse_args()
Entrez.email = options.email
print '<ul>'
for one in options.pubmed:
handle = Entrez.esummary(db='pubmed', id=one)
record = Entrez.read(handle)
handle.close()
print '<li>'+make_citation_format(record[0])+'</li>'
print '</ul>'
if __name__ == '__main__':
_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment