]> git.donarmstrong.com Git - biopieces.git/commitdiff
added patfind.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 1 Nov 2010 09:14:12 +0000 (09:14 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 1 Nov 2010 09:14:12 +0000 (09:14 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1149 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/patfind.rb [new file with mode: 0644]

diff --git a/code_ruby/Maasha/lib/patfind.rb b/code_ruby/Maasha/lib/patfind.rb
new file mode 100644 (file)
index 0000000..1696b62
--- /dev/null
@@ -0,0 +1,48 @@
+DEBUG = false
+
+module PatFind
+  @@pos = 0
+
+  def scan(pattern, max_mis = 0, max_ins = 0, max_del = 0)
+    if block_given?
+      while m = match(pattern, @@pos, max_mis, max_ins, max_del)
+        @@pos += m.pos + 1
+
+        yield m
+      end
+    else
+      matches = []
+
+      while m = match(pattern, @@pos, max_mis, max_ins, max_del)
+        matches << m
+
+        @@pos += m.pos + 1
+      end
+
+      return matches
+    end
+  end
+
+  def match(pattern, pos = 0, max_mis = 0, max_ins = 0, max_del = 0)
+    if pattern[0] == self.seq[pos]
+      puts self.seq[pos]
+    end
+
+    block_given? ? (yield m) : (return m)
+  end
+end
+
+# Class containing match information for use with PatFind.
+class Match
+  attr_accessor :pattern, :pos, :length, :mismatches, :insertions, :deletions
+
+  def initialize(pattern, pos, mismatches, insertions, deletions)
+    @pattern    = pattern
+    @pos        = pos
+    @length     = pattern.length
+    @mismatches = mismatches
+    @insertions = insertions
+    @deletions  = deletions
+  end
+end
+