File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change 1515from Bio .SeqRecord import SeqRecord , Seq
1616from typing import Sequence , Iterator
1717from pathlib import Path
18+ from micall .utils .stable_random_distribution import stable_random_distribution
1819
1920MAX_QUALITY = 40
2021
@@ -52,19 +53,16 @@ def simulate_reads(reference: Seq,
5253
5354 ref_len = len (reference )
5455 file_num = 2 if is_reversed else 1
56+ rng = stable_random_distribution (maximum = (ref_len - min_length ))
5557
5658 for i in range (n_reads ):
5759 # Choose a read length uniformly between min_length and max_length.
5860 read_length = random .randint (min_length , max_length )
59-
60- # Choose a random start index ensuring the read fits within
61- # the reference.
62- if ref_len - read_length <= 0 :
63- start = 0
64- else :
65- start = random .randrange (0 , ref_len - read_length + 1 )
66-
61+ # Choose a start index from a fair distribution.
62+ start = next (rng )
6763 end = start + read_length
64+
65+ # Get the read nucleotides.
6866 read_seq_seq = reference [start :end ]
6967 read_seq_str = str (read_seq_seq )
7068 read_seq = Seq (read_seq_str )
You can’t perform that action at this time.
0 commit comments