Class: Bio::SQL

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

Defined Under Namespace

Classes: Sequence

Instance Method Summary collapse

Constructor Details

#initialize(db = 'dbi:Mysql:biosql', user = nil, pass = nil) ⇒ SQL

Returns a new instance of SQL.



23
24
25
# File 'lib/bio/io/sql.rb', line 23

def initialize(db = 'dbi:Mysql:biosql', user = nil, pass = nil)
  @dbh = DBI.connect(db, user, pass)
end

Instance Method Details

#closeObject



27
28
29
# File 'lib/bio/io/sql.rb', line 27

def close
  @dbh.disconnect
end

#fetch(accession) ⇒ Object Also known as: get_by_id

Returns Bio::SQL::Sequence object.



32
33
34
35
36
37
38
39
40
# File 'lib/bio/io/sql.rb', line 32

def fetch(accession)	# or display_id for fall back
  query = "select * from bioentry where accession = ?"
  entry = @dbh.execute(query, accession).fetch
  return Sequence.new(@dbh, entry) if entry

  query = "select * from bioentry where display_id = ?"
  entry = @dbh.execute(query, accession).fetch
  return Sequence.new(@dbh, entry) if entry
end