Homework #4

Due: Thursday, March 8, 2018 at 11:59 p.m.
Points: 100


Please turn in your answers for the homework assignment on Canvas under Homework #4 in Assignments.

This exercise has you query the PubMed database for a list of publications related to a keyword. Although we won’t do it here, the list of publication numbers you get back can then be turned into a list of papers with a second query to the PubMed database.

To access the PubMed database, go to the URL below, replacing keyword with the keyword you want to search for, and num the number of publications you would like returned:

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?
     db=pubmed&retmode=json&retmax=num&sort=relevance&term=keyword
with no spaces and all on a single line.

So, for example, to find the 20 publications most relevant to “fever”, the URL would be:

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?
     db=pubmed&retmode=json&retmax=20&sort=relevance&term=fever
with no spaces and all on a single line.

When you read the contents of this web page, it is in the JSON format. You can turn this into a dictionary easily using the module json. The method json.loads(contents), where contents is the contents of the web page, returns a dictionary with one entry, the key of which is “esearchresults”. The associated value is another dictionary. The part you want is a list of the publication numbers. The key is “idlist” and the value is a list of the numbers.

You are to print the numbers of that list on a single line, with commas between them (no spaces). So, for the above, your output would look like this:

29078933,29092992,28822610,27822946,28377245,28747169,28187992,28106314,28390959,27995553,
28640776,28449675,27992852,28438740,28223176,29049070,28863031,28233624,28097438,27240113

but all on a single line. Note your numbers might differ from these because more relevant publications may be found.

Call this program “pubmed.py” when you submit it.


Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of February 28, 2018 at 12:41PM
Winter Quarter 2018
You can get a PDF version of this