Class: GeneValidatorApp::Database

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/genevalidatorapp/database.rb

Overview

class on the BLAST databases

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Database

Returns a new instance of Database.



95
96
97
98
99
100
101
# File 'lib/genevalidatorapp/database.rb', line 95

def initialize(*args)
  args.last.downcase!
  args.each(&:freeze)
  super

  @id = Digest::MD5.hexdigest args.first
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



103
104
105
# File 'lib/genevalidatorapp/database.rb', line 103

def id
  @id
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



7
8
9
# File 'lib/genevalidatorapp/database.rb', line 7

def name
  @name
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



7
8
9
# File 'lib/genevalidatorapp/database.rb', line 7

def title
  @title
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



7
8
9
# File 'lib/genevalidatorapp/database.rb', line 7

def type
  @type
end

Class Method Details

.<<(database) ⇒ Object



19
20
21
# File 'lib/genevalidatorapp/database.rb', line 19

def <<(database)
  collection[database.id] = database
end

.[](ids) ⇒ Object



23
24
25
26
# File 'lib/genevalidatorapp/database.rb', line 23

def [](ids)
  ids = Array ids
  collection.values_at(*ids)
end

.allObject



32
33
34
# File 'lib/genevalidatorapp/database.rb', line 32

def all
  collection.values
end

.collectionObject



13
14
15
# File 'lib/genevalidatorapp/database.rb', line 13

def collection
  @collection ||= {}
end

.default_dbObject



52
53
54
55
56
57
58
# 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) ⇒ Object



36
37
38
# File 'lib/genevalidatorapp/database.rb', line 36

def each(&block)
  all.each(&block)
end

.firstObject



48
49
50
# File 'lib/genevalidatorapp/database.rb', line 48

def first
  all.first
end

.group_by(&block) ⇒ Object



44
45
46
# File 'lib/genevalidatorapp/database.rb', line 44

def group_by(&block)
  all.group_by(&block)
end

.idsObject



28
29
30
# File 'lib/genevalidatorapp/database.rb', line 28

def ids
  collection.keys
end

.include?(path) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/genevalidatorapp/database.rb', line 40

def include?(path)
  collection.include? Digest::MD5.hexdigest path
end

.multipart_database_name?(db_name) ⇒ Boolean

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

Returns:

  • (Boolean)


90
91
92
# File 'lib/genevalidatorapp/database.rb', line 90

def multipart_database_name?(db_name)
  !db_name.match(%r{.+\/\S+\d{2}$}).nil?
end

.non_default_dbsObject



60
61
62
# 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) ⇒ Object

Returns the original structure that the title is within.



65
66
67
# 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_dirObject

Recurisvely scan ‘database_dir` for blast databases.



70
71
72
73
74
75
76
77
78
79
80
81
# 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

Instance Method Details

#to_sObject



105
106
107
# File 'lib/genevalidatorapp/database.rb', line 105

def to_s
  "#{type}: #{title} #{name}"
end