What You’re Doing Is Rather Desperate

Notes from the life of a bioinformatics researcher

Querying NCBI Entrez database fields using Ruby

Here’s a problem. You’d like to construct a complex query at NCBI Entrez using various fields. Example:

“9606″[Taxonomy ID]

to limit your search to Homo sapiens. Except – you don’t know which fields are available for the database that you want to query.

EInfo can return an XML file with this information. Ruby + Hpricot eats XML for breakfast. Here’s an example using the GEO Datasets (gds) database.

#!/usr/bin/ruby

require 'rubygems'
require 'hpricot'
require 'open-uri'

doc = Hpricot(open("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi?db=gds"))

(doc/'//fieldlist/field').each do |f|
  puts "#{(f/'/name').inner_html},#{(f/'/fullname').inner_html},#{(f/'description').inner_html}"
end

And the first few lines of output:

ALL,All Fields,All terms from all searchable fields
UID,UID,Unique number assigned to publication
FILT,Filter,Limits the records
ORGN,Organism,exploded organism names
....24 more lines....

Written by nsaunders

May 27, 2009 at 5:33 pm

Posted in bioinformatics, computing, ruby

Tagged with , , ,

3 Responses

Subscribe to comments with RSS.

  1. Going the Ruby route I see! I wrote up the BioPerl EUtilities tools (Bio::DB::EUtilities, Bio::Tools::EUtilities) to run and parse this stuff (it doesn’t dive into Seq objects, you get raw data for now).

    Got a small HOWTO on it as well!

    cjfields

    May 27, 2009 at 11:39 pm

  2. Nice tip – thanks!

    I’ve written up a example using EInfo in Biopython,
    http://news.open-bio.org/news/2009/06/ncbi-einfo-biopython/

    Peter

    June 22, 2009 at 8:37 pm


Comments are closed.