Last active
August 29, 2015 14:09
-
-
Save konrad/bf476f05676d7ac50087 to your computer and use it in GitHub Desktop.
Small script to retrieve data of all publications of a given journal in a given time frame from MEDLINE
This file contains 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/python | |
# medline_search.py | |
# | |
# Small script to retrieve data of all publications of a given journal in | |
# a given time frame from MEDLINE | |
# | |
# 2014 - Konrad Förstner <[email protected]> | |
# | |
# To the extent possible under law, the author have dedicated all | |
# copyright and related and neighboring rights to this software to | |
# the public domain worldwide. This software is distributed without | |
# any warranty. | |
# | |
# See <http://creativecommons.org/publicdomain/zero/1.0/> | |
# | |
# MEDLINE/PubMed Data Element (Field) Descriptions can be found at | |
# http://www.nlm.nih.gov/bsd/mms/medlineelements.html | |
# | |
# Version 1.0 | |
from Bio import Entrez | |
from Bio import Medline | |
search_term = '"Mol Microbiol"[jour] 2013/05:2014/11 [edat]' | |
output_file = "medline_search_result.csv" | |
email = "[email protected]" | |
max_number_of_hits = 500 | |
Entrez.email = email | |
esearch = Entrez.esearch( | |
db='pubmed', term=search_term, retmax=max_number_of_hits, ) | |
hits = Entrez.read(esearch) | |
with open(output_file, "w") as output_fh: | |
output_fh.write( | |
"\t".join( | |
["Title", "Abstract", "Authors", "Affiliation", "Entrez time", | |
"Date create", "Source", "Publication Type", "DOI", "Pubmed ID"]) | |
+ "\n") | |
for pmid in hits["IdList"]: | |
efetch = Entrez.efetch( | |
db="pubmed", id=pmid, rettype="medline", retmode="text") | |
for record in Medline.parse(efetch): | |
output_fh.write( | |
"\t".join([ | |
record.get("TI", "-"), | |
record.get("AB", "-"), | |
", ".join(record.get("AU", ["-"])), | |
record.get("AD", "-"), | |
record.get("EDAT", "-"), | |
record.get("DA", "-"), | |
record.get("SO", "-"), | |
", ".join(record.get("PT", ["-"])), | |
record.get("LID", "-"), | |
record.get("PMID", "-")]) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment