class Bio::OldBioFetchEmulator::Client

Constants

Databases

web.archive.org/web/20070306215757/http://bioruby.org/cgi-bin/biofetch.rb?info=dbs aa aax bl cpd dgenes dr ec eg emb embu epd est exp gb gbu genes gl gn gp gpu gss htgs ko ld lit mim nt og path pd pdb pdoc pf pir pmd pr prf ps rn rp rs rsaa rsnt sp str sts tr vg

Public Class Methods

new(url = URL) click to toggle source
Calls superclass method
# File lib/bio-old-biofetch-emulator/emulator.rb, line 173
def initialize(url = URL)
  super
end

Public Instance Methods

databases() click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 181
def databases
  Databases.collect do |key, val|
    while val && val.is_a?(String)
      val = Databases[val]
    end
    if val && val.is_a?(Array) && val[0] then
      key
    else
      nil
    end
  end.compact
end
fetch(db, id, style = 'raw', format = nil) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 177
def fetch(db, id, style = 'raw', format = nil)
  _fetch(:fetch, db, id, style, format)
end
formats(database = @database) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 194
def formats(database = @database)
  if database
    [ "default" ]
  end
end
maxids() click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 200
def maxids
  MAX_ID_NUM
end

Private Instance Methods

_fetch(cmd, db, id, style, format) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 205
def _fetch(cmd, db, id, style, format)
  db_orig = db
  db = db.to_s.downcase
  while a = Databases[db]
    case a
    when Array
      break
    when String
      db = a
    else
      break
    end
  end

  if !a and /[a-z]{3}/ =~ db then
    remote = :KEGG
    dbs = [ 'genes' ]
    id_prefix = db
  elsif a.is_a?(Array) then
    remote = a[0]
    dbs = a[1..-1]
    dbs.collect! { |x| x == true ? db : x }
  end
  
  if !remote then
    return "ERROR 1 Unknown database [#{db_orig.inspect}]"
  end
  
  ids = id.strip.split(/(?:\s*\,\s*|\s+)/)
  if ids.size > MAX_ID_NUM then
    return "ERROR 5 Too many IDs [#{ids.size}]. Max [#{MAX_ID_NUM}] allowed."
  end
  if id_prefix then
    ids.collect! { |x| "#{id_prefix}:#{x.strip}" }
  end

  case cmd
  when :fetch
    ret = case remote
          when :TogoWS
            _fetch_togows(cmd, dbs, ids)
          when :KEGG
            _fetch_kegg(cmd, dbs, ids)
          when :DBGET
            _fetch_dbget(cmd, dbs, ids)
          when :PubMed
            _fetch_pubmed(cmd, dbs, ids)
          else
      raise "Bug: unknown remote site #{remote.inspect}"
    end
  end
  ret
end
_fetch_dbget(cmd, dbs, ids) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 324
def _fetch_dbget(cmd, dbs, ids)
  all = []
  ids.each do |id|
    ret = nil
    dbs.each do |db|
      url = "http://www.genome.jp/dbget-bin/www_bget?#{CGI.escape(db)}:#{CGI.escape(id)}"
      begin
        ret = Bio::Command.read_uri(url)
      rescue OpenURI::HTTPError
        ret = nil
      end
      if ret then
        ret = _scrape_dbget(ret)
        break if ret
      end
      ret = nil
    end
    all.push ret if ret
  end
  if all.empty?
    return "Error 4 ID not found [#{ids.inspect}]"
  else
    return all.join("")
  end
end
_fetch_kegg(cmd, dbs, ids) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 294
def _fetch_kegg(cmd, dbs, ids)
  all = []
  ids.each do |id|
    ret = nil
    dbs.each do |db|
      if db == "genes" then
        url = "http://rest.kegg.jp/get/#{CGI.escape(id)}"
      else
        url = "http://rest.kegg.jp/get/#{CGI.escape(db)}:#{CGI.escape(id)}"
      end
      begin
        ret = Bio::Command.read_uri(url)
      rescue OpenURI::HTTPError
        ret = nil
      end
      if ret && ret.strip.size > 0 then
        break
      else
        ret = nil
      end
    end
    all.push ret if ret
  end
  if all.empty?
    return "Error 4 ID not found [#{ids.inspect}]"
  else
    return all.join("")
  end
end
_fetch_pubmed(cmd, dbs, ids) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 259
def _fetch_pubmed(cmd, dbs, ids)
  a = Bio::PubMed.efetch(ids)
  if a && a.size > 0 then
    a.join("\n\n") + "\n"
  else
    "Error 4 ID not found [#{ids.inspect}]"
  end
end
_fetch_togows(cmd, dbs, ids) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 268
def _fetch_togows(cmd, dbs, ids)
  all = []
  ids.each do |id|
    ret = nil
    dbs.each do |db|
      url = "http://togows.org/entry/#{CGI.escape(db)}/#{CGI.escape(id)}"
      begin
        ret = Bio::Command.read_uri(url)
      rescue OpenURI::HTTPError
        ret = nil
      end
      if ret && /\AError/ !~ ret && ret.strip.size > 0 then
        break
      else
        ret = nil
      end
    end
    all.push ret if ret
  end
  if all.empty?
    return "Error 4 ID not found [#{ids.inspect}]"
  else
    return all.join("")
  end
end
_scrape_dbget(orig_str) click to toggle source
# File lib/bio-old-biofetch-emulator/emulator.rb, line 350
def _scrape_dbget(orig_str)
  a = orig_str.split(/^\s*\<\!\-\- bget\:result \-\-\>$\s*/)
  if a[1] then
    str = a[1]
    str.sub!(/\A\s*\<pre\>$\s*/, "")
    str.sub!(/^\s*\<\/pre\>.*/m, "")
    str.gsub!(/\<[^\>]+\>/, "")
    return str
  end
  nil
end