]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed bug in find_adaptor
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 18 Apr 2011 12:20:10 +0000 (12:20 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 18 Apr 2011 12:20:10 +0000 (12:20 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1334 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/find_adaptor

index 5c74eeac453d9b9a749298cf9be74b6836c8e1fc..b37ca8beb5a13a90ff49db75c70721090c290519 100755 (executable)
@@ -32,6 +32,8 @@
 require 'biopieces'
 require 'seq'
 
+VERBOSE = true
+
 def disambiguate(adaptor)
   adaptor_disamb = adaptor.dup
   adaptor_disamb.gsub!('U', 'T')
@@ -57,15 +59,17 @@ class Seq
     raise SeqError, "Edit distance percent out of range #{ed_percent}" unless (0 .. 100).include? ed_percent
 
     if pos < 0
-      pos = self.length - pos # pos offset from the right end
+      pos = self.length + pos # pos offset from the right end
     end
 
-    if match = adaptor_find_simple(adaptor_disamb, pos)
-      return match
-    elsif match = adaptor_find_complex(adaptor, pos, ed_percent)
-      return match
-    elsif match = adaptor_partial_find_complex(adaptor, ed_percent)
-      return match
+    if pos < self.length
+      if match = adaptor_find_simple(adaptor_disamb, pos)
+        return match
+      elsif match = adaptor_find_complex(adaptor, pos, ed_percent)
+        return match
+      elsif match = adaptor_partial_find_complex(adaptor, pos, ed_percent)
+        return match
+      end
     end
   end
 
@@ -91,12 +95,20 @@ class Seq
 
   # Method to find part of an adaptor at the right end of a sequence taking
   # into account ambiguity codes, mismatches, insertions, and deletions.
-  def adaptor_partial_find_complex(adaptor, ed_percent)
-    adaptor = adaptor[0 ... -1]
+  def adaptor_partial_find_complex(adaptor, pos, ed_percent)
+    if pos > self.length - adaptor.length
+      adaptor = adaptor[0 ... self.length - pos]
+    else
+      adaptor = adaptor[0 ... adaptor.length - 1]
 
-    pos = self.len - adaptor.length
+      pos = self.length - adaptor.length
+    end
+
+    #puts self.seq if VERBOSE
 
     while adaptor.length > 0
+      #puts (" " * pos) + adaptor if VERBOSE
+
       ed_max = (adaptor.length * ed_percent * 0.01).round
 
       if ed_max == 0
@@ -111,7 +123,7 @@ class Seq
 
       adaptor = adaptor[0 ... -1]
 
-      pos = self.len - adaptor.length
+      pos += 1
     end
   end
 end