Class: Bioinform::Frequencies

Inherits:
Object
  • Object
show all
Includes:
Background, FrequencyCalculations
Defined in:
lib/bioinform/background.rb

Constant Summary

Constants included from Background

Background::Uniform, Background::Wordwise

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Background

from_frequencies, from_gc_content, from_string, uniform, wordwise

Methods included from FrequencyCalculations

#mean, #mean_square, #symmetric?

Constructor Details

#initialize(frequencies) ⇒ Frequencies

Returns a new instance of Frequencies.

Raises:



51
52
53
54
55
56
# File 'lib/bioinform/background.rb', line 51

def initialize(frequencies)
  @frequencies = frequencies
  raise Error, 'Frequencies should have 4 components' unless frequencies.length == 4
  raise Error, 'Frequencies should be in [0;1]' unless frequencies.all?{|el| (0..1).include?(el) }
  raise Error, 'Sum of Background frequencies should be equal to 1' unless (frequencies.inject(0.0, &:+) - 1.0).abs < 1e-4
end

Instance Attribute Details

#frequenciesObject (readonly)

Returns the value of attribute frequencies.



58
59
60
# File 'lib/bioinform/background.rb', line 58

def frequencies
  @frequencies
end

Instance Method Details

#==(other) ⇒ Object



64
65
66
# File 'lib/bioinform/background.rb', line 64

def ==(other)
  self.class == other.class && frequencies == other.frequencies
end

#countsObject



59
# File 'lib/bioinform/background.rb', line 59

def counts; frequencies; end

#to_sObject



68
69
70
# File 'lib/bioinform/background.rb', line 68

def to_s
  counts.join(',')
end

#volumeObject



60
# File 'lib/bioinform/background.rb', line 60

def volume; 1; end

#wordwise?Boolean

Returns:

  • (Boolean)


61
# File 'lib/bioinform/background.rb', line 61

def wordwise?; false; end