Class: Bioinform::ConversionAlgorithms::PPM2PCMConverter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PPM2PCMConverter

Returns a new instance of PPM2PCMConverter.



9
10
11
# File 'lib/bioinform/conversion_algorithms/ppm2pcm_converter.rb', line 9

def initialize(options = {})
  @count = options.fetch(:count, 100)
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



7
8
9
# File 'lib/bioinform/conversion_algorithms/ppm2pcm_converter.rb', line 7

def count
  @count
end

Instance Method Details

#convert(ppm) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bioinform/conversion_algorithms/ppm2pcm_converter.rb', line 13

def convert(ppm)
  raise Error, "#{self.class}#convert accepts only models acting as PPM"  unless MotifModel.acts_as_ppm?(ppm)
  matrix = ppm.each_position.map do |pos|
    pos.map do |el|
      el * @count
    end
  end

  pcm = MotifModel::PCM.new(matrix)
  if ppm.respond_to? :name
    pcm.named(ppm.name)
  else
    pcm
  end
end