needleman_wunsch_aligner 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/needleman_wunsch_aligner.rb +12 -2
- data/lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb +6 -4
- data/lib/needleman_wunsch_aligner/version.rb +1 -1
- data/spec/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner_spec.rb +1 -1
- data/spec/needleman_wunsch_aligner_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400aaa5f217e86854b380018d7cf7c60e5ac6c46
|
4
|
+
data.tar.gz: ef24f13b5c47b6ec838cdf1ee9d62586d70ebe1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b23ad08d6b95c3307a69098e6c37688edf1082839c7a6f0fc4d2775dad5f0a4505891a2061f1b10203e1e28d6832d259f54b43b9bbff2718b934e322f1d4444a
|
7
|
+
data.tar.gz: 07b5be3582e3b1431c28fdddf41aa86d10eb6e9bd87b815a161df502ac9d1a76f7f0221c54bb9b1cd06474c39cdb9d03d3699de865d10055db0aea9f9accec51
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 1.1.0
|
2
|
+
|
3
|
+
* Changed #compute_score method params: Added row and column index for performance optimizations where I may not want to compute scores for the entire matrix, but only for a narrow band around the diagonal. The width of the band is determined by the maximum expected alignment offset.
|
4
|
+
|
1
5
|
### 1.0.4
|
2
6
|
|
3
7
|
* Added overridable methods for `#inspect_alignment`
|
@@ -28,10 +28,14 @@ class NeedlemanWunschAligner
|
|
28
28
|
|
29
29
|
# This is a basic implementation of the scoring algorithm. See
|
30
30
|
# ExampleParagraphAndSentenceAligner for a more complex scoring function.
|
31
|
+
# NOTE: You can use row_index and col_index to improve performance if you know
|
32
|
+
# the maximum offset between left_el and top_el.
|
31
33
|
# @param left_el [Object]
|
32
34
|
# @param top_el [Object]
|
35
|
+
# @param row_index [Integer] zero based row index, origin is at top.
|
36
|
+
# @param col_index [Integer] zero based column index, origin is to the left.
|
33
37
|
# @return [Numeric]
|
34
|
-
def compute_score(left_el, top_el)
|
38
|
+
def compute_score(left_el, top_el, row_index, col_index)
|
35
39
|
left_el == top_el ? 1 : -3
|
36
40
|
end
|
37
41
|
|
@@ -155,7 +159,13 @@ protected
|
|
155
159
|
from_top = @score_matrix[row-1][col] + default_gap_penalty
|
156
160
|
from_left = @score_matrix[row][col-1] + default_gap_penalty
|
157
161
|
# @left_seq and @top_seq are off by 1 because we added cells for gaps in the matrix
|
158
|
-
|
162
|
+
score = compute_score(
|
163
|
+
@left_seq[row-1],
|
164
|
+
@top_seq[col-1],
|
165
|
+
row-1,
|
166
|
+
col-1
|
167
|
+
)
|
168
|
+
from_top_left = @score_matrix[row-1][col-1] + score
|
159
169
|
|
160
170
|
# find max score and direction
|
161
171
|
max, direction = [from_top_left, '⬉']
|
@@ -14,10 +14,12 @@ class NeedlemanWunschAligner
|
|
14
14
|
# s/b 10 -10
|
15
15
|
# s/nil 10
|
16
16
|
#
|
17
|
-
# param left_el [Hash]
|
18
|
-
# param top_el [Hash]
|
19
|
-
#
|
20
|
-
|
17
|
+
# @param left_el [Hash]
|
18
|
+
# @param top_el [Hash]
|
19
|
+
# @param row_index [Integer] zero based row index, origin is at top.
|
20
|
+
# @param col_index [Integer] zero based column index, origin is to the left.
|
21
|
+
# @return [Integer]
|
22
|
+
def compute_score(left_el, top_el, row_index, col_index)
|
21
23
|
score = 0
|
22
24
|
if left_el[:type] == top_el[:type]
|
23
25
|
# Match on type (paragraph vs. sentence)
|
@@ -143,7 +143,7 @@ class NeedlemanWunschAligner
|
|
143
143
|
].each do |(left_el, right_el, xpect)|
|
144
144
|
|
145
145
|
it "handles #{ left_el.inspect }:#{ right_el.inspect }" do
|
146
|
-
aligner.send(:compute_score, left_el, right_el).must_equal(xpect)
|
146
|
+
aligner.send(:compute_score, left_el, right_el, 0, 0).must_equal(xpect)
|
147
147
|
end
|
148
148
|
|
149
149
|
end
|
@@ -76,7 +76,7 @@ describe NeedlemanWunschAligner do
|
|
76
76
|
].each do |(left_el, right_el, xpect)|
|
77
77
|
|
78
78
|
it "handles #{ left_el.inspect }:#{ right_el.inspect }" do
|
79
|
-
aligner.send(:compute_score, left_el, right_el).must_equal(xpect)
|
79
|
+
aligner.send(:compute_score, left_el, right_el, 0, 0).must_equal(xpect)
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: needleman_wunsch_aligner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|