Class: Macroape::PWMCompare

Inherits:
Object
  • Object
show all
Includes:
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.



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

def initialize(first, second)
  @first = first
  @second = second
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



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

def first
  @first
end

#secondObject (readonly)

Returns the value of attribute second.



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

def second
  @second
end

Instance Method Details

#each_alignmentObject Also known as: each



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

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

#jaccard(threshold_first, threshold_second) ⇒ Object



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

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



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

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

#max_hash_size(*args) ⇒ Object



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

def max_hash_size(*args)
  case args.size
  when 0 then @max_hash_size
  when 1 then max_hash_size!(args.first)
  else raise ArgumentError, '#max_hash_size method can get 0 or 1 argument'
  end
end

#max_hash_size!(new_max_hash_size) ⇒ Object

sets or gets limit of summary size of calculation hash. It’s a defence against overuse CPU resources by non-appropriate data



4
5
6
7
# File 'lib/macroape/pwm_compare.rb', line 4

def max_hash_size!(new_max_hash_size)
  @max_hash_size = new_max_hash_size
  self
end