bioRxivPreprintOpen accessbioinformatics

To sort or to hash? Revisiting k-mer counting

V. Levallois, R. Patro, P. Peterlongo, G. E. Pibiri

Key points

From the paper's conclusion
  • We then design a k-mer counting algorithm in the light of this analysis.

Abstract

Motivation: Counting k-mers in large genomic datasets is a foundational primitive in bioinformatics, supporting applications such as genome assembly, variant discovery, metagenomic profiling, and sequence database indexing. As sequencing throughput grows, k-mer counting is routinely applied to collections of hundreds to thousands of files. Even a modest per-file speedup compounds into hours of saved computation across such collections. Methods: Sorting and hashing are the two main ways of counting k-mers, and practice has largely settled on the former, of which KMC3 (Kokot et al., 2017) is the most refined expression. We reconsider this choice and analyze both approaches using a cost model that charges computation and memory transfers together. We show that the outcome of the comparison rests on two matters: how abundant the k-mers are, and whether the hash tables fit in cache. Sorting is faster only when data is mostly unique and the hash tables do not fit in cache. We then design a k-mer counting algorithm in the light of this analysis. We adopt the consolidated paradigm based on first partitioning the k-mers by their minimizer, thus obtaining partitions of super-k-mers, and then counting each partition independently in parallel. In particular, super-k-mers are deduplicated before counting, and the number of partitions is chosen so that the hash tables fit in cache whenever possible. The algorithm avoids writing temporary data to disk if enough internal memory is available. Results: We implemented this strategy in a tool named Tuna and show that it is faster than KMC3 on all but one of our inputs, spanning bacterial and human assemblies, metagenomes and read sets, by up to 4.3x. The advantage of Tuna compared to KMC3 in the counting step alone widens to 6.8x as k-mer abundance grows, as the analysis predicts. On the largest input tested, 614 GB of human sequencing reads, Tuna counts within 4 GB of memory and 0.7 TB of temporary disk. On that input the two tools finish within 1.1x of each other under the full 256 GB budget, and restricting every tool to the same 8 GB budget widens the advantage of Tuna over KMC3 to 1.8x. Software: The software is freely available at github.com/vicLeva/tuna under the MIT license.

Read the paper

Discussion

Science Skim's AI key points, plus readers' public thoughts

Readers' thoughts

No reader thoughts yet.

Related papers