Class: GeneValidatorApp::Database
- Inherits:
-
Struct
- Object
- Struct
- GeneValidatorApp::Database
- Extended by:
- Forwardable
- Defined in:
- lib/genevalidatorapp/database.rb
Overview
class on the BLAST databases
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .<<(database) ⇒ Object
- .[](ids) ⇒ Object
- .all ⇒ Object
- .collection ⇒ Object
- .default_db ⇒ Object
- .each(&block) ⇒ Object
- .first ⇒ Object
- .group_by(&block) ⇒ Object
- .ids ⇒ Object
- .include?(path) ⇒ Boolean
-
.multipart_database_name?(db_name) ⇒ Boolean
Returns true if the database name appears to be a multi-part database name.
- .non_default_dbs ⇒ Object
-
.obtain_original_structure(db_title) ⇒ Object
Returns the original structure that the title is within.
-
.scan_databases_dir ⇒ Object
Recurisvely scan ‘database_dir` for blast databases.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Database
constructor
A new instance of Database.
- #to_s ⇒ Object
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
103 104 105 |
# File 'lib/genevalidatorapp/database.rb', line 103 def id @id end |
#name ⇒ Object
Returns the value of attribute name
7 8 9 |
# File 'lib/genevalidatorapp/database.rb', line 7 def name @name end |
#title ⇒ Object
Returns the value of attribute title
7 8 9 |
# File 'lib/genevalidatorapp/database.rb', line 7 def title @title end |
#type ⇒ Object
Returns the value of attribute 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 |
.all ⇒ Object
32 33 34 |
# File 'lib/genevalidatorapp/database.rb', line 32 def all collection.values end |
.collection ⇒ Object
13 14 15 |
# File 'lib/genevalidatorapp/database.rb', line 13 def collection @collection ||= {} end |
.default_db ⇒ Object
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 |
.first ⇒ Object
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 |
.ids ⇒ Object
28 29 30 |
# File 'lib/genevalidatorapp/database.rb', line 28 def ids collection.keys end |
.include?(path) ⇒ 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
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_dbs ⇒ Object
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_dir ⇒ Object
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_s ⇒ Object
105 106 107 |
# File 'lib/genevalidatorapp/database.rb', line 105 def to_s "#{type}: #{title} #{name}" end |