[BioRuby-cvs] bioruby/lib/bio/io pubmed.rb,1.18,1.19
Katayama Toshiaki
k at dev.open-bio.org
Thu Nov 15 07:23:41 UTC 2007
Update of /home/repository/bioruby/bioruby/lib/bio/io
In directory dev.open-bio.org:/tmp/cvs-serv6745/io
Modified Files:
pubmed.rb
Log Message:
* esearch2, efetch2: candidates for the better replacement of esearch and efetch methods which are enchanced to accept options as a hash and utilize Bio::Command.post_form for the options
Index: pubmed.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/pubmed.rb,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** pubmed.rb 10 Nov 2007 08:21:54 -0000 1.18
--- pubmed.rb 15 Nov 2007 07:23:39 -0000 1.19
***************
*** 9,15 ****
#
- require 'net/http'
- require 'cgi' unless defined?(CGI)
require 'bio/command'
module Bio
--- 9,14 ----
#
require 'bio/command'
+ require 'cgi' unless defined?(CGI)
module Bio
***************
*** 112,115 ****
--- 111,134 ----
end
+ def self.esearch2(str, hash = {})
+ serv = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"
+ opts = {
+ "retmax" => 100,
+ "tool" => "bioruby",
+ "db" => "pubmed",
+ "term" => str
+ }
+ opts.update(hash)
+
+ response, = Bio::Command.post_form(serv, opts)
+ result = response.body
+ if opts['rettype'] == 'count'
+ result = result.scan(/<Count>(.*?)<\/Count>/m).flatten.first.to_i
+ else
+ result = result.scan(/<Id>(.*?)<\/Id>/m).flatten
+ end
+ return result
+ end
+
# Retrieve PubMed entry by PMID and returns MEDLINE formatted string using
# entrez efetch. Multiple PubMed IDs can be provided:
***************
*** 132,136 ****
response, = http.get(path + list)
result = response.body
! result = result.split(/\n\n+/)
return result
end
--- 151,173 ----
response, = http.get(path + list)
result = response.body
! return result
! end
!
! def self.efetch2(ids, hash = {})
! return "" if ids.empty?
! ids = ids.join(",") if ids === Array
!
! serv = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi"
! opts = {
! "tool" => "bioruby",
! "db" => "pubmed",
! "retmode" => "text",
! "rettype" => "medline",
! "id" => ids,
! }
! opts.update(hash)
!
! response, = Bio::Command.post_form(serv, opts)
! result = response.body
return result
end
***************
*** 212,216 ****
puts "--- Search PubMed by E-Utils ---"
! Bio::PubMed.esearch("(genome AND analysis) OR bioinformatics)").each do |x|
p x
end
--- 249,255 ----
puts "--- Search PubMed by E-Utils ---"
! puts Bio::PubMed.esearch("(genome AND analysis) OR bioinformatics)", {"rettype" => "count"})
!
! Bio::PubMed.esearch2("(genome AND analysis) OR bioinformatics)").each do |x|
p x
end
***************
*** 218,221 ****
--- 257,261 ----
puts "--- Retrieve PubMed entry by E-Utils ---"
puts Bio::PubMed.efetch("10592173", "14693808")
+ puts Bio::PubMed.efetch2(["10592173", "14693808"], {"retmode" => "xml"})
puts "--- Search PubMed by Entrez CGI ---"
More information about the bioruby-cvs
mailing list