Skip to content

Commit

Permalink
fix rounding error (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrienG committed Jan 29, 2021
1 parent 226ee39 commit 3a3ce93
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions iss/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def generate_reads(args):
f = open(genome_file, 'r') # re-opens the file
with f:
fasta_file = SeqIO.parse(f, 'fasta')

total_reads_generated = 0
total_reads_generated_unrouned = 0
for record in fasta_file:
# generate reads for records
try:
Expand All @@ -252,9 +253,22 @@ def generate_reads(args):
err_mod.read_length,
genome_size
)
n_pairs = int(round(
(coverage *
len(record.seq)) / err_mod.read_length) / 2)
n_pairs_unrounded = (
(coverage * len(record.seq)) /
err_mod.read_length) / 2
n_pairs = round(n_pairs_unrounded)

# check that the rounding does not cause to drop
# read pairs
total_reads_generated_unrouned += n_pairs_unrounded
total_reads_generated += n_pairs
if round(total_reads_generated_unrouned) > \
total_reads_generated:
logger.debug(
"Adding a pair to correct rounding error")
n_pairs += 1
total_reads_generated += 1

# skip record if n_reads == 0
if n_pairs == 0:
continue
Expand Down

0 comments on commit 3a3ce93

Please sign in to comment.