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 99 def initialize(file = nil) 100 @spec_version = nil 101 @databases = Array.new 102 read_local(file) if file 103 env_path = ENV['OBDA_SEARCH_PATH'] 104 if env_path and env_path.size > 0 105 read_env(env_path) 106 else 107 read_local("#{ENV['HOME']}/.bioinformatics/seqdatabase.ini") 108 read_local("/etc/bioinformatics/seqdatabase.ini") 109 if @databases.empty? 110 read_remote("http://www.open-bio.org/registry/seqdatabase.ini") 111 end 112 end 113 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 124 def get_database(dbname) 125 @databases.each do |db| 126 if db.database == dbname.downcase 127 case db.protocol 128 when 'biofetch' 129 return serv_biofetch(db) 130 when 'biosql' 131 return serv_biosql(db) 132 when 'flat', 'index-flat', 'index-berkeleydb' 133 return serv_flat(db) 134 when 'bsane-corba', 'biocorba' 135 raise NotImplementedError 136 when 'xembl' 137 raise NotImplementedError 138 end 139 end 140 end 141 return nil 142 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 147 def query(dbname) 148 @databases.each do |db| 149 return db if db.database == dbname.downcase 150 end 151 end
Private Instance Methods
parse_stanza(stanza)
click to toggle source
# File lib/bio/io/registry.rb 180 def parse_stanza(stanza) 181 return unless stanza 182 if stanza[/.*/] =~ /VERSION\s*=\s*(\S+)/ 183 @spec_version ||= $1 # for internal use (may differ on each file) 184 stanza[/.*/] = '' # remove VERSION line 185 end 186 stanza.each_line do |line| 187 case line 188 when /^\[(.*)\]/ 189 dbname = $1.downcase 190 db = Bio::Registry::DB.new($1) 191 @databases.push(db) 192 when /=/ 193 tag, value = line.chomp.split(/\s*=\s*/) 194 @databases.last[tag] = value 195 end 196 end 197 end
read_env(path)
click to toggle source
# File lib/bio/io/registry.rb 155 def read_env(path) 156 path.split('+').each do |elem| 157 if /:/.match(elem) 158 read_remote(elem) 159 else 160 read_local(elem) 161 end 162 end 163 end
read_local(file)
click to toggle source
# File lib/bio/io/registry.rb 165 def read_local(file) 166 if File.readable?(file) 167 stanza = File.read(file) 168 parse_stanza(stanza) 169 end 170 end
read_remote(url)
click to toggle source
# File lib/bio/io/registry.rb 172 def read_remote(url) 173 schema, user, host, port, reg, path, = URI.split(url) 174 Bio::Command.start_http(host, port) do |http| 175 response = http.get(path) 176 parse_stanza(response.body) 177 end 178 end
serv_biofetch(db)
click to toggle source
# File lib/bio/io/registry.rb 199 def serv_biofetch(db) 200 serv = Bio::Fetch.new(db.location) 201 serv.database = db.dbname 202 return serv 203 end
serv_biosql(db)
click to toggle source
# File lib/bio/io/registry.rb 205 def serv_biosql(db) 206 location, port = db.location.split(':') 207 port = db.port unless port 208 209 case db.driver 210 when /mysql/i 211 driver = 'Mysql' 212 when /pg|postgres/i 213 driver = 'Pg' 214 when /oracle/ 215 when /sybase/ 216 when /sqlserver/ 217 when /access/ 218 when /csv/ 219 when /informix/ 220 when /odbc/ 221 when /rdb/ 222 end 223 224 dbi = [ "dbi", driver, db.dbname, location ].compact.join(':') 225 dbi += ';port=' + port if port 226 serv = Bio::SQL.new(dbi, db.user, db.pass) 227 228 # We can not manage biodbname (for name space) in BioSQL yet. 229 # use db.biodbname here!! 230 231 return serv 232 end
serv_flat(db)
click to toggle source
# File lib/bio/io/registry.rb 234 def serv_flat(db) 235 path = db.location 236 path = File.join(path, db.dbname) if db.dbname 237 serv = Bio::FlatFileIndex.open(path) 238 return serv 239 end