Class: Bio::Registry

Inherits:
Object show all
Defined in:
lib/bio/io/registry.rb

Defined Under Namespace

Classes: DB

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Registry

Returns a new instance of Registry.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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

Instance Attribute Details

#databasesObject (readonly)

List of databases (Array of Bio::Registry::DB)



119
120
121
# File 'lib/bio/io/registry.rb', line 119

def databases
  @databases
end

#spec_versionObject (readonly)

Version string of the first configulation file



116
117
118
# File 'lib/bio/io/registry.rb', line 116

def spec_version
  @spec_version
end

Instance Method Details

#get_database(dbname) ⇒ Object Also known as: db

Returns a dababase handle (Bio::SQL, Bio::Fetch etc.) or nil if not found (case insensitive). The handles should have get_by_id method.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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

#query(dbname) ⇒ Object

Returns a Registry::DB object corresponding to the first dbname entry in the registry records (case insensitive).



147
148
149
150
151
# File 'lib/bio/io/registry.rb', line 147

def query(dbname)
  @databases.each do |db|
    return db if db.database == dbname.downcase
  end
end