Class: Wrnap::Rna::Box

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, MetaMissing, Global::Yaml
Defined in:
lib/wrnap/rna/box.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Global::Yaml

#deserialize, #serialize

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

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/wrnap/rna/box.rb', line 10

def name
  @name
end

#rnasObject (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

#inspectObject



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

Returns:

  • (Boolean)


51
52
53
# File 'lib/wrnap/rna/box.rb', line 51

def kind_of?(klass)
  klass == Array ? true : super
end

#ppObject



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