Class: Bioinform::MotifModel::PCM

Inherits:
PM
  • Object
show all
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

Attributes inherited from PM

#alphabet, #matrix

Class Method Summary collapse

Instance Method Summary collapse

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

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

.default_validatorObject



33
34
35
# File 'lib/bioinform/data_models/pcm.rb', line 33

def self.default_validator
  PCM::VALIDATOR
end