]> git.donarmstrong.com Git - biopieces.git/commitdiff
added patmatch method to backtrack.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 4 Dec 2012 12:51:49 +0000 (12:51 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 4 Dec 2012 12:51:49 +0000 (12:51 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2027 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq/backtrack.rb

index 532bf641278947941c45a380f1369786f16ea960..948d68bc495c36d2af491b890ea103a75c6a49e4 100644 (file)
@@ -40,6 +40,24 @@ module BackTrack
   MAX_INS    = 5 # Maximum number of insertions allowed
   MAX_DEL    = 5 # Maximum number of deletions allowed
 
+  def patmatch(pattern, offset = 0, max_mismatches = 0, max_insertions = 0, max_deletions = 0)
+    self.patscan(pattern, offset, max_mismatches, max_insertions, max_deletions) do |m|
+      if block_given?
+        yield m
+      else
+        return m
+      end
+
+      break
+    end
+
+    if block_given?
+      yield nil
+    else
+      return nil
+    end
+  end
+
   # ------------------------------------------------------------------------------
   #   str.scan(pattern[, max_mismatches[, max_insertions[, max_deletions]]])
   #   -> Array
@@ -65,12 +83,12 @@ module BackTrack
     matches = []
 
     if block_given?
-      while result = track_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
+      while result = scan_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
         yield Match.new(result.first, result.last, self.seq[result.first ... result.first + result.last])
         offset = result.first + 1
       end
     else
-      while result = track_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
+      while result = scan_C(self.seq, self.length, pattern, offset, max_mismatches, max_insertions, max_deletions)
         matches << Match.new(result.first, result.last, self.seq[result.first ... result.first + result.last])
         offset = result.first + 1
       end
@@ -113,7 +131,8 @@ module BackTrack
 
     # Backtrack algorithm for matching a pattern (p) starting in a sequence (s) allowing for mis
     # mismatches, ins insertions and del deletions. ss is the start of the sequence, used only for
-    # reporting the match endpoints.
+    # reporting the match endpoints. State is used to avoid ins followed by del and visa versa which
+    # are nonsense.
     builder.prefix %{
       unsigned int backtrack(
         char         *ss,     // Sequence start
@@ -145,7 +164,7 @@ module BackTrack
     # Find pattern (p) in a sequence (s) starting at pos, with at most mis mismatches, ins
     # insertions and del deletions.
     builder.c %{
-      VALUE track_C(
+      VALUE scan_C(
         VALUE _s,     // Sequence
         VALUE _len,   // Sequence length
         VALUE _p,     // Pattern