Class: Macroape::PWMCompare

Inherits:
Object
  • Object
show all
Includes:
Bioinform::Parameters, Enumerable
Defined in:
lib/macroape/pwm_compare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, second) ⇒ PWMCompare

Returns a new instance of PWMCompare.



10
11
12
13
14
# File 'lib/macroape/pwm_compare.rb', line 10

def initialize(first, second)
  @parameters = OpenStruct.new
  @first = first
  @second = second
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



9
10
11
# File 'lib/macroape/pwm_compare.rb', line 9

def first
  @first
end

#parametersObject (readonly)

Returns the value of attribute parameters.



9
10
11
# File 'lib/macroape/pwm_compare.rb', line 9

def parameters
  @parameters
end

#secondObject (readonly)

Returns the value of attribute second.



9
10
11
# File 'lib/macroape/pwm_compare.rb', line 9

def second
  @second
end

Instance Method Details

#each_alignmentObject Also known as: each



34
35
36
37
38
# File 'lib/macroape/pwm_compare.rb', line 34

def each_alignment
  (-second.length..first.length).to_a.product([:direct,:revcomp]) do |shift, orientation|
    yield PWMCompareAligned.new(first, second, shift, orientation).set_parameters(max_pair_hash_size: max_pair_hash_size)
  end
end

#jaccard(threshold_first, threshold_second) ⇒ Object



16
17
18
19
20
# File 'lib/macroape/pwm_compare.rb', line 16

def jaccard(threshold_first, threshold_second)
  self.map_each_alignment do |alignment|
    alignment.alignment_infos.merge( alignment.jaccard(threshold_first, threshold_second) )
  end.max_by {|alignment_infos| alignment_infos[:similarity] }
end

#jaccard_by_pvalue(pvalue) ⇒ Object



22
23
24
25
26
# File 'lib/macroape/pwm_compare.rb', line 22

def jaccard_by_pvalue(pvalue)
  threshold_first = first.threshold(pvalue)
  threshold_second = second.threshold(pvalue)
  jaccard(threshold_first, threshold_second)
end

#jaccard_by_weak_pvalue(pvalue) ⇒ Object



28
29
30
31
32
# File 'lib/macroape/pwm_compare.rb', line 28

def jaccard_by_weak_pvalue(pvalue)
  threshold_first = first.weak_threshold(pvalue)
  threshold_second = second.weak_threshold(pvalue)
  jaccard(threshold_first, threshold_second)
end