Class: Align::PairwiseAlgorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/align/pairwise_algorithm.rb

Overview

Provides a base for algorithms that align two sequences.

Direct Known Subclasses

NeedlemanWunsch, SmithWaterman

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seq1, seq2, scoring) ⇒ PairwiseAlgorithm

Returns a new instance of PairwiseAlgorithm.



6
7
8
9
10
# File 'lib/align/pairwise_algorithm.rb', line 6

def initialize(seq1, seq2, scoring)
  @seq1 = seq1
  @seq2 = seq2
  @scoring = scoring
end

Instance Attribute Details

#scoringObject (readonly)

Returns the value of attribute scoring.



4
5
6
# File 'lib/align/pairwise_algorithm.rb', line 4

def scoring
  @scoring
end

#seq1Object (readonly)

Returns the value of attribute seq1.



4
5
6
# File 'lib/align/pairwise_algorithm.rb', line 4

def seq1
  @seq1
end

#seq2Object (readonly)

Returns the value of attribute seq2.



4
5
6
# File 'lib/align/pairwise_algorithm.rb', line 4

def seq2
  @seq2
end

Instance Method Details

#alignObject

Returns the sequences in aligned arrays. Gaps are filled with :skip_obj

Returns:

  • Two arrays containing the sequences, and their elements.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/align/pairwise_algorithm.rb', line 34

def align
  raise NotImplementedError.new("#{self.class}#align")
end

#max2(a, b) ⇒ Object

Max of 2



13
14
15
# File 'lib/align/pairwise_algorithm.rb', line 13

def max2(a,b)
  a >= b ? a : b
end

#max3(a, b, c) ⇒ Object

Determines the maximum value of three variables. 3-4 times faster than [a,b,c].max.



19
20
21
# File 'lib/align/pairwise_algorithm.rb', line 19

def max3(a,b,c)
  (a >= b) ? ((a >= c)? a : c) : ((b >= c)? b : c)
end

#max4(a, b, c, d) ⇒ Object

Returns the max of 4 integers



24
25
26
27
28
# File 'lib/align/pairwise_algorithm.rb', line 24

def max4(a,b,c,d)
  x = a >= b ? a : b
  y = c >= d ? c : d
  (x >= y) ? x : y
end