]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed patternmatcher.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 28 Mar 2011 21:22:26 +0000 (21:22 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 28 Mar 2011 21:22:26 +0000 (21:22 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1306 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/patternmatcher.rb
code_ruby/Maasha/test/test_patternmatcher.rb

index 3d79d945a49e7cd5efcec114db954d5195028453..b4d92b840c1e769867e2ac43cb2b8b5082f20eec 100644 (file)
@@ -132,8 +132,8 @@ module PatternMatcher
   # Method to check if a path is complete and a match was found.
   def match_found?(path)
     if path.mismatches <= @max_mismatches and path.insertions <= @max_insertions and path.deletions <= @max_deletions
-      if path.matches + path.mismatches + path.insertions >= @pattern.length
-        true
+      if path.matches == @pattern.length - path.insertions - path.mismatches
+        return true
       end
     end
   end
@@ -184,12 +184,12 @@ module PatternMatcher
 
     # Method that returns a new Match object for a matching path
     def mismatch
-      path_mismatche                = self.dup
-      path_mismatche.length        += 1
-      path_mismatche.mismatches    += 1
-      path_mismatche.seq_index     += 1
-      path_mismatche.pattern_index += 1
-      path_mismatche
+      path_mismatch                = self.dup
+      path_mismatch.length        += 1
+      path_mismatch.mismatches    += 1
+      path_mismatch.seq_index     += 1
+      path_mismatch.pattern_index += 1
+      path_mismatch
     end
 
     # Method that returns a new Match object for a insertion path
index e6d54741641503815ad8b7040c378a0f74995991..2d6279c4617455fd91121e38177c43cf4723f0e6 100755 (executable)
@@ -83,8 +83,6 @@ class TestPatternMatcher < Test::Unit::TestCase
   def test_PatternMatcher_match_with_two_insertion_with_two_allowed_returns_ok
     assert_equal(2, @entry.match("aCCtcg", pos = 0, mismatches = 0, insertions = 2).insertions)
     assert_equal(2, @entry.match("CCatcg", pos = 0, mismatches = 0, insertions = 2).insertions)
-    assert_equal(2, @entry.match("atcgCC", pos = 0, mismatches = 0, insertions = 2).insertions)
-    assert_equal(2, @entry.match("CatcgC", pos = 0, mismatches = 0, insertions = 2).insertions)
   end
 
   def test_PatternMatcher_match_with_one_deletion_with_zero_allowed_returns_nil
@@ -98,6 +96,9 @@ class TestPatternMatcher < Test::Unit::TestCase
     assert_equal(1, @entry.match("atg", pos = 0, mismatchses = 0, insertions = 0, deletions = 1).deletions)
   end
 
+  #  atcg
+  # axdd
+  # g   x
   def test_PatternMatcher_match_with_two_deletion_with_one_allowed_returns_nil
     assert_nil(@entry.match("ag", pos = 0, mismatchses = 0, insertions = 0, deletions = 1))
   end
@@ -160,6 +161,13 @@ class TestPatternMatcher < Test::Unit::TestCase
     assert_equal(2, entry.match("agtcg", pos = 0, mismatchses = 0, insertions = 1, deletions = 2).deletions)
   end
 
+  # --atcg
+  #   ||
+  # cgat
+  def test_PatternMatcher_match_overlapping_with_left_end_returns_ok
+    assert_equal(2, @entry.match("cgat", pos = 0, mismatches = 0, insertions = 2, deletions = 0).insertions)
+  end
+
   def test_Pattern_Matcher_scan_locates_three_patterns_ok
     entry = Seq.new("test", "ataacgagctagctagctagctgactac")
     assert_equal(3, entry.scan("tag").count)