Created
April 16, 2013 06:32
-
-
Save informationsea/5393815 to your computer and use it in GitHub Desktop.
Generate HTML paper list from PubMed ID list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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