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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 525f3aee90fc6e9de7a8de268cfcd7300836b5e7
4
- data.tar.gz: 561e1b71b51e6c45cbaf0e6da72bbe9341a9adbb
3
+ metadata.gz: 4e5a077fb1aa978f0c1b594a746fe4a5e025b21d
4
+ data.tar.gz: fec7feb9ca6547fb4026ed33fc538964a509941f
5
5
  SHA512:
6
- metadata.gz: b87838a2c2bf5460090d68ea23494aa2a714556b51f558ea17a9ad708612181f0a71ae96b56025a6e1ed5af96512ed25fce8a694f1cb3476876fad85c8d82f88
7
- data.tar.gz: 2579acb036d6b4fba976fc3705a1cbc129ef9fc68a30458b699d37ac2909f0607b8a6e65ecde3aab4217816dc556d44e56b342b0b3e54551ac545f4993f1b43c
6
+ metadata.gz: 153c29214d4c90573521eb4ba5733d0441962f014d38a05b24857cbc12d8509446878140900f2ad6df3348fd923146d13a3902bd9e11b3fe8230c0a2eca63492
7
+ data.tar.gz: 490fae39b38730a20b139e8a50fda22d64ed02cc0a62f0ea878ddf3dbde7d696b5875fbd4b75f70909566ded2a77abc6d5ddc47ec9933be78d644c4449bdb034
data/.gitignore CHANGED
@@ -9,7 +9,6 @@ Gemfile.lock
9
9
  InstalledFiles
10
10
  _yardoc
11
11
  coverage
12
- doc/
13
12
  lib/bundler/man
14
13
  pkg
15
14
  rdoc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ script: "bundle exec rake test"
4
+
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.2.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ### 1.0.1
2
+
3
+ * Added travis CI integration.
4
+ * Fixed UTF-8 encoding issues for Ruby 1.9.
5
+ * Added minitest Gem for Ruby 2.2.
6
+ * Updated documentation.
7
+ * Changed return value of inspect methods.
8
+
9
+ # 1.0.0
10
+
11
+ Initial release
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # NeedlemanWunschAligner
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.print_alignment
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.print_as_table(:score)
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.print_as_table(:traceback)
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,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  class NeedlemanWunschAligner
2
4
  class ExampleParagraphAndSentenceAligner < NeedlemanWunschAligner
3
5
 
@@ -1,3 +1,3 @@
1
1
  class NeedlemanWunschAligner
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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
- # Prints the optimal alignment.
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
- def print_alignment(col_width = 20)
51
+ # @return [String]
52
+ def inspect_alignment(col_width = 20)
49
53
  aligned_left_seq, aligned_top_seq = get_optimal_alignment
50
- puts
54
+ s = []
51
55
  aligned_left_seq.each_with_index do |ls_el, idx|
52
56
  rs_el = aligned_top_seq[idx]
53
- puts [
54
- ls_el.inspect[0..col_width].rjust(col_width),
55
- rs_el.inspect[0..col_width].ljust(col_width),
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
- # Prints either the score or the traceback matrix as table.
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
- def print_as_table(which_matrix, col_width = 3)
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
- puts
75
- puts 'left_seq = ' + @left_seq.join
76
- puts 'top_seq = ' + @top_seq.join
77
- puts
78
- print ' ' * 2 * col_width
79
-
80
- # Print header row
81
- @top_seq.each_index { |e| print(@top_seq[e].to_s.rjust(col_width)) }
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
- print ' '.rjust(col_width)
92
+ s << ' '.rjust(col_width)
88
93
  elsif 0 == col
89
94
  # first col in subsequent rows
90
- print @left_seq[row - 1].to_s.rjust(col_width)
95
+ s << @left_seq[row - 1].to_s.rjust(col_width)
91
96
  end
92
- print the_matrix[row][col].to_s.rjust(col_width)
93
- puts '' if col == the_matrix[row].length - 1
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
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.6"
21
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest"
22
23
  end
@@ -1,7 +1,6 @@
1
- require 'spec_helper'
2
- require 'needleman_wunsch_aligner'
3
- require 'needleman_wunsch_aligner/example_paragraph_and_sentence_aligner'
4
- require 'pp'
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative '../spec_helper'
5
4
 
6
5
  class NeedlemanWunschAligner
7
6
 
@@ -1,10 +1,10 @@
1
- # must raise exceptions on overridable methods
2
- require 'spec_helper'
3
- require 'needleman_wunsch_aligner'
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
@@ -1,6 +1,5 @@
1
- ENV["RAILS_ENV"] = "test"
1
+ # -*- coding: utf-8 -*-
2
+
2
3
  require 'bundler/setup'
3
4
  require 'minitest/autorun'
4
5
  require 'needleman_wunsch_aligner'
5
-
6
- #MiniTest::Unit.autorun
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.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