From 10e0db1d8cc294afc9bcff4c56ca34770e0052cb Mon Sep 17 00:00:00 2001
From: martinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Date: Mon, 13 Jan 2014 10:38:40 +0000
Subject: [PATCH] refactor subseq to Seq#[]

git-svn-id: http://biopieces.googlecode.com/svn/trunk@2287 74ccb610-7750-0410-82ae-013aeee3265d
---
 bp_bin/clip_adaptor   |  4 ++--
 bp_bin/remove_primers | 18 +++++++++---------
 bp_bin/split_pair_seq |  4 ++--
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/bp_bin/clip_adaptor b/bp_bin/clip_adaptor
index 1e722b2..1bf6bf5 100755
--- a/bp_bin/clip_adaptor
+++ b/bp_bin/clip_adaptor
@@ -42,12 +42,12 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
       entry = Seq.new_bp(record)
 
       if record[:ADAPTOR_POS_RIGHT]
-        entry.subseq!(0, record[:ADAPTOR_POS_RIGHT].to_i)
+        entry = entry[0 ... record[:ADAPTOR_POS_RIGHT].to_i]
       end
 
       if record[:ADAPTOR_POS_LEFT]
         if record[:ADAPTOR_POS_LEFT].to_i + record[:ADAPTOR_LEN_LEFT].to_i < entry.length
-          entry.subseq!(record[:ADAPTOR_POS_LEFT].to_i + record[:ADAPTOR_LEN_LEFT].to_i)
+          entry = entry[record[:ADAPTOR_POS_LEFT].to_i + record[:ADAPTOR_LEN_LEFT].to_i .. -1]
         end
       end
 
diff --git a/bp_bin/remove_primers b/bp_bin/remove_primers
index 88c1a81..6544afc 100755
--- a/bp_bin/remove_primers
+++ b/bp_bin/remove_primers
@@ -50,22 +50,22 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
     if record[:SEQ]
       forward = false
       reverse = false
-      seq = Seq.new_bp(record)
+      entry = Seq.new_bp(record)
 
-      seq.patscan(options[:forward].to_s,
+      entry.patscan(options[:forward].to_s,
                   max_mismatches: options[:mismatches],
                   max_insertions: options[:insertions],
                   max_deletions:  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
+        len = entry.length - pos
+        entry = entry[pos ... pos + len] if len > 0
         forward = true
         break
       end
 
-      seq.patscan(options[:reverse].to_s,
+      entry.patscan(options[:reverse].to_s,
                   max_mismatches: options[:mismatches],
                   max_insertions: options[:insertions],
                   max_deletions:  options[:deletions]) do |match|
@@ -75,10 +75,10 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
         len = match.pos
 
         if len == 0
-          seq.seq  = ""
-          seq.qual = "" if seq.qual
+          entry.seq  = ""
+          entry.qual = "" if entry.qual
         else
-          seq.subseq!(pos, len)
+          entry = entry[pos ... pos + len]
         end 
 
         reverse = true
@@ -86,7 +86,7 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
       end
 
       if forward or reverse
-        record.merge!(seq.to_bp)
+        record.merge!(entry.to_bp)
       end
 
       output.puts record
diff --git a/bp_bin/split_pair_seq b/bp_bin/split_pair_seq
index b0425ac..cd0aea6 100755
--- a/bp_bin/split_pair_seq
+++ b/bp_bin/split_pair_seq
@@ -46,8 +46,8 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
         raise "SEQ_LEN_LEFT + SEQ_LEN_RIGHT != SEQ_LEN #{len_left} + #{len_right} != #{entry.length}"
       end
 
-      entry1 = entry.subseq(0, len_left)
-      entry2 = entry.subseq(len_left)
+      entry1 = entry[0 ... len_left]
+      entry2 = entry[len_left .. -1]
 
       if entry.seq_name =~ /^[^ ]+ \d:/
         entry2.seq_name.sub!(/ \d:/, " 2:")
-- 
2.39.5