Last active
December 23, 2015 00:03
-
-
Save hashemi/7b58899f75432d8b9ef7 to your computer and use it in GitHub Desktop.
Revisions
-
hashemi revised this gist
Dec 23, 2015 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,18 @@ def citation(PMID, email): article_data = data[0]["MedlineCitation"]["Article"] journal_data = article_data["Journal"] journal_issue_data = journal_data["JournalIssue"] authors = [] for author in article_data["AuthorList"]: author_name = '' try: author_name = author["LastName"] except KeyError: continue try: author_name += ' ' + author["Initials"] except KeyError: pass authors.append(author_name) cite = { "journal": str(journal_data["ISOAbbreviation"]), "volume": str(journal_issue_data["Issue"]), @@ -21,7 +33,7 @@ def citation(PMID, email): "year": str(journal_issue_data["PubDate"]["Year"]), # remove trailing period after a title if it already exists "title": str(article_data["ArticleTitle"]).rstrip("."), "authors": ", ".join(authors), "pagination": str(article_data["Pagination"]["MedlinePgn"]), } return "{authors}. {title}. {journal}. {year} {month};{volume}({issue}):{pagination}.".format(**cite) -
hashemi created this gist
Dec 16, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # Takes a PubMed ID (PMID) and your email and returns # a citation more or less in Vancouver style. # # Depends on biopython: # $ pip install biopython # def citation(PMID, email): from Bio import Entrez Entrez.email = email handle = Entrez.efetch(db="pubmed", id=PMID, retmode="xml") data = Entrez.read(handle) article_data = data[0]["MedlineCitation"]["Article"] journal_data = article_data["Journal"] journal_issue_data = journal_data["JournalIssue"] cite = { "journal": str(journal_data["ISOAbbreviation"]), "volume": str(journal_issue_data["Issue"]), "issue": str(journal_issue_data["Volume"]), "month": str(journal_issue_data["PubDate"]["Month"]), "year": str(journal_issue_data["PubDate"]["Year"]), # remove trailing period after a title if it already exists "title": str(article_data["ArticleTitle"]).rstrip("."), "authors": ", ".join("{0[LastName]} {0[Initials]}".format(a) for a in article_data["AuthorList"]), "pagination": str(article_data["Pagination"]["MedlinePgn"]), } return "{authors}. {title}. {journal}. {year} {month};{volume}({issue}):{pagination}.".format(**cite)