class GeneValidatorApp::Database

class on the BLAST databases

Attributes

id[R]

Public Class Methods

<<(database) click to toggle source
# File lib/genevalidatorapp/database.rb, line 19
def <<(database)
  collection[database.id] = database
end
[](ids) click to toggle source
# File lib/genevalidatorapp/database.rb, line 23
def [](ids)
  ids = Array ids
  collection.values_at(*ids)
end
all() click to toggle source
# File lib/genevalidatorapp/database.rb, line 32
def all
  collection.values
end
default_db() click to toggle source
# File lib/genevalidatorapp/database.rb, line 52
def default_db
  if config[:default_db] && Database.include?(config[:default_db])
    all.find { |a| a.name == config[:default_db] }
  else
    all.first
  end
end
each(&block) click to toggle source
# File lib/genevalidatorapp/database.rb, line 36
def each(&block)
  all.each(&block)
end
first() click to toggle source
# File lib/genevalidatorapp/database.rb, line 48
def first
  all.first
end
group_by(&block) click to toggle source
# File lib/genevalidatorapp/database.rb, line 44
def group_by(&block)
  all.group_by(&block)
end
ids() click to toggle source
# File lib/genevalidatorapp/database.rb, line 28
def ids
  collection.keys
end
include?(path) click to toggle source
# File lib/genevalidatorapp/database.rb, line 40
def include?(path)
  collection.include? Digest::MD5.hexdigest path
end
multipart_database_name?(db_name) click to toggle source

Returns true if the database name appears to be a multi-part database name.

e.g. /home/ben/pd.ben/sequenceserver/db/nr.00 => yes /home/ben/pd.ben/sequenceserver/db/nr => no /home/ben/pd.ben/sequenceserver/db/img3.5.finished.faa.01 => yes

# File lib/genevalidatorapp/database.rb, line 90
def multipart_database_name?(db_name)
  !db_name.match(%r{.+\/\S+\d{2}$}).nil?
end
new(*args) click to toggle source
Calls superclass method
# File lib/genevalidatorapp/database.rb, line 95
def initialize(*args)
  args.last.downcase!
  args.each(&:freeze)
  super

  @id = Digest::MD5.hexdigest args.first
end
non_default_dbs() click to toggle source
# File lib/genevalidatorapp/database.rb, line 60
def non_default_dbs
  all.find_all { |a| a != Database.default_db }
end
obtain_original_structure(db_title) click to toggle source

Returns the original structure that the title is within.

# File lib/genevalidatorapp/database.rb, line 65
def obtain_original_structure(db_title)
  all.find_all { |a| a.title.chomp == db_title }
end
scan_databases_dir() click to toggle source

Recurisvely scan `database_dir` for blast databases.

# File lib/genevalidatorapp/database.rb, line 70
def scan_databases_dir
  database_dir = config[:database_dir]
  cmd  = "blastdbcmd -recursive -list #{database_dir} -list_outfmt" \
         ' "%p::%f::%t"'
  list = `#{cmd} 2>&1`
  list.each_line do |line|
    type, name, title = line.split('::', 3)
    next if multipart_database_name?(name)
    next unless type.casecmp('protein').zero?
    self << Database.new(name, title, type)
  end
end

Private Class Methods

collection() click to toggle source
# File lib/genevalidatorapp/database.rb, line 13
def collection
  @collection ||= {}
end

Public Instance Methods

to_s() click to toggle source
# File lib/genevalidatorapp/database.rb, line 105
def to_s
  "#{type}: #{title} #{name}"
end