Sha256: fe7ae40a449874d7d20e060c673cb36e65667831dc1c1ee37a1a8581f99eac22

Contents?: true

Size: 758 Bytes

Versions: 3

Compression:

Stored size: 758 Bytes

Contents

require_relative 'pm'

module Bioinform
  module MotifModel
    def self.acts_as_pcm?(pcm)
      pcm.is_a?(MotifModel::PCM) || pcm.is_a?(MotifModel::NamedModel) && acts_as_pcm?(pcm.model)
    end

    class PCM < PM
      def validation_errors
        errors = super
        errors << "elements of PCM should be non-negative"  unless matrix.all?{|pos| pos.all?{|el| el >= 0 } }
        errors
      end

      def count
        counts = each_position.map{|pos| pos.inject(0.0, &:+)}
        count = counts.first
        diffs = counts.map{|pos_count| (pos_count - count).abs }
        counts_are_same = (diffs.max < count * 1e-3)
        raise Error, 'Different columns have different count'  unless counts_are_same
        count
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bioinform-0.2.2 lib/bioinform/data_models/pcm.rb
bioinform-0.2.1 lib/bioinform/data_models/pcm.rb
bioinform-0.2.0 lib/bioinform/data_models/pcm.rb