]> git.donarmstrong.com Git - biopieces.git/commitdiff
added ambiguity to hamming_distance
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Sep 2013 10:17:27 +0000 (10:17 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Sep 2013 10:17:27 +0000 (10:17 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2198 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq.rb
code_ruby/test/maasha/test_seq.rb

index e4b6bfd7c27d5933d0bd9c6b65210bd9a7b32ea0..73bf0552938cef82fa937aa43ff7be23b190c94b 100644 (file)
@@ -31,6 +31,7 @@ autoload :BackTrack,   'maasha/seq/backtrack'
 autoload :Dynamic,     'maasha/seq/dynamic'
 autoload :Homopolymer, 'maasha/seq/homopolymer'
 autoload :Levenshtein, 'maasha/seq/levenshtein'
+autoload :Ambiguity,   'maasha/seq/ambiguity'
 
 # Residue alphabets
 DNA     = %w[a t c g]
@@ -384,8 +385,12 @@ class Seq
 
   # Method to determine the Hamming Distance between
   # two Sequence objects (case insensitive).
-  def hamming_distance(entry)
-    self.seq.upcase.hamming_distance(entry.seq.upcase)
+  def hamming_distance(entry, options = nil)
+    if options and options[:ambiguity]
+      Ambiguity.hamming_distance(self.seq, entry.seq)
+    else
+      self.seq.upcase.hamming_distance(entry.seq.upcase)
+    end
   end
 
   # Method to determine the Edit Distance between
index 5947ee874666102cf6ef61f3ab8f8ff90516a2ef..bbb6759277359c0254275cc92101bd00c113abe6 100755 (executable)
@@ -304,6 +304,14 @@ class TestSeq < Test::Unit::TestCase
     assert_equal(1, seq1.hamming_distance(seq2))
   end
 
+  test "#hamming_distance with ambiguity codes return correctly" do
+    seq1 = Seq.new("test1", "ATCG")
+    seq2 = Seq.new("test2", "atng")
+
+    assert_equal(1, seq1.hamming_distance(seq2))
+    assert_equal(0, seq1.hamming_distance(seq2, ambiguity: true))
+  end
+
   test "#edit_distance returns correctly" do
     seq1 = Seq.new("test1", "ATCG")
     seq2 = Seq.new("test2", "tgncg")