needleman_wunsch_aligner 1.0.3 → 1.0.4
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/README.md +14 -19
- data/lib/needleman_wunsch_aligner.rb +26 -3
- data/lib/needleman_wunsch_aligner/version.rb +1 -1
- data/spec/needleman_wunsch_aligner_spec.rb +47 -0
- 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: 87606c963077521d74f35b81133e0075ef992e2b
|
4
|
+
data.tar.gz: 6bf09bfc25f9592fb41b1749ae2026c89fdf11c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2cae7d6b77826a43d3e0fb1b08cb01d41a7e13244e6ec57b391b4da55e5152cdebf2215109d38046265d4524c936a85d2ee8afb41139a5652beb488d2d84528
|
7
|
+
data.tar.gz: f5f5cacb4e4d6d5d5762b4be0cc9957b1883bac379bdb66a680742a7942d1ca639cbe122215325a3f3bbb3c9c59aa5422e90bca700545412ee64051e1bfc506a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,18 +12,8 @@ Given two sequences
|
|
12
12
|
The algorithm will find the optimal alignment based on a scoring function you specify:
|
13
13
|
|
14
14
|
GCATG-CU
|
15
|
-
=+==!-=!
|
16
15
|
G-ATTACA
|
17
16
|
|
18
|
-
Meaning of the symbols:
|
19
|
-
|
20
|
-
= Match
|
21
|
-
! Mismatch
|
22
|
-
+ Insert
|
23
|
-
- Deletion
|
24
|
-
|
25
|
-
Insert and Deletion are usually grouped together as `IndDel`.
|
26
|
-
|
27
17
|
## Installation
|
28
18
|
|
29
19
|
Add this line to your application's Gemfile:
|
@@ -52,10 +42,10 @@ Inspect the alignment:
|
|
52
42
|
|
53
43
|
puts aligner.inspect_alignment
|
54
44
|
|
55
|
-
# => 1
|
56
|
-
2
|
57
|
-
3
|
58
|
-
nil
|
45
|
+
# => 1 - nil
|
46
|
+
2 = 2
|
47
|
+
3 = 3
|
48
|
+
nil + 4
|
59
49
|
|
60
50
|
Inspect the score table:
|
61
51
|
|
@@ -69,11 +59,11 @@ Inspect the score table:
|
|
69
59
|
Inspect the traceback table:
|
70
60
|
|
71
61
|
puts aligner.inspect_matrix(:traceback)
|
72
|
-
# =>
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
# => 2 3 4
|
63
|
+
x ← ← ←
|
64
|
+
1 ↑ ↑ ↑ ↑
|
65
|
+
2 ↑ ⬉ ← ←
|
66
|
+
3 ↑ ↑ ⬉ ←
|
77
67
|
|
78
68
|
## Customization
|
79
69
|
|
@@ -87,6 +77,11 @@ sophisticated ones by subclassing the `NeedlemanWunschAligner` class and overrid
|
|
87
77
|
Please see `NeedlemanWunschAligner::ExampleParagraphAndSentenceAligner` for an
|
88
78
|
example.
|
89
79
|
|
80
|
+
You can also override these methods which are related to `#inspect_alignment`:
|
81
|
+
|
82
|
+
* `element_for_inspection_display`
|
83
|
+
* `elements_are_equal_for_inspection`
|
84
|
+
|
90
85
|
## Contributing
|
91
86
|
|
92
87
|
1. Fork it ( https://github.com/jhund/needleman_wunsch_aligner/fork )
|
@@ -56,7 +56,7 @@ class NeedlemanWunschAligner
|
|
56
56
|
s = []
|
57
57
|
aligned_left_seq.each_with_index do |left_el, idx|
|
58
58
|
top_el = aligned_top_seq[idx]
|
59
|
-
delimiter = if top_el
|
59
|
+
delimiter = if elements_are_equal_for_inspection(top_el, left_el)
|
60
60
|
'=' # match
|
61
61
|
elsif gap_indicator == top_el
|
62
62
|
'-' # delete
|
@@ -66,8 +66,8 @@ class NeedlemanWunschAligner
|
|
66
66
|
'!' # mismatch
|
67
67
|
end
|
68
68
|
s << [
|
69
|
-
left_el
|
70
|
-
top_el
|
69
|
+
element_for_inspection_display(left_el, col_width).rjust(col_width),
|
70
|
+
element_for_inspection_display(top_el, col_width).ljust(col_width),
|
71
71
|
].join(" #{ delimiter } ")
|
72
72
|
end
|
73
73
|
s.join("\n")
|
@@ -113,6 +113,29 @@ class NeedlemanWunschAligner
|
|
113
113
|
s
|
114
114
|
end
|
115
115
|
|
116
|
+
# Transforms element to an object that can be used for display when inspecting
|
117
|
+
# an alignment
|
118
|
+
# @params element [Object]
|
119
|
+
# @return [Object]
|
120
|
+
def element_for_inspection_display(element, col_width = nil)
|
121
|
+
r = case element
|
122
|
+
when String
|
123
|
+
element
|
124
|
+
else
|
125
|
+
element.inspect
|
126
|
+
end
|
127
|
+
col_width ? r[0...col_width] : r
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns true if top_el and left_el are considered equal for inspection
|
131
|
+
# purposes
|
132
|
+
# @params top_el [Object]
|
133
|
+
# @params left_el [Object]
|
134
|
+
# @return [Boolean]
|
135
|
+
def elements_are_equal_for_inspection(top_el, left_el)
|
136
|
+
top_el == left_el
|
137
|
+
end
|
138
|
+
|
116
139
|
protected
|
117
140
|
|
118
141
|
def construct_score_matrix_and_traceback_matrix
|
@@ -80,6 +80,7 @@ describe NeedlemanWunschAligner do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
end
|
83
|
+
|
83
84
|
end
|
84
85
|
|
85
86
|
describe "#default_gap_penalty" do
|
@@ -118,6 +119,52 @@ describe NeedlemanWunschAligner do
|
|
118
119
|
].join("\n"))
|
119
120
|
end
|
120
121
|
|
122
|
+
it 'uses #element_for_inspection_display' do
|
123
|
+
def aligner.element_for_inspection_display(element, col_width)
|
124
|
+
'override'
|
125
|
+
end
|
126
|
+
|
127
|
+
aligner.inspect_alignment(8).must_equal([
|
128
|
+
'override - override',
|
129
|
+
'override = override',
|
130
|
+
'override = override',
|
131
|
+
'override + override',
|
132
|
+
].join("\n"))
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'uses #elements_are_equal_for_inspection' do
|
136
|
+
def aligner.elements_are_equal_for_inspection(top_el, left_el)
|
137
|
+
false
|
138
|
+
end
|
139
|
+
|
140
|
+
aligner.inspect_alignment(4).must_equal([
|
141
|
+
' 1 - nil ',
|
142
|
+
' 2 ! 2 ',
|
143
|
+
' 3 ! 3 ',
|
144
|
+
' nil + 4 ',
|
145
|
+
].join("\n"))
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#element_for_inspection_display" do
|
151
|
+
|
152
|
+
it 'returns the expected value' do
|
153
|
+
aligner.element_for_inspection_display('hello', 3).must_equal('hel')
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#elements_are_equal_for_inspection" do
|
159
|
+
|
160
|
+
it 'returns true if equal' do
|
161
|
+
aligner.elements_are_equal_for_inspection('hello', 'hello').must_equal(true)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'returns false if not equal' do
|
165
|
+
aligner.elements_are_equal_for_inspection('hello', 'heller').must_equal(false)
|
166
|
+
end
|
167
|
+
|
121
168
|
end
|
122
169
|
|
123
170
|
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.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|