]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/backtrack.rb
fixed minor issue in align.rb tests
[biopieces.git] / code_ruby / lib / maasha / backtrack.rb
index c47f97ebbf84562b38af7bd15125eac36c811ad7..896fe091100d506cecd5b2f7c0cab1f08ba93b2e 100644 (file)
@@ -35,7 +35,7 @@ class BackTrackError < StandardError; end
 # Algorithm based on code kindly provided by j_random_hacker @ Stackoverflow:
 # http://stackoverflow.com/questions/7557017/approximate-string-matching-using-backtracking/
 module BackTrack
-  OK_PATTERN = Regexp.new('^[flsycwphqrimtnkvadegu]+$')
+  OK_PATTERN = Regexp.new('^[bflsycwphqrimtnkvadegu]+$')
   MAX_MIS    = 5 # Maximum number of mismatches allowed
   MAX_INS    = 5 # Maximum number of insertions allowed
   MAX_DEL    = 5 # Maximum number of deletions allowed
@@ -56,7 +56,7 @@ module BackTrack
   # pattern. Matches found in block context return the Match object. Otherwise
   # matches are returned in an Array of Match objects.
   def patscan(pattern, offset = 0, max_mismatches = 0, max_insertions = 0, max_deletions = 0)
-    raise BackTrackError, "Bad pattern: #{pattern}" unless pattern.downcase =~ OK_PATTERN
+    raise BackTrackError, "Bad pattern: #{pattern}"                                          unless pattern.downcase =~ OK_PATTERN
     raise BackTrackError, "offset: #{offset} out of range (0 ... #{self.length - 1})"        unless (0 ... self.length).include? offset
     raise BackTrackError, "max_mismatches: #{max_mismatches} out of range (0 .. #{MAX_MIS})" unless (0 .. MAX_MIS).include? max_mismatches
     raise BackTrackError, "max_insertions: #{max_insertions} out of range (0 .. #{MAX_INS})" unless (0 .. MAX_INS).include? max_insertions
@@ -153,9 +153,7 @@ module BackTrack
 
               while (*s)
               {
-                  e = backtrack(ss, s, p, mm, ins, del);
-
-                  if (e)
+                  if (e = backtrack(ss, s, p, mm, ins, del))
                   {
                       tuple = rb_ary_new();
                       rb_ary_push(tuple, INT2FIX((int) (s - ss)));