]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/remove_primers
rewriting uclust_seq
[biopieces.git] / bp_bin / remove_primers
index 9c8457ccb527bd50281e2a202dc47ae1003959f6..720d943ee6db515b49980342afb96a8717a0fa22 100755 (executable)
@@ -45,30 +45,35 @@ options = Biopieces.options_parse(ARGV, casts)
 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
   input.each do |record|
     if record.has_key? :SEQ
+      forward = false
+      reverse = false
       seq = Seq.new_bp(record)
-      pos = 0
-      len = 0
 
-      if forward = seq.patscan(options[:forward].to_s, pos, options[:mismatches], options[:insertions], options[:deletions])
-        record[:FORWARD_POS] = forward.last.pos
-        record[:FORWARD_LEN] = forward.last.length
-        pos = forward.last.pos + forward.last.length
+      seq.patscan(options[:forward].to_s, 0, options[:mismatches], options[:insertions], options[:deletions]) do |match|
+        record[:FORWARD_POS] = match.pos
+        record[:FORWARD_LEN] = match.length
+        pos = match.pos + match.length
         len = seq.length - pos
         seq.subseq!(pos, len) if len > 0
+        forward = true
+        break
       end
 
-      if pos < seq.length && reverse = seq.patscan(options[:reverse].to_s, pos, options[:mismatches], options[:insertions], options[:deletions])
-        record[:REVERSE_POS] = reverse.first.pos
-        record[:REVERSE_LEN] = reverse.first.length
+      seq.patscan(options[:reverse].to_s, 0, options[:mismatches], options[:insertions], options[:deletions]) do |match|
+        record[:REVERSE_POS] = match.pos
+        record[:REVERSE_LEN] = match.length
         pos = 0
-        len = reverse.first.pos
+        len = match.pos
 
         if len == 0
           seq.seq  = ""
           seq.qual = "" if seq.qual
         else
           seq.subseq!(pos, len)
-        end
+        end 
+
+        reverse = true
+        break
       end
 
       if forward or reverse