From: martinahansen Date: Mon, 18 Apr 2011 12:20:10 +0000 (+0000) Subject: fixed bug in find_adaptor X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=12c28bb3fb9ff08b608029889c27c2e7da722538;p=biopieces.git fixed bug in find_adaptor git-svn-id: http://biopieces.googlecode.com/svn/trunk@1334 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/find_adaptor b/bp_bin/find_adaptor index 5c74eea..b37ca8b 100755 --- a/bp_bin/find_adaptor +++ b/bp_bin/find_adaptor @@ -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