Class: Bioinform::MotifModel::PCM
- Defined in:
- lib/bioinform/data_models/pcm.rb
Constant Summary collapse
- VALIDATOR =
PM::VALIDATOR * PCM.count_validator(eps: 1.0e-4).make_strict
- DIFFERENT_COUNTS_VALIDATOR =
PM::VALIDATOR * PCM.count_validator(eps: nil).make_strict
Constants inherited from PM
Bioinform::MotifModel::PM::DEFAULT_PARSER, Bioinform::MotifModel::PM::TRIVIAL_VALIDATOR
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Attributes inherited from PM
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(matrix, alphabet: NucleotideAlphabet, validator: default_validator) ⇒ PCM
constructor
A new instance of PCM.
Methods inherited from PM
#==, #complemented, #default_validator, #each_position, from_file, from_string, #length, #named, #reverse_complemented, #reversed, #rounded, #to_s
Constructor Details
#initialize(matrix, alphabet: NucleotideAlphabet, validator: default_validator) ⇒ PCM
Returns a new instance of PCM.
37 38 39 40 41 |
# File 'lib/bioinform/data_models/pcm.rb', line 37 def initialize(matrix, alphabet: NucleotideAlphabet, validator: default_validator) super # validator already checked count discrepancy. We store median count. @count = matrix.map{|pos| pos.inject(0.0, &:+) }.sort[matrix.length / 2] end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
42 43 44 |
# File 'lib/bioinform/data_models/pcm.rb', line 42 def count @count end |
Class Method Details
.count_validator(eps: 1.0e-4) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bioinform/data_models/pcm.rb', line 10 def self.count_validator(eps: 1.0e-4) Validator.new{|matrix, alphabet| errors = [] unless matrix.all?{|pos| pos.all?{|el| el >= 0 } } errors << "Elements of PCM should be non-negative." end warnings = [] if eps counts = matrix.map{|pos| pos.inject(0.0, &:+) } unless (counts.max - counts.min) <= eps * counts.min warnings << "PCM counts are different (discrepancy is greater than eps * MinCount; eps=#{eps}; MinCountn=#{counts.min})." end end ValidationResult.new(errors: errors, warnings: warnings) } end |