Closed Adoni5 closed 12 months ago
When reading through a file like this (no seeking and few fields), you can 1) use bgzf::MultithreadedReader
for parallel block decoding and 2) read lazy BAM records to avoid decoding all the fields in a record.
Here's a full example for noodles.
$ cargo new issue_219
$ cd issue_219
$ cargo add noodles --features bam,bgzf,sam
$ cargo add noodles-bgzf --features libdeflate
main.rs
Thanks @zaeleus for the quick and detailed reply - will give this a try tomorrow and report back!
Can confirm that this is twice as fast as the implementation that I wrote in rust_htslib
🥇 . Whilst there may be some under the hood compiler optimisations on the filter
and reference_seq_name
functions (which I haven't done in my htslib
based code), and setting the number of threads to a smarter number than just the number of available cores, I'm very happy I don't have to mess around cross-compiling the htslib
C bindings anymore!
Thanks very much @zaeleus!
Using available_parallelism
in the rust_htslib
version, makes a big difference with it now being ~2 seconds slower than noodles
over a 2.8 million row BAM file! That is a good trick to know. There probably some optimisations I could make to the htslib
code, but still very happy with this, Thanks again!
----------------------------------------------- benchmark: 1 tests -----------------------------------------------
Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
------------------------------------------------------------------------------------------------------------------
test_iterate_bam_file 44.8837 46.5181 45.7009 1.1557 45.7009 1.6344 0;0 0.0219 2 2
------------------------------------------------------------------------------------------------------------------
----------------------------------------------- benchmark: 1 tests -----------------------------------------------
Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
------------------------------------------------------------------------------------------------------------------
test_iterate_bam_file 47.3635 47.4921 47.4278 0.0909 47.4278 0.1286 0;0 0.0211 2 2
------------------------------------------------------------------------------------------------------------------
Hi @zaeleus ,
Thank you very much for this solid set of crates! I have a question, specifically about the fastest way to iterate BAM records. I've written code in
rust_htslib
This runs approximately 6 times faster than the equivalent
noodles_bam
implementation. I suspect this due to therust_htslib
thread pool, and was wondering how I can efficiently reimplement this intonoodles
? This is what I have so far -Many Thanks, Rory