Class: Bioinform::MotifModel::DiPM

Inherits:
Object
  • Object
show all
Defined in:
lib/sequence_logo/di_pm.rb

Overview

Doesn’t work with alphabet

Direct Known Subclasses

DiPCM, DiPWM

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix) ⇒ DiPM

Returns a new instance of DiPM.

Raises:

  • (ValidationError)


17
18
19
20
# File 'lib/sequence_logo/di_pm.rb', line 17

def initialize(matrix)
  @matrix = matrix
  raise ValidationError.new('invalid matrix', validation_errors: validation_errors)  unless valid?
end

Instance Attribute Details

#matrixObject (readonly)

Returns the value of attribute matrix.



16
17
18
# File 'lib/sequence_logo/di_pm.rb', line 16

def matrix
  @matrix
end

Class Method Details

.from_file(filename) ⇒ Object



9
10
11
12
13
14
# File 'lib/sequence_logo/di_pm.rb', line 9

def self.from_file(filename)
  parser = Bioinform::MatrixParser.new(fix_nucleotides_number: 16)
  infos = parser.parse(File.read(filename))
  name = infos[:name] || File.basename(filename, File.extname(filename))
  pcm = self.new(infos[:matrix]).named(name)
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/sequence_logo/di_pm.rb', line 53

def ==(other)
  self.class == other.class && matrix == other.matrix # alphabet should be considered (when alphabet implemented)
end

#each_positionObject



57
58
59
60
61
62
63
# File 'lib/sequence_logo/di_pm.rb', line 57

def each_position
  if block_given?
    matrix.each{|pos| yield pos}
  else
    self.to_enum(:each_position)
  end
end

#lengthObject



49
50
51
# File 'lib/sequence_logo/di_pm.rb', line 49

def length
  matrix.size + 1
end

#named(name) ⇒ Object



45
46
47
# File 'lib/sequence_logo/di_pm.rb', line 45

def named(name)
  NamedModel.new(self, name)
end

#to_sObject



41
42
43
# File 'lib/sequence_logo/di_pm.rb', line 41

def to_s
  MotifFormatter.new.format(self)
end