sum = 0
strand = '+'
- while (sum / self.seq.length) < max_cov
- entry = get_random_seq(size, strand)
+ while coverage(sum) < max_cov
+ entry = self.subseq_rand(size)
+ entry.revcomp if strand == '-'
if block_given?
yield entry
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
+ # Method that returns the coverage of subsequences.
+ def coverage(sum)
+ sum / self.seq.length
end
end
bp.each_record do |record|
if record.has_key? :SEQ and record[:SEQ].length >= options[:size]
- entry = Seq.new(record[:SEQ_NAME], record[:SEQ], record[:SCORES])
+ entry = Seq.new(record[:SEQ_NAME], record[:SEQ], record[:SCORES])
+ entry.type = 'dna'
entry.shred(options[:size], options[:coverage]) do |subentry|
bp.puts subentry.to_bp