[BioRuby] Bio::PubMed efetch xml support and other options

Kaustubh Patil kpatil at science.uva.nl
Mon Nov 12 11:09:33 UTC 2007


Hi,

XML is very nice for searching etc. PubMed documents can be fetched in 
various formats, including xml. I have changed the efetch method in 
Bio::PubMed class in order to implement this. Here is the modified method;

# Kaustubh Patil: 6 Nov. 2007
# options hash here is different than options hash in esearch
    def self.efetch(ids, hash = {} )
      return [] if ids.empty?

      # default options
      hash['retmode'] = 'xml' unless hash['retmode']
      hash['rettype'] = 'medline' unless hash['rettype']

      # create options array in required format
      opts = []
      hash.each do |k, v|
        opts << "#{k}=#{v}"
      end

      host = "eutils.ncbi.nlm.nih.gov"
      path = 
"/entrez/eutils/efetch.fcgi?tool=bioruby&db=pubmed&#{opts.join('&')}&id="

      ids = ids.join(",")

      http = Net::HTTP.new(host)
      response, = http.get(path + ids)
      result = response.body

      if(hash['retmode']=='text')
        result = result.split(/\n\n+/)
      end

      return result

    end


I hope it is useful.

Cheers,
Kaustubh

PS: for details of entrez efetch parameters 
http://www.ncbi.nlm.nih.gov/entrez/query/static/efetchlit_help.html



More information about the BioRuby mailing list