Class: Ensembl::Variation::DBConnection

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/ensembl/db_connection.rb

Overview

DESCRIPTION

The Ensembl::Variation::DBConnection is the actual connection established with the Ensembl server.

Class Method Summary collapse

Class Method Details

.connect(species, release = Ensembl::ENSEMBL_RELEASE, args = {}) ⇒ Object

DESCRIPTION

The Ensembl::Variation::DBConnection#connect method makes the connection to the Ensembl variation database for a given species. By default, it connects to release 50 for that species. You could use a lower number, but some parts of the API might not work, or worse: give the wrong results.

USAGE

# Connect to release 50 of human
Ensembl::Variation::DBConnection.connect('homo_sapiens')

# Connect to release 42 of chicken
Ensembl::Variation::DBConnection.connect('gallus_gallus')

Arguments:

  • species

    species to connect to. Arguments should be in snake_case

  • ensembl_release

    the release of the database to connect to

(default = 50)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ensembl/db_connection.rb', line 119

def self.connect(species, release = Ensembl::ENSEMBL_RELEASE, args = {})
  dummy_dbconnection = ( release > 47 ) ? Ensembl::NewDummyDBConnection.connection : Ensembl::OldDummyDBConnection.connection
  db_name = nil
  if args[:database]
    db_name = args[:database]
  else  
    db_name = dummy_dbconnection.select_values('show databases').select{|v| v =~ /#{species}_variation_#{release.to_s}/}[0]
  end
  
  if db_name.nil?
    warn "WARNING: No connection to database established. Check that the species is in snake_case (was: #{species})."
  else
    port = ( release > 47 ) ? 5306 : nil
    establish_connection(
                        :adapter => Ensembl::DB_ADAPTER,
                        :host => args[:host] || Ensembl::DB_HOST,
                        :database => db_name,
                        :username => args[:username] || Ensembl::DB_USERNAME,
                        :password => args[:password] || Ensembl::DB_PASSWORD,
                        :port => args[:port] || port
                      )
    self.retrieve_connection                                                                                                                             
  end
  
end