Question: Queries in PubMed and MEDLINE with Entrez
gravatar for pl640
8 months ago by
pl6400 wrote:

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?

Entrez.api_key = "example" = ""

TERM= "infant*[mh] AND colic[majr]"

handle = Entrez.egquery(term=TERM)
record =
for row in record["eGQueryResult"]:
    if row["DbName"]=="pubmed":

handle = Entrez.esearch(db="pubmed",
record =
idlist = record["IdList"]
for i in idlist:
    if i == '27631535':


#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':
    print("title:", record.get("TI", "?"))
    print("PMID:", record.get("PMID", "?"))
    print("MeSH Terms:", record.get("MH","?"))
    #print("abstracts:", record.get("AB", "?"))

Many thanks in advance!

ADD COMMENTlink modified 8 months ago • written 8 months ago by pl6400

Go to PubMed and play with your query first. I suggest something like these:

  • (infantile colic[mesh] AND effectiveness) AND (drugs OR herbal* OR sugar* OR safety)
  • (infantile colic[mesh] AND treatment) AND (effectiveness OR drugs OR herbal* OR sugar* OR safety)

Remember, that parenthesis in your query are important.

ADD REPLYlink modified 8 months ago • written 8 months ago by a.zielezinski9.0k

Thank you for your response, I've experimented with the queries in PubMed and I've set up a list of queries that I want to test. Do you have recommendations of how to efficiently incorporate a loop in my code to do so?

ADD REPLYlink written 8 months ago by pl6400
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1663 users visited in the last hour