From 86c2f53b4bffdcc8d9b2f5d34160131cdc8292ac Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sat, 19 Mar 2011 21:07:42 +0000 Subject: [PATCH] worked on match code in Seq.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1303 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/seq.rb | 10 ++-------- code_ruby/Maasha/test/test_seq.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code_ruby/Maasha/lib/seq.rb b/code_ruby/Maasha/lib/seq.rb index 60f91bd..5dedb36 100644 --- a/code_ruby/Maasha/lib/seq.rb +++ b/code_ruby/Maasha/lib/seq.rb @@ -433,13 +433,11 @@ class Seq # ------------------------------------------------------------------------------ # Method to locate a pattern in a sequence and return the position of the match # or nil if no match was found. Hamming or Edit distance may be specified. - def match(pattern, pos = 0) + def match(pattern, pos = 0, hd = 0, ed = 0) while pos < self.length - pattern.length + 1 str1 = self.seq[pos ... pos + pattern.length] str2 = pattern - puts "pos: #{pos} str1: #{str1} str2: #{str2}" - rows = str1.length + 1 cols = str2.length + 1 @@ -455,8 +453,6 @@ class Seq for j in 1 ... cols do for i in 1 ... rows do - puts "pos: #{pos} i: #{i} j: #{j} str1: #{str1} str2: #{str2} str1[i-1]: #{str1[i-1]} str2[j-1]: #{str2[j-1]}" - if EQUAL[(str1[i - 1].upcase + str2[j - 1].upcase).to_sym] matrix[i, j] = matrix[i - 1, j - 1] matches += 1 @@ -478,10 +474,8 @@ class Seq end end end - pp matrix - puts "match: #{matches} mis: #{mismatches} del: #{deletions} ins: #{insertions}" - return pos if matrix[rows - 1, cols - 1] == 0 + return pos if matrix[rows - 1, cols - 1] <= hd pos += 1 end diff --git a/code_ruby/Maasha/test/test_seq.rb b/code_ruby/Maasha/test/test_seq.rb index d8317d3..f8ae29e 100755 --- a/code_ruby/Maasha/test/test_seq.rb +++ b/code_ruby/Maasha/test/test_seq.rb @@ -457,6 +457,14 @@ class TestSeq < Test::Unit::TestCase @entry.seq = "atcatc" assert_equal(3, @entry.match("aTc", 2)) end + + def test_Seq_match_with_hamming_dist_returns_correctly + @entry.seq = "atcg" + assert_equal(0, @entry.match("XTCG", pos=0, hd=1)) + assert_equal(0, @entry.match("TTCX", pos=0, hd=2)) + assert_equal(0, @entry.match("XXCX", pos=0, hd=3)) + assert_equal(0, @entry.match("XXXX", pos=0, hd=4)) + end end -- 2.39.5