Class: Bioinform::ConversionAlgorithms::MaraPCM2PWMConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/bioinform/conversion_algorithms/pcm2pwm_mara_converter.rb

Overview

s_alpha,j = ln(fracx_{alpha,j + cappa p_alpha}(N+cappa)p_{alpha})

Instance Method Summary collapse

Instance Method Details

#convert(pcm) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bioinform/conversion_algorithms/pcm2pwm_mara_converter.rb', line 9

def convert(pcm)
  raise Error, "#{self.class}#convert accepts only models acting as PCM"  unless MotifModel.acts_as_pcm?(pcm)
  matrix = pcm.each_position.map do |pos|
    count = pos.inject(0.0, &:+)
    pos.each_index.map do |index|
      Math.log((pos[index] + 0.5).to_f / (0.25 * (count + 2)) )
    end
  end
  pwm = MotifModel::PWM.new(matrix)
  if pcm.respond_to? :name
    pwm.named(pcm.name)
  else
    pwm
  end
end