[BioRuby-cvs] bioruby/lib/bio/io pubmed.rb,1.21,1.22

Katayama Toshiaki k at dev.open-bio.org
Wed Nov 28 06:34:35 UTC 2007


Update of /home/repository/bioruby/bioruby/lib/bio/io
In directory dev.open-bio.org:/tmp/cvs-serv23044

Modified Files:
	pubmed.rb 
Log Message:
* all class methods are changed to instance methods (class methods are
  still remained for the backward compatibility)


Index: pubmed.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/pubmed.rb,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** pubmed.rb	20 Nov 2007 15:22:03 -0000	1.21
--- pubmed.rb	28 Nov 2007 06:34:33 -0000	1.22
***************
*** 79,83 ****
    @@last_access = nil
  
!   def self.ncbi_access_wait(wait = NCBI_INTERVAL)
      if @@last_access
        duration = Time.now - @@last_access
--- 79,85 ----
    @@last_access = nil
  
!   private
! 
!   def ncbi_access_wait(wait = NCBI_INTERVAL)
      if @@last_access
        duration = Time.now - @@last_access
***************
*** 89,92 ****
--- 91,96 ----
    end
  
+   public
+ 
    # Search the PubMed database by given keywords using E-Utils and returns 
    # an array of PubMed IDs.
***************
*** 107,111 ****
    # * _rettype_
    # *Returns*:: array of PubMed IDs or a number of results
!   def self.esearch(str, hash = {})
      return nil if str.empty?
  
--- 111,115 ----
    # * _rettype_
    # *Returns*:: array of PubMed IDs or a number of results
!   def esearch(str, hash = {})
      return nil if str.empty?
  
***************
*** 119,123 ****
      opts.update(hash)
  
!     self.ncbi_access_wait
  
      response, = Bio::Command.post_form(serv, opts)
--- 123,127 ----
      opts.update(hash)
  
!     ncbi_access_wait
  
      response, = Bio::Command.post_form(serv, opts)
***************
*** 139,143 ****
    # * _ids_: list of PubMed IDs (required)
    # *Returns*:: Array of MEDLINE formatted String
!   def self.efetch(ids, hash = {})
      return nil if ids.to_s.empty?
      ids = ids.join(",") if ids === Array
--- 143,147 ----
    # * _ids_: list of PubMed IDs (required)
    # *Returns*:: Array of MEDLINE formatted String
!   def efetch(ids, hash = {})
      return nil if ids.to_s.empty?
      ids = ids.join(",") if ids === Array
***************
*** 153,157 ****
      opts.update(hash)
  
!     self.ncbi_access_wait
  
      response, = Bio::Command.post_form(serv, opts)
--- 157,161 ----
      opts.update(hash)
  
!     ncbi_access_wait
  
      response, = Bio::Command.post_form(serv, opts)
***************
*** 170,177 ****
    # * _id_: query string (required)
    # *Returns*:: array of PubMed IDs
!   def self.search(str)
      host = "www.ncbi.nlm.nih.gov"
      path = "/sites/entrez?tool=bioruby&cmd=Search&doptcmdl=Brief&db=PubMed&term="
  
      http = Bio::Command.new_http(host)
      response, = http.get(path + CGI.escape(str))
--- 174,183 ----
    # * _id_: query string (required)
    # *Returns*:: array of PubMed IDs
!   def search(str)
      host = "www.ncbi.nlm.nih.gov"
      path = "/sites/entrez?tool=bioruby&cmd=Search&doptcmdl=Brief&db=PubMed&term="
  
+     ncbi_access_wait
+ 
      http = Bio::Command.new_http(host)
      response, = http.get(path + CGI.escape(str))
***************
*** 187,196 ****
    # * _id_: PubMed ID (required)
    # *Returns*:: MEDLINE formatted String
!   def self.query(*ids)
      host = "www.ncbi.nlm.nih.gov"
      path = "/sites/entrez?tool=bioruby&cmd=Text&dopt=MEDLINE&db=PubMed&uid="
- 
      list = ids.join(",")
  
      http = Bio::Command.new_http(host)
      response, = http.get(path + list)
--- 193,203 ----
    # * _id_: PubMed ID (required)
    # *Returns*:: MEDLINE formatted String
!   def query(*ids)
      host = "www.ncbi.nlm.nih.gov"
      path = "/sites/entrez?tool=bioruby&cmd=Text&dopt=MEDLINE&db=PubMed&uid="
      list = ids.join(",")
  
+     ncbi_access_wait
+ 
      http = Bio::Command.new_http(host)
      response, = http.get(path + list)
***************
*** 216,223 ****
    # * _id_: PubMed ID (required)
    # *Returns*:: MEDLINE formatted String
!   def self.pmfetch(id)
      host = "www.ncbi.nlm.nih.gov"
      path = "/entrez/utils/pmfetch.fcgi?tool=bioruby&mode=text&report=medline&db=PubMed&id="
  
      http = Bio::Command.new_http(host)
      response, = http.get(path + id.to_s)
--- 223,232 ----
    # * _id_: PubMed ID (required)
    # *Returns*:: MEDLINE formatted String
!   def pmfetch(id)
      host = "www.ncbi.nlm.nih.gov"
      path = "/entrez/utils/pmfetch.fcgi?tool=bioruby&mode=text&report=medline&db=PubMed&id="
  
+     ncbi_access_wait
+ 
      http = Bio::Command.new_http(host)
      response, = http.get(path + id.to_s)
***************
*** 231,234 ****
--- 240,263 ----
    end
  
+   def self.esearch(*args)
+     self.new.esearch(*args)
+   end
+ 
+   def self.efetch(*args)
+     self.new.efetch(*args)
+   end
+ 
+   def self.search(*args)
+     self.new.search(*args)
+   end
+ 
+   def self.query(*args)
+     self.new.query(*args)
+   end
+ 
+   def self.pmfetch(*args)
+     self.new.pmfetch(*args)
+   end
+ 
  end # PubMed
  
***************
*** 238,241 ****
--- 267,316 ----
  if __FILE__ == $0
  
+   puts "=== instance methods ==="
+ 
+   pubmed = Bio::PubMed.new
+ 
+   puts "--- Search PubMed by E-Utils ---"
+   opts = {"rettype" => "count"}
+   puts Time.now
+   puts pubmed.esearch("(genome AND analysis) OR bioinformatics)", opts)
+   puts Time.now
+   puts pubmed.esearch("(genome AND analysis) OR bioinformatics)", opts)
+   puts Time.now
+   puts pubmed.esearch("(genome AND analysis) OR bioinformatics)", opts)
+   puts Time.now
+   pubmed.esearch("(genome AND analysis) OR bioinformatics)").each do |x|
+     puts x
+   end
+ 
+   puts "--- Retrieve PubMed entry by E-Utils ---"
+   puts Time.now
+   puts pubmed.efetch(16381885)
+   puts Time.now
+   puts pubmed.efetch("16381885")
+   puts Time.now
+   puts pubmed.efetch("16381885")
+   puts Time.now
+   opts = {"retmode" => "xml"}
+   puts pubmed.efetch([10592173, 14693808], opts)
+   puts Time.now
+   puts pubmed.efetch(["10592173", "14693808"], opts)
+ 
+   puts "--- Search PubMed by Entrez CGI ---"
+   pubmed.search("(genome AND analysis) OR bioinformatics)").each do |x|
+     p x
+   end
+ 
+   puts "--- Retrieve PubMed entry by Entrez CGI ---"
+   puts pubmed.query("16381885")
+ 
+ 
+   puts "--- Retrieve PubMed entry by PMfetch ---"
+   puts pubmed.pmfetch("16381885")
+ 
+ 
+   puts "=== class methods ==="
+ 
+ 
    puts "--- Search PubMed by E-Utils ---"
    opts = {"rettype" => "count"}




More information about the bioruby-cvs mailing list