Sha256: 481bdb4a096934918bb38c83267fb618dbf37487850ae83e10c9f8dea7430486

Contents?: true

Size: 795 Bytes

Versions: 4

Compression:

Stored size: 795 Bytes

Contents

module Bioinform
  module ConversionAlgorithms
    module PCM2PWMConverter
      def self.convert(pcm, parameters = {})
        default_parameters = {pseudocount: Math.log(pcm.count),
                              probability: (pcm.probability || [0.25, 0.25, 0.25, 0.25])
                              }
        parameters = default_parameters.merge(parameters)
        probability = parameters[:probability]
        pseudocount = parameters[:pseudocount]
        matrix = pcm.each_position.map do |pos|
          pos.each_index.map do |index|
            Math.log((pos[index] + probability[index] * pseudocount) / (probability[index]*(pcm.count + pseudocount)) )
          end
        end
        PWM.new(pcm.get_parameters.merge(matrix: matrix))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bioinform-0.1.12 lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb
bioinform-0.1.11 lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb
bioinform-0.1.10 lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb
bioinform-0.1.9 lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb