Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
First, thanks for this soft. I've been running a lot of badread runs for a project and while waiting for the soft to finish, I found it fun to check why it takes so long to simulate reads. I profile badread using cProfile using this command line:
python -m cProfile -s cumtime badread-runner.py simulate --reference test/kleb_MN.fasta --quantity 1x --error_model nanopore2020 --qscore_model nanopore2020 --identity 87.5,97.5,5 --glitches 1000,25,25 --junk_reads 1 --random_reads 1 --chimeras 1 --seed 50 > test/res
with
kleb_MN
being a Klebsiella pneumoniae strain I've on disk.Here is the head of the cprofile results with current version:
You can see that a lot of time is actually used to compute the qscores, mostly because of the millionof
random.choice
calls.I decided to give a try and replaced the random part using numpy generator. For numpy generator to be effective, we need to compute a lot of choices first and iterate over them later. One of the issue is that all cigar strings do not have the same frequency, and generating a lot of choices for all cigar string is ineffective.
The
CIGARQProbDist
object tries to circumvent this issue by generating choices based on an increasingly buffer size each time all choices have been consumed. I also use alru_cache
fromfunctools
to avoid reformatting of the same cigar strings over and over.New profiling with the same command line looks like this:
We have here a substantial speed increase (1.6x). Only drawback is the increased memory footprint but this should be ok in most cases.