Class: Bioinform::MotifModel::PWM

Inherits:
PM
  • Object
show all
Defined in:
lib/bioinform/data_models/pwm.rb

Constant Summary collapse

VALIDATOR =
PM::VALIDATOR

Constants inherited from PM

Bioinform::MotifModel::PM::DEFAULT_PARSER, Bioinform::MotifModel::PM::TRIVIAL_VALIDATOR

Instance Attribute Summary

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, #initialize, #length, #named, #reverse_complemented, #reversed, #rounded, #to_s

Constructor Details

This class inherits a constructor from Bioinform::MotifModel::PM

Class Method Details

.default_validatorObject



12
13
14
# File 'lib/bioinform/data_models/pwm.rb', line 12

def self.default_validator
  PWM::VALIDATOR
end

Instance Method Details

#discreted(rate, rounding_method: :ceil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/bioinform/data_models/pwm.rb', line 23

def discreted(rate, rounding_method: :ceil)
  discreted_matrix = matrix.map{|position|
    position.map{|element|
      (element * rate).send(rounding_method)
    }
  }
  self.class.new(discreted_matrix, alphabet: alphabet, validator: TRIVIAL_VALIDATOR)
end

#left_augmented(n) ⇒ Object

Raises:



37
38
39
40
41
# File 'lib/bioinform/data_models/pwm.rb', line 37

def left_augmented(n)
  raise Error, 'Augmenting with negative number of columns is impossible'  if n < 0
  augmented_matrix = Array.new(n, zero_column) + matrix
  self.class.new(augmented_matrix, alphabet: alphabet)
end

#right_augmented(n) ⇒ Object

Raises:



43
44
45
46
47
# File 'lib/bioinform/data_models/pwm.rb', line 43

def right_augmented(n)
  raise Error, 'Augmenting with negative number of columns is impossible'  if n < 0
  augmented_matrix = matrix + Array.new(n, zero_column)
  self.class.new(augmented_matrix, alphabet: alphabet)
end

#score(word) ⇒ Object

Raises:



16
17
18
19
20
21
# File 'lib/bioinform/data_models/pwm.rb', line 16

def score(word)
  raise Error, 'Word length should be the same as PWM length'  unless word.length == length
  length.times.map do |pos|
    matrix[pos][alphabet.index_by_letter(word[pos])]
  end.inject(0.0, &:+)
end