Class: Wrnap::Rna::Box
- Inherits:
-
Object
- Object
- Wrnap::Rna::Box
- Extended by:
- Forwardable
- Includes:
- Enumerable, MetaMissing, Global::Yaml
- Defined in:
- lib/wrnap/rna/box.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#rnas ⇒ Object
readonly
Returns the value of attribute rnas.
Class Method Summary collapse
Instance Method Summary collapse
- #+(arrayish) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(rnas, name = "") ⇒ Box
constructor
A new instance of Box.
- #inspect ⇒ Object
- #kind_of?(klass) ⇒ Boolean
- #pp ⇒ Object
- #run_in_parallel(method, *args) ⇒ Object
- #write_fa!(filename) ⇒ Object
Methods included from Global::Yaml
Constructor Details
#initialize(rnas, name = "") ⇒ Box
Returns a new instance of Box.
21 22 23 |
# File 'lib/wrnap/rna/box.rb', line 21 def initialize(rnas, name = "") @rnas, @name = rnas.kind_of?(Array) ? rnas : [rnas], name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/wrnap/rna/box.rb', line 10 def name @name end |
#rnas ⇒ Object (readonly)
Returns the value of attribute rnas.
9 10 11 |
# File 'lib/wrnap/rna/box.rb', line 9 def rnas @rnas end |
Class Method Details
.load_all(pattern = "*.fa", &block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/wrnap/rna/box.rb', line 13 def load_all(pattern = "*.fa", &block) new(Dir[File.directory?(pattern) ? File.join(pattern, "*.fa") : pattern].inject([]) do |array, file| loaded_rnas = RNA.from_fasta(file, &block) array + (loaded_rnas.is_a?(Box) ? loaded_rnas.rnas : [loaded_rnas]) end) end |
Instance Method Details
#+(arrayish) ⇒ Object
35 36 37 |
# File 'lib/wrnap/rna/box.rb', line 35 def +(arrayish) self.class.new(rnas + (arrayish.is_a?(Box) ? arrayish.rnas : arrayish)) end |
#each(&block) ⇒ Object
41 42 43 44 |
# File 'lib/wrnap/rna/box.rb', line 41 def each(&block) return enum_for(:each) unless block_given? rnas.each(&block) end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/wrnap/rna/box.rb', line 59 def inspect ("#<Wrnap::Rna::Box %s with %d RNAs>" % [name, rnas.size]).gsub(/\s\s+/, " ") end |
#kind_of?(klass) ⇒ Boolean
51 52 53 |
# File 'lib/wrnap/rna/box.rb', line 51 def kind_of?(klass) klass == Array ? true : super end |
#pp ⇒ Object
31 32 33 |
# File 'lib/wrnap/rna/box.rb', line 31 def pp rnas.each(&:pp) and nil end |
#run_in_parallel(method, *args) ⇒ Object
46 47 48 49 |
# File 'lib/wrnap/rna/box.rb', line 46 def run_in_parallel(method, *args) Wrnap.debug, debug_status = false, Wrnap.debug Parallel.map(self, progress: "Calling %s on %d RNAs" % [method, rnas.size]) { |rna| rna.send(method, *args) }.tap { Wrnap.debug = debug_status } end |
#write_fa!(filename) ⇒ Object
25 26 27 28 29 |
# File 'lib/wrnap/rna/box.rb', line 25 def write_fa!(filename) filename.tap do |filename| File.open(filename, ?w) { |file| file.write(rnas.map(&:formatted_string).join(?\n) + ?\n) } end end |