needleman_wunsch_aligner 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/CHANGELOG.md +11 -0
- data/README.md +20 -4
- data/doc/meta.md +19 -0
- data/lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb +2 -0
- data/lib/needleman_wunsch_aligner/version.rb +1 -1
- data/lib/needleman_wunsch_aligner.rb +29 -21
- data/needleman_wunsch_aligner.gemspec +1 -0
- data/spec/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner_spec.rb +3 -4
- data/spec/needleman_wunsch_aligner_spec.rb +26 -4
- data/spec/spec_helper.rb +2 -3
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5a077fb1aa978f0c1b594a746fe4a5e025b21d
|
4
|
+
data.tar.gz: fec7feb9ca6547fb4026ed33fc538964a509941f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 153c29214d4c90573521eb4ba5733d0441962f014d38a05b24857cbc12d8509446878140900f2ad6df3348fd923146d13a3902bd9e11b3fe8230c0a2eca63492
|
7
|
+
data.tar.gz: 490fae39b38730a20b139e8a50fda22d64ed02cc0a62f0ea878ddf3dbde7d696b5875fbd4b75f70909566ded2a77abc6d5ddc47ec9933be78d644c4449bdb034
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Needleman Wunsch Aligner
|
2
2
|
|
3
3
|
This gem finds the optimal alignment of two sequences of any kind of Ruby Objects. You can implement sophisticated scoring functions, using any of the Objects’ attributes.
|
4
4
|
|
@@ -50,7 +50,7 @@ Instantiate a new aligner with the two sequences and compute the optimal alignme
|
|
50
50
|
|
51
51
|
Inspect the alignment:
|
52
52
|
|
53
|
-
aligner.
|
53
|
+
puts aligner.inspect_alignment
|
54
54
|
|
55
55
|
# => 1 | nil
|
56
56
|
2 | 2
|
@@ -59,7 +59,7 @@ Inspect the alignment:
|
|
59
59
|
|
60
60
|
Inspect the score table:
|
61
61
|
|
62
|
-
aligner.
|
62
|
+
puts aligner.inspect_matrix(:score)
|
63
63
|
# => 2 3 4
|
64
64
|
0 -1 -2 -3
|
65
65
|
1 -1 -2 -3 -4
|
@@ -68,7 +68,7 @@ Inspect the score table:
|
|
68
68
|
|
69
69
|
Inspect the traceback table:
|
70
70
|
|
71
|
-
aligner.
|
71
|
+
puts aligner.inspect_matrix(:traceback)
|
72
72
|
# => 2 3 4
|
73
73
|
x ← ← ←
|
74
74
|
1 ↑ ↑ ↑ ↑
|
@@ -94,3 +94,19 @@ example.
|
|
94
94
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
95
|
4. Push to the branch (`git push origin my-new-feature`)
|
96
96
|
5. Create a new Pull Request
|
97
|
+
|
98
|
+
### Resources
|
99
|
+
|
100
|
+
* [Source code (github)](https://github.com/jhund/needleman_wunsch_aligner)
|
101
|
+
* [Issues](https://github.com/jhund/needleman_wunsch_aligner/issues)
|
102
|
+
* [Rubygems.org](http://rubygems.org/gems/needleman_wunsch_aligner)
|
103
|
+
|
104
|
+
[![Build Status](https://travis-ci.org/jhund/needleman_wunsch_aligner.svg?branch=master)](https://travis-ci.org/jhund/needleman_wunsch_aligner)
|
105
|
+
|
106
|
+
### License
|
107
|
+
|
108
|
+
[MIT licensed](https://github.com/jhund/needleman_wunsch_aligner/blob/master/LICENSE.txt).
|
109
|
+
|
110
|
+
### Copyright
|
111
|
+
|
112
|
+
Copyright (c) 2015 Jo Hund. See [(MIT) LICENSE](https://github.com/jhund/needleman_wunsch_aligner/blob/master/LICENSE.txt) for details.
|
data/doc/meta.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Gem meta info
|
2
|
+
|
3
|
+
## Release a new version
|
4
|
+
|
5
|
+
* Make and commit code changes.
|
6
|
+
* Update `CHANGELOG.md`.
|
7
|
+
* Update the gem version in `lib/needleman_wunsch_aligner/version.rb`.
|
8
|
+
* Commit version bump and changelog.
|
9
|
+
* Run `rake release`. This will perform the following steps:
|
10
|
+
* Build a gem package to e.g. pkg/needleman_wunsch_aligner-1.0.1.gem.
|
11
|
+
* Push the `.gem` package to `Rubygems.org`
|
12
|
+
* Add and push a tag like “v1.0.1” to git.
|
13
|
+
* Push commits to the git remote.
|
14
|
+
|
15
|
+
## Run tests
|
16
|
+
|
17
|
+
rake test
|
18
|
+
|
19
|
+
Also every push to github will trigger a test run at travis CI.
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "needleman_wunsch_aligner/example_paragraph_and_sentence_aligner"
|
1
4
|
require "needleman_wunsch_aligner/version"
|
2
5
|
|
3
6
|
# Finds the optimal alignment of two sequences using the Needleman-Wunsch algorithm.
|
@@ -43,24 +46,27 @@ class NeedlemanWunschAligner
|
|
43
46
|
nil
|
44
47
|
end
|
45
48
|
|
46
|
-
#
|
49
|
+
# Returns a string representation of the optimal alignment in two columns.
|
47
50
|
# @param col_width [Integer, optional] max width of each col in chars
|
48
|
-
|
51
|
+
# @return [String]
|
52
|
+
def inspect_alignment(col_width = 20)
|
49
53
|
aligned_left_seq, aligned_top_seq = get_optimal_alignment
|
50
|
-
|
54
|
+
s = []
|
51
55
|
aligned_left_seq.each_with_index do |ls_el, idx|
|
52
56
|
rs_el = aligned_top_seq[idx]
|
53
|
-
|
54
|
-
ls_el.inspect[0
|
55
|
-
rs_el.inspect[0
|
57
|
+
s << [
|
58
|
+
ls_el.inspect[0...col_width].rjust(col_width),
|
59
|
+
rs_el.inspect[0...col_width].ljust(col_width),
|
56
60
|
].join(' | ')
|
57
61
|
end
|
62
|
+
s.join("\n")
|
58
63
|
end
|
59
64
|
|
60
|
-
#
|
65
|
+
# Returns string representation of either the score or the traceback matrix.
|
61
66
|
# @param which_matrix [Symbol] one of :traceback or :score
|
62
67
|
# @param col_width [Integer, optional], defaults to 3
|
63
|
-
|
68
|
+
# @return [String]
|
69
|
+
def inspect_matrix(which_matrix, col_width = 3)
|
64
70
|
get_optimal_alignment if @score_matrix.nil?
|
65
71
|
the_matrix = case which_matrix
|
66
72
|
when :traceback
|
@@ -71,27 +77,29 @@ class NeedlemanWunschAligner
|
|
71
77
|
raise "Handle this: #{ which_matrix.inspect }"
|
72
78
|
end
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
s = ''
|
81
|
+
s << 'left_seq = ' + @left_seq.join + "\n"
|
82
|
+
s << 'top_seq = ' + @top_seq.join + "\n"
|
83
|
+
s << "\n"
|
84
|
+
# Header row
|
85
|
+
s << ' ' * 2 * col_width
|
86
|
+
@top_seq.each_index { |e| s << @top_seq[e].to_s.rjust(col_width) }
|
87
|
+
s << "\n"
|
82
88
|
|
83
|
-
puts ''
|
84
89
|
traverse_score_matrix do |row, col|
|
85
90
|
if 0 == col and 0 == row
|
86
91
|
# first column in first row
|
87
|
-
|
92
|
+
s << ' '.rjust(col_width)
|
88
93
|
elsif 0 == col
|
89
94
|
# first col in subsequent rows
|
90
|
-
|
95
|
+
s << @left_seq[row - 1].to_s.rjust(col_width)
|
91
96
|
end
|
92
|
-
|
93
|
-
|
97
|
+
# subsequent cells
|
98
|
+
s << the_matrix[row][col].to_s.rjust(col_width)
|
99
|
+
# finalize row
|
100
|
+
s << "\n" if col == the_matrix[row].length - 1
|
94
101
|
end
|
102
|
+
s
|
95
103
|
end
|
96
104
|
|
97
105
|
protected
|
@@ -1,10 +1,10 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative './spec_helper'
|
4
4
|
|
5
5
|
describe NeedlemanWunschAligner do
|
6
6
|
|
7
|
-
let(:aligner){ NeedlemanWunschAligner.new([], []) }
|
7
|
+
let(:aligner){ NeedlemanWunschAligner.new([1,2,3], [2,3,4]) }
|
8
8
|
|
9
9
|
describe "#get_optimal_alignment" do
|
10
10
|
|
@@ -90,4 +90,26 @@ describe NeedlemanWunschAligner do
|
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
+
describe "#inspect_alignment" do
|
94
|
+
|
95
|
+
it 'prints the alignment' do
|
96
|
+
aligner.inspect_alignment.must_equal([
|
97
|
+
' 1 | nil ',
|
98
|
+
' 2 | 2 ',
|
99
|
+
' 3 | 3 ',
|
100
|
+
' nil | 4 ',
|
101
|
+
].join("\n"))
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'adjusts the column width' do
|
105
|
+
aligner.inspect_alignment(4).must_equal([
|
106
|
+
' 1 | nil ',
|
107
|
+
' 2 | 2 ',
|
108
|
+
' 3 | 3 ',
|
109
|
+
' nil | 4 ',
|
110
|
+
].join("\n"))
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
93
115
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- jhund@clearcove.ca
|
@@ -46,10 +60,13 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- CHANGELOG.md
|
49
65
|
- Gemfile
|
50
66
|
- LICENSE.txt
|
51
67
|
- README.md
|
52
68
|
- Rakefile
|
69
|
+
- doc/meta.md
|
53
70
|
- lib/needleman_wunsch_aligner.rb
|
54
71
|
- lib/needleman_wunsch_aligner/example_paragraph_and_sentence_aligner.rb
|
55
72
|
- lib/needleman_wunsch_aligner/version.rb
|