X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Flib%2Fmaasha%2Fseq%2Ftrim.rb;h=2ca94542b65c3ed3e6d536b460095295b1f13181;hb=3656f15bb59e2eb7eff628bae117db6479b2f03f;hp=e7e9bb1daf6b019e77e78b8eabf44cad1abc2ea5;hpb=351549b36ba20cf06daf9cf0e14273d84ae1f83e;p=biopieces.git diff --git a/code_ruby/lib/maasha/seq/trim.rb b/code_ruby/lib/maasha/seq/trim.rb index e7e9bb1..2ca9454 100644 --- a/code_ruby/lib/maasha/seq/trim.rb +++ b/code_ruby/lib/maasha/seq/trim.rb @@ -23,6 +23,9 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'inline' +require 'maasha/seq/backtrack' + +include BackTrack # Error class for all exceptions to do with Trim. class TrimError < StandardError; end @@ -37,7 +40,7 @@ module Trim pos = trim_right_pos_c(self.qual, self.length, min_qual, min_len, Seq::SCORE_BASE) - self.subseq(0, pos) + self[0, pos] end # Method to progressively trim a Seq object sequence from the right end until @@ -47,7 +50,10 @@ module Trim pos = trim_right_pos_c(self.qual, self.length, min_qual, min_len, Seq::SCORE_BASE) - self.subseq!(0, pos) + self.seq = self.seq[0, pos] + self.qual = self.qual[0, pos] if self.qual + + self end # Method to progressively trim a Seq object sequence from the left end until @@ -57,7 +63,7 @@ module Trim pos = trim_left_pos_c(self.qual, self.length, min_qual, min_len, Seq::SCORE_BASE) - self.subseq(pos) + self[pos .. -1] end # Method to progressively trim a Seq object sequence from the left end until @@ -67,7 +73,10 @@ module Trim pos = trim_left_pos_c(self.qual, self.length, min_qual, min_len, Seq::SCORE_BASE) - self.subseq!(pos) + self.seq = self.seq[pos .. -1] + self.qual = self.qual[pos .. -1] if self.qual + + self end # Method to progressively trim a Seq object sequence from both ends until a @@ -80,7 +89,7 @@ module Trim pos_left = pos_right if pos_left > pos_right - self.subseq(pos_left, pos_right - pos_left) + self[pos_left ... pos_right] end # Method to progressively trim a Seq object sequence from both ends until a @@ -93,7 +102,42 @@ module Trim pos_left = pos_right if pos_left > pos_right - self.subseq!(pos_left, pos_right - pos_left) + self.seq = self.seq[pos_left ... pos_right] + self.qual = self.qual[pos_left ... pos_right] if self.qual + + self + end + + # Method to locate a pattern in a sequence and trim all sequence to the left + # including the pattern. + def patmatch_trim_left!(pattern, options = {}) + match = self.patmatch(pattern, options) + + if match + stop = self.length + + self.seq = self.seq[match.pos + match.length .. stop] + self.qual = self.qual[match.pos + match.length .. stop] if self.qual + + return self + end + + nil + end + + # Method to locate a pattern in a sequence and trim all sequence to the right + # including the pattern. + def patmatch_trim_right!(pattern, options = {}) + match = self.patmatch(pattern, options) + + if match + self.seq = self.seq[0 ... match.pos] + self.qual = self.qual[0 ... match.pos] if self.qual + + return self + end + + nil end private