class Bio::Registry
Attributes
databases[R]
List of databases (Array of Bio::Registry::DB)
spec_version[R]
Version string of the first configulation file
Public Class Methods
new(file = nil)
click to toggle source
# File lib/bio/io/registry.rb, line 99 def initialize(file = nil) @spec_version = nil @databases = Array.new read_local(file) if file env_path = ENV['OBDA_SEARCH_PATH'] if env_path and env_path.size > 0 read_env(env_path) else read_local("#{ENV['HOME']}/.bioinformatics/seqdatabase.ini") read_local("/etc/bioinformatics/seqdatabase.ini") if @databases.empty? read_remote("http://www.open-bio.org/registry/seqdatabase.ini") end end end
Public Instance Methods
get_database(dbname)
click to toggle source
Returns a dababase handle (Bio::SQL, Bio::Fetch etc.) or nil if not found (case insensitive). The handles should have get_by_id method.
# File lib/bio/io/registry.rb, line 124 def get_database(dbname) @databases.each do |db| if db.database == dbname.downcase case db.protocol when 'biofetch' return serv_biofetch(db) when 'biosql' return serv_biosql(db) when 'flat', 'index-flat', 'index-berkeleydb' return serv_flat(db) when 'bsane-corba', 'biocorba' raise NotImplementedError when 'xembl' raise NotImplementedError end end end return nil end
Also aliased as: db
query(dbname)
click to toggle source
Returns a Registry::DB object corresponding to the first dbname entry in the registry records (case insensitive).
# File lib/bio/io/registry.rb, line 147 def query(dbname) @databases.each do |db| return db if db.database == dbname.downcase end end
Private Instance Methods
parse_stanza(stanza)
click to toggle source
# File lib/bio/io/registry.rb, line 180 def parse_stanza(stanza) return unless stanza if stanza[/.*/] =~ /VERSION\s*=\s*(\S+)/ @spec_version ||= $1 # for internal use (may differ on each file) stanza[/.*/] = '' # remove VERSION line end stanza.each_line do |line| case line when /^\[(.*)\]/ dbname = $1.downcase db = Bio::Registry::DB.new($1) @databases.push(db) when /=/ tag, value = line.chomp.split(/\s*=\s*/) @databases.last[tag] = value end end end
read_env(path)
click to toggle source
# File lib/bio/io/registry.rb, line 155 def read_env(path) path.split('+').each do |elem| if /:/.match(elem) read_remote(elem) else read_local(elem) end end end
read_local(file)
click to toggle source
# File lib/bio/io/registry.rb, line 165 def read_local(file) if File.readable?(file) stanza = File.read(file) parse_stanza(stanza) end end
read_remote(url)
click to toggle source
# File lib/bio/io/registry.rb, line 172 def read_remote(url) schema, user, host, port, reg, path, = URI.split(url) Bio::Command.start_http(host, port) do |http| response = http.get(path) parse_stanza(response.body) end end
serv_biofetch(db)
click to toggle source
# File lib/bio/io/registry.rb, line 199 def serv_biofetch(db) serv = Bio::Fetch.new(db.location) serv.database = db.dbname return serv end
serv_biosql(db)
click to toggle source
# File lib/bio/io/registry.rb, line 205 def serv_biosql(db) location, port = db.location.split(':') port = db.port unless port case db.driver when /mysql/i driver = 'Mysql' when /pg|postgres/i driver = 'Pg' when /oracle/ when /sybase/ when /sqlserver/ when /access/ when /csv/ when /informix/ when /odbc/ when /rdb/ end dbi = [ "dbi", driver, db.dbname, location ].compact.join(':') dbi += ';port=' + port if port serv = Bio::SQL.new(dbi, db.user, db.pass) # We can not manage biodbname (for name space) in BioSQL yet. # use db.biodbname here!! return serv end
serv_flat(db)
click to toggle source
# File lib/bio/io/registry.rb, line 234 def serv_flat(db) path = db.location path = File.join(path, db.dbname) if db.dbname serv = Bio::FlatFileIndex.open(path) return serv end