Skip to content

Commit b0ea7a9

Browse files
committed
Revert "Revert "Use stable distribution in fasta_to_fastq""
This reverts commit 1154fb9.
1 parent 9ccbdf9 commit b0ea7a9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

micall/utils/fasta_to_fastq.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from Bio.SeqRecord import SeqRecord, Seq
1616
from typing import Sequence, Iterator
1717
from pathlib import Path
18+
from micall.utils.stable_random_distribution import stable_random_distribution
1819

1920
MAX_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)

0 commit comments

Comments
 (0)