From: martinahansen Date: Mon, 28 Mar 2011 21:22:26 +0000 (+0000) Subject: fixed patternmatcher.rb X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=70b80305d0b9b615ae121e16caca37c6c5fb4a32;p=biopieces.git fixed patternmatcher.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1306 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/patternmatcher.rb b/code_ruby/Maasha/lib/patternmatcher.rb index 3d79d94..b4d92b8 100644 --- a/code_ruby/Maasha/lib/patternmatcher.rb +++ b/code_ruby/Maasha/lib/patternmatcher.rb @@ -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 diff --git a/code_ruby/Maasha/test/test_patternmatcher.rb b/code_ruby/Maasha/test/test_patternmatcher.rb index e6d5474..2d6279c 100755 --- a/code_ruby/Maasha/test/test_patternmatcher.rb +++ b/code_ruby/Maasha/test/test_patternmatcher.rb @@ -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)