From: martinahansen Date: Thu, 3 Feb 2011 15:56:38 +0000 (+0000) Subject: crude polish of shred_seq X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=7bad75ba44c304fb33a5768781357b415e8c6816;p=biopieces.git crude polish of shred_seq git-svn-id: http://biopieces.googlecode.com/svn/trunk@1251 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/shred_seq b/bp_bin/shred_seq index aaff5b7..6c1a8d0 100755 --- a/bp_bin/shred_seq +++ b/bp_bin/shred_seq @@ -50,18 +50,7 @@ class Seq strand = '+' while (sum / self.seq.length) < max_cov - if self.seq.size - size == 0 - start = 0 - else - start = rand(self.seq.size - size) - end - - stop = start + size - 1 - seq_name = self.seq_name + "[#{start + 1}-#{stop + 1}:#{strand}]" - seq = self.seq[start .. stop] - entry = Seq.new(seq_name, seq, 'dna') - - entry.revcomp if strand == '-' + entry = get_random_seq(size, strand) if block_given? yield entry @@ -76,6 +65,29 @@ class Seq entries end + + private + + # Method that picks a random subsequence of a given size from a sequence. + # The position of the subsequence is appended to the sequence name along + # with the strand. The sequence is reverse complemented in case of minus + # strand. + def get_random_seq(size, strand) + if self.seq.size - size == 0 + start = 0 + else + start = rand(self.seq.size - size) + end + + stop = start + size - 1 + seq_name = self.seq_name + "[#{start + 1}-#{stop + 1}:#{strand}]" + seq = self.seq[start .. stop] + entry = Seq.new(seq_name, seq, 'dna') + + entry.revcomp if strand == '-' + + entry + end end casts = []