====== Kraken2: Efficient Multi-Sample Classification ====== ===== Problem and solution ===== By default, ''kraken2'' loads its database into process-local RAM for every invocation, which requires substantial amount of time. Repeating this for many samples (*mhm* especially with the better db - Pracken (>400 GB)) the time to classify samples explodes, just because of repeated db-loading from scratch. Use **''--memory-mapping''** to access the database through file-backed memory mapping instead of copying the entire index into each process's RAM. The operating system can reuse cached database pages between samples((This does not keep a Kraken2 process or mapping alive between runs. Benefits depend on cache availability and disk speed. On slow or network storage, random disk I/O may make classification slower. )), reducing repeated loading overhead. e.g. kraken2 \ --db /mnt/nas1/db/kraken/pracken_20260708/ \ --paired \ --gzip-compressed \ --threads 8 \ --confidence 0.1 \ --use-names \ --memory-mapping \ --report sample_report.txt \ --output sample_output.txt \ sample_R1.fastq.gz sample_R2.fastq.gz Example Kraken2 Script: * [[https://wiki.abi.am/scripts:kraken2|ABI Wiki's Kraken2 page]] References: * [[https://github.com/DerrickWood/kraken2/wiki/Manual|Official Kraken2 manual]] — explains what ''--memory-mapping'' does. * [[https://github.com/DerrickWood/kraken2/issues/719|GitHub issue #719]] — discusses the ability to load db only once for multiple samples. * [[https://github.com/DerrickWood/kraken2/issues/451|GitHub issue #451]] — discusses memory mapping and I/O performance. * [[https://wiki.abi.am/pipelines:metagenomic_classification|ABI Wiki's own metagenomic classification pipeline]]