Class: Bioinform::MotifModel::PM
- Inherits:
-
Object
- Object
- Bioinform::MotifModel::PM
- Defined in:
- lib/bioinform/data_models/pm.rb
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
readonly
Returns the value of attribute alphabet.
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #complemented ⇒ Object
- #each_position ⇒ Object
-
#initialize(matrix, options = {}) ⇒ PM
constructor
A new instance of PM.
- #length ⇒ Object
-
#named(name) ⇒ Object
def consensus ConsensusFormatter.by_maximal_elements.format_string(self) end.
- #reverse_complemented ⇒ Object (also: #revcomp)
- #reversed ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(matrix, options = {}) ⇒ PM
Returns a new instance of PM.
10 11 12 13 14 |
# File 'lib/bioinform/data_models/pm.rb', line 10 def initialize(matrix, = {}) @matrix = matrix @alphabet = .fetch(:alphabet, NucleotideAlphabet) raise ValidationError.new('invalid matrix', validation_errors: validation_errors) unless valid? end |
Instance Attribute Details
#alphabet ⇒ Object (readonly)
Returns the value of attribute alphabet.
9 10 11 |
# File 'lib/bioinform/data_models/pm.rb', line 9 def alphabet @alphabet end |
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
9 10 11 |
# File 'lib/bioinform/data_models/pm.rb', line 9 def matrix @matrix end |
Class Method Details
.from_file(filename, options = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/bioinform/data_models/pm.rb', line 23 def self.from_file(filename, = {}) parser = .fetch(:parser, MatrixParser.new) alphabet = .fetch(:alphabet, NucleotideAlphabet) info = parser.parse!(File.read(filename)) name = (info[:name] && !info[:name].strip.empty?) ? info[:name] : File.basename(filename, File.extname(filename)) self.new(info[:matrix], alphabet: alphabet).named( name ) end |
.from_string(input, options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/bioinform/data_models/pm.rb', line 16 def self.from_string(input, = {}) parser = .fetch(:parser, MatrixParser.new) alphabet = .fetch(:alphabet, NucleotideAlphabet) info = parser.parse!(input) self.new(info[:matrix], alphabet: alphabet).named( info[:name] ) end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/bioinform/data_models/pm.rb', line 58 def ==(other) self.class == other.class && matrix == other.matrix && alphabet == other.alphabet end |
#complemented ⇒ Object
74 75 76 |
# File 'lib/bioinform/data_models/pm.rb', line 74 def complemented self.class.new(complement_matrix, alphabet: alphabet) end |
#each_position ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/bioinform/data_models/pm.rb', line 62 def each_position if block_given? matrix.each{|pos| yield pos} else self.to_enum(:each_position) end end |
#length ⇒ Object
50 51 52 |
# File 'lib/bioinform/data_models/pm.rb', line 50 def length matrix.size end |
#named(name) ⇒ Object
95 96 97 |
# File 'lib/bioinform/data_models/pm.rb', line 95 def named(name) NamedModel.new(self, name) end |
#reverse_complemented ⇒ Object Also known as: revcomp
78 79 80 |
# File 'lib/bioinform/data_models/pm.rb', line 78 def reverse_complemented self.class.new(complement_matrix.reverse, alphabet: alphabet) end |
#reversed ⇒ Object
70 71 72 |
# File 'lib/bioinform/data_models/pm.rb', line 70 def reversed self.class.new(matrix.reverse, alphabet: alphabet) end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/bioinform/data_models/pm.rb', line 54 def to_s MotifFormatter.new.format(self) end |