Pubmed fetch xml entry by ID

It wasn’t clear how to grab a pubmed entry in xml format given an ID. This is how to do it:

import scala.io.Source.{fromFile, fromInputStream}
import scala.xml._
import java.net._
import java.io._

val idFile = "medline_ids.txt"

val ids = fromFile( idFile ).getLines()

for ( i <- 0 until 1 ) {
  val url = new URL("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=" + ids.next + "&retmode=xml")
  println( url )
  val inStream = fromInputStream(url.openStream).getLines.mkString("\n")
  println( inStream ) 

}

The important part is this:

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=20980263&retmode=xml

rather than http://www.ncbi.nlm.nih.gov/pubmed/20980263?report=xml which simply forces the output to look like xml. If you fetch the report=xml code using scala/curl you will see that all the are represented by their html codes – not nice.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s