]> git.donarmstrong.com Git - biopieces.git/commitdiff
crude polish of shred_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 3 Feb 2011 15:56:38 +0000 (15:56 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 3 Feb 2011 15:56:38 +0000 (15:56 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1251 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/shred_seq

index aaff5b79dbcc52b56c57c8cd123f7f0e36fa25e9..6c1a8d0623adfefa5c288178297b73c2b79f7622 100755 (executable)
@@ -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 = []