From: martinahansen Date: Mon, 1 Nov 2010 09:14:12 +0000 (+0000) Subject: added patfind.rb X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e997df92c994702f532068554290102557fe6e87;p=biopieces.git added patfind.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1149 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/patfind.rb b/code_ruby/Maasha/lib/patfind.rb new file mode 100644 index 0000000..1696b62 --- /dev/null +++ b/code_ruby/Maasha/lib/patfind.rb @@ -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 +