Class: ViennaRna::Rna
- Inherits:
-
Object
- Object
- ViennaRna::Rna
- Includes:
- RnaExtensions
- Defined in:
- lib/vienna_rna/modules/rna.rb
Instance Attribute Summary collapse
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#sequence ⇒ Object
(also: #seq)
readonly
Returns the value of attribute sequence.
-
#structure ⇒ Object
(also: #str)
readonly
Returns the value of attribute structure.
Class Method Summary collapse
- .init_from_array(array) ⇒ Object
- .init_from_fasta(string) ⇒ Object
- .init_from_hash(hash) ⇒ Object
- .init_from_self(rna) ⇒ Object
- .init_from_string(sequence, structure = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(sequence, structure, raw_data = {}) ⇒ Rna
constructor
A new instance of Rna.
- #inspect ⇒ Object
- #run(module_name, options = {}) ⇒ Object
- #write_fa!(filename, comment = "") ⇒ Object
Methods included from RnaExtensions
Constructor Details
#initialize(sequence, structure, raw_data = {}) ⇒ Rna
Returns a new instance of Rna.
30 31 32 33 34 35 36 37 38 |
# File 'lib/vienna_rna/modules/rna.rb', line 30 def initialize(sequence, structure, raw_data = {}) @sequence, @raw_data = sequence, raw_data @structure = case structure when :empty then empty_structure when :mfe then ViennaRna::Fold.run(Rna.init_from_string(seq)).structure when String then structure end end |
Instance Attribute Details
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
5 6 7 |
# File 'lib/vienna_rna/modules/rna.rb', line 5 def raw_data @raw_data end |
#sequence ⇒ Object (readonly) Also known as: seq
Returns the value of attribute sequence.
5 6 7 |
# File 'lib/vienna_rna/modules/rna.rb', line 5 def sequence @sequence end |
#structure ⇒ Object (readonly) Also known as: str
Returns the value of attribute structure.
5 6 7 |
# File 'lib/vienna_rna/modules/rna.rb', line 5 def structure @structure end |
Class Method Details
.init_from_array(array) ⇒ Object
16 17 18 |
# File 'lib/vienna_rna/modules/rna.rb', line 16 def init_from_array(array) new(*array) end |
.init_from_fasta(string) ⇒ Object
20 21 22 |
# File 'lib/vienna_rna/modules/rna.rb', line 20 def init_from_fasta(string) init_from_string(*string.split(/\n/).reject { |line| line.start_with?(">") }) end |
.init_from_hash(hash) ⇒ Object
12 13 14 |
# File 'lib/vienna_rna/modules/rna.rb', line 12 def init_from_hash(hash) new(hash[:sequence] || hash[:seq], hash[:structure] || hash[:str], hash) end |
.init_from_self(rna) ⇒ Object
24 25 26 27 |
# File 'lib/vienna_rna/modules/rna.rb', line 24 def init_from_self(rna) # This happens when you call a ViennaRna library function with the output of something like ViennaRna::Fold.run(...).mfe new(rna.sequence, rna.structure, rna.raw_data) end |
.init_from_string(sequence, structure = nil) ⇒ Object
8 9 10 |
# File 'lib/vienna_rna/modules/rna.rb', line 8 def init_from_string(sequence, structure = nil) new(sequence, structure) end |
Instance Method Details
#inspect ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vienna_rna/modules/rna.rb', line 44 def inspect case [sequence.present?, structure.present?] when [true, true] then "#<#{self.class.name} #{seq[0, 20] + (seq.length > 20 ? '...' : '')} #{str[0, 20] + (str.length > 20 ? ' [truncated]' : '')}>" when [true, false] then "#<#{self.class.name} #{seq[0, 20] + (seq.length > 20 ? '...' : '')}>" when [false, false] then "#<#{self.class.name}>" end end |
#run(module_name, options = {}) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/vienna_rna/modules/rna.rb', line 65 def run(module_name, = {}) if rna_module = ViennaRna.const_missing("#{module_name}".camelize) rna_module.run(self, ) else raise ArgumentError.new("#{module_name} can't be resolved as an executable") end end |
#write_fa!(filename, comment = "") ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/vienna_rna/modules/rna.rb', line 55 def write_fa!(filename, comment = "") (File.basename(filename, ".fa") + ".fa").tap do |filename| File.open(filename, "w") do |file| file.write("> %s\n" % comment) if comment file.write("%s\n" % seq) if seq file.write("%s\n" % str) if str end end end |