Class: Bioinform::MotifModel::PPM
- Defined in:
- lib/bioinform/data_models/ppm.rb
Constant Summary collapse
- VALIDATOR =
PM::VALIDATOR * PPM.probability_validator(eps: 1.0e-4).make_strict
Constants inherited from PM
Bioinform::MotifModel::PM::DEFAULT_PARSER, Bioinform::MotifModel::PM::TRIVIAL_VALIDATOR
Instance Attribute Summary
Attributes inherited from PM
Class Method Summary collapse
Methods inherited from PM
#==, #complemented, #default_validator, #each_position, from_file, from_string, #initialize, #length, #named, #reverse_complemented, #reversed, #rounded, #to_s
Constructor Details
This class inherits a constructor from Bioinform::MotifModel::PM
Class Method Details
.default_validator ⇒ Object
10 11 12 |
# File 'lib/bioinform/data_models/ppm.rb', line 10 def self.default_validator PPM::VALIDATOR end |
.probability_validator(eps: 1.0e-4) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bioinform/data_models/ppm.rb', line 14 def self.probability_validator(eps: 1.0e-4) Validator.new{|matrix, alphabet| errors = [] unless matrix.all?{|pos| pos.all?{|el| el >= 0 } } errors << "Elements of PPM should be non-negative." end warnings = [] probability_sums = matrix.map{|pos| pos.inject(0.0, &:+) } max_discrepancy = probability_sums.map{|sum| (sum - 1.0).abs }.max unless max_discrepancy <= eps warnings << "PPM should sum up to 1, with discrepancy not greater than #{eps}." end ValidationResult.new(errors: errors, warnings: warnings) } end |