Module: Bioinform::Background

Included in:
Frequencies, WordwiseBackground
Defined in:
lib/bioinform/background.rb,
lib/bioinform/background.rb

Overview

it also tags Frequencies and WordwiseBackground classes so that .is_a?(Bioinform::Background) is true for them

Constant Summary collapse

Uniform =
Bioinform::Frequencies.new([0.25, 0.25, 0.25, 0.25])
Wordwise =
Bioinform::WordwiseBackground.new

Class Method Summary collapse

Class Method Details

.from_frequencies(frequencies) ⇒ Object



14
15
16
# File 'lib/bioinform/background.rb', line 14

def self.from_frequencies(frequencies)
  Frequencies.new(frequencies)
end

.from_gc_content(gc_content) ⇒ Object

Raises:



18
19
20
21
22
23
# File 'lib/bioinform/background.rb', line 18

def self.from_gc_content(gc_content)
  raise Error, 'GC-content should be withing range [0;1]'  unless (0..1).include?(gc_content)
  p_at = (1.0 - gc_content) / 2.0
  p_cg = gc_content / 2.0
  Frequencies.new([p_at, p_cg, p_cg, p_at])
end

.from_string(str) ⇒ Object



25
26
27
28
29
30
# File 'lib/bioinform/background.rb', line 25

def self.from_string(str)
  return wordwise  if str.downcase == 'wordwise'
  return uniform  if str.downcase == 'uniform'
  arr = str.strip.split(',').map(&:to_f)
  arr == [1,1,1,1] ? wordwise : Bioinform::Frequencies.new(arr)
end

.uniformObject



10
11
12
# File 'lib/bioinform/background.rb', line 10

def self.uniform
  Bioinform::Background::Uniform
end

.wordwiseObject



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

def self.wordwise
  Bioinform::Background::Wordwise
end