I'm trying to set up a PubMed query using Entrez and MEDLINE to retrieve journals about a complicated subject. I want to retrieve the most relevant abstracts of articles about the effectiveness of various drugs and treatments in infantile colic. Moreover, I want to see what MESH terms are linked to the search query. My goal is to improve the search query as much as possible, so I need a way in which I can build on top of my results.
-Update, I've replaced my last code with its newest version-
I've succeeded partly in setting up the general code for extracting titles, PMIDs, MeSH terms and Abstracts of a query. I'm now trying to create a loop in which I can test different queries and their results. Does anyone know how to efficiently create a loop? Or does anyone have an useful tutorial for doing this?
#Initialisation Entrez.api_key = "example" Entrez.email = "firstname.lastname@example.org" TERM= "infant*[mh] AND colic[majr]" handle = Entrez.egquery(term=TERM) record = Entrez.read(handle) for row in record["eGQueryResult"]: if row["DbName"]=="pubmed": print(row["Count"]) handle = Entrez.esearch(db="pubmed", term=TERM, retmax='100', sort='relevance', retmode='xml', mindate="2016/11", maxdate="2019/02") record = Entrez.read(handle) handle.close() idlist = record["IdList"] for i in idlist: if i == '27631535': idlist.remove(i) print(idlist) #downloading the corresponding MEDLINE records handle = Entrez.efetch(db="pubmed", id=idlist, rettype="medline", retmode="json") records = Medline.parse(handle) records = list(records) for record in records: #if record[PMID] == '27631535': #records.remove(record) print("title:", record.get("TI", "?")) print("PMID:", record.get("PMID", "?")) print("MeSH Terms:", record.get("MH","?")) #print("abstracts:", record.get("AB", "?")) print("")
Many thanks in advance!