1. Introduction
K-mer analysis is central to genome assembly, metagenomics, and variant detection. A k-mer refers to a substring of length k derived from DNA or RNA sequences, and analyzing its frequency and distribution can reveal genomic structure and function. However, the surge in sequencing data has heightened computational performance requirements, driving the need for more efficient algorithms.
Python is widely used for k-mer analysis in various programming languages due to its concise syntax, rich library resources, and strong compatibility with machine learning. Compared to traditional implementations in C++ or Java, Python facilitates rapid development and integration of bioinformatics tools. Meanwhile, greedy algorithms, which achieve fast, approximate optimal solutions at lower computational costs, are increasingly applied in k-mer processing. This article explores the current state of Python's application in k-mer analysis, computational challenges, and the latest advancements in greedy algorithms. It also envisions its optimization potential in large-scale genomic research.
2. Applications of k-mer analysis in bioinformatics
K-mer analysis represents a fundamental methodology within bioinformatics, finding broad application across diverse contexts, including but not limited to genome assembly, variant identification, metagenomic studies, and the correction of sequencing errors. With the development of second- and third-generation sequencing technologies, Next-generation sequencing (NGS) has become a crucial tool in genomic research, producing millions to billions of nucleotides in a single run, providing foundational support for high-throughput assembly [1]. While NGS is the cornerstone in assembly, k-mer-based de Bruijn graph algorithms can efficiently construct sequence graphs and reconstruct genome structures. The sorting-optimized distributed-memory k-mer counter HySortK significantly reduces memory usage and improves processing efficiency, demonstrating excellent performance in practical large-scale k-mer datasets [2].
In variant detection, Jellyfish leverages lock-free hashing and parallel optimization to rapidly count k-mer frequencies under high coverage, providing high-coverage k-mer counts that underpin downstream variant calling and quality control [3]. Within Python workflows, k-mer toolkits (e.g., khmer) together with the scientific stack (NumPy/Scikit-learn) enable principal component analysis (PCA) on k-mer frequency vectors, which can be used to explore separations among taxa or contigs in practice.
In metagenomic classification, MT-MAG employs alignment-free k-mer frequency and hierarchical taxonomic structures, combined with a confidence prediction mechanism, to effectively support the complete or partial classification of microbial assembled genomes (MAGs) in environmental samples. It achieves up to 87.32% weighted classification accuracy across multiple test datasets and can partially classify the remaining 27% of sequences, achieving an overall adequate classification coverage of approximately 95.13% [4]. Recent studies demonstrate that k-mer frequency spectra vary markedly among taxa, with tetrapod genomes—such as those of mammals—frequently presenting multimodal distributions, in contrast to the predominantly unimodal patterns observed in bacterial genomes [5]. These modal structures provide identifiable patterns for representation learning; within Python-based pipelines, k-mer–tokenizing models (e.g., DNABERT) and metagenomic taxonomic classifiers leveraging k-mer encodings (e.g., DeepMicrobes) capitalize on this structure and report strong performance in microbiome classification [6, 7]. Additionally, sparsity-exploiting k-mer–based estimation methods (e.g., SEK) formalize community-composition inference as a constrained sparse-recovery problem which is using windowed k-mer statistics with non-negativity/normalization constraints and OMP-based solvers :thereby offering methodological guidance for modeling and tool choices [8]. As a three-stage feedforward greedy algorithm, the GTCA (Greedy Target Controllability Algorithm) satisfies Kalman controllability conditions through progressive driver node selection and achieves efficient and stable target control in complex networks [9]. Its modeling strategy for minimal control sets in biological systems offers structured inspiration for anomaly detection and stability control in sequencing error correction workflows.
3. Greedy algorithms in k-mer analysis
Greedy algorithms are widely adopted in graph computation, path optimization, and network control due to their strong locality, low computational overhead, and ease of implementation. For example, in addressing target controllability challenges, the GTCA algorithm utilizes a three-phase localized greedy approach to iteratively identify driver nodes that satisfy Kalman controllability criteria, thereby exhibiting both computational efficiency and scalability within intricate biological network systems [9].
Similarly, greedy algorithms are extensively applied in genomic data processing, particularly in efficient k-mer selection and compression. For instance, the Matchtigs algorithm proposed by Schmidt et al. employs a greedy heuristic approach to construct compact k-mer set representations, thereby substantially decreasing storage overhead and enhancing query performance [10]. This strategy provides a lightweight path selection mechanism for de Bruijn graph construction and optimization, making it suitable for high-throughput, low-redundancy assembly scenarios.
In practice, greedy algorithms are applied to tasks such as de Bruijn graph simplification, k-mer spectrum assembly, and compressed storage. For instance, genome assemblers such as SPAdes and MEGAHIT employ localized graph traversal algorithms to resolve branching complexities and sequencing ambiguities within assembly graphs, thereby enhancing the accuracy and quality of short-read assemblies. Additionally, the UST algorithm proposed by Rahman and Medvedev employs a greedy heuristic to construct SPSS sets, reducing the total character count while maintaining accuracy, making it suitable for compression and fast queries [11].
Although greedy algorithms are computationally efficient, they are prone to introducing redundant paths and misassembly issues when handling highly repetitive regions and high-error-rate data. Due to the absence of global optimality, these methods can result in fragmented assemblies. To mitigate this issue, researchers have introduced hybrid strategies that integrate probabilistic modeling, adaptive thresholding, and denoising preprocessing techniques to improve the robustness and accuracy of classification and assembly processes.
Recent studies have explored adaptive greedy algorithms integrating feedback mechanisms with Bayesian modeling to enhance decision-making resilience. At the same time, parallelization designs improve their scalability in high-throughput metagenomic and transcriptomic data. Concurrently, graph optimization approaches like the k-greedy routing algorithm offer theoretical frameworks for enhancing path selection efficiency within complex network structures. In the future, greedy strategies are expected to co-evolve with AI decision models like deep learning and reinforcement learning, optimising biological assembly workflows through data-driven greedy path selection. With access to cloud computing resources, their deployment capabilities in petabyte-scale data analysis will be further enhanced.
4. Computational challenges of Python in k-mer analysis
Although greedy algorithms and AI-driven methods theoretically offer great potential for k-mer analysis, their practical performance in large-scale genome processing ultimately depends on the efficiency and scalability of their programming implementations. Python is widely adopted among various programming languages due to its ease of use and ecosystem. However, when applying these advanced strategies in Python, a series of computational bottlenecks often arise, which may undermine their effectiveness in real-world applications. For instance, when processing large-scale genomic data, the three major computational bottlenecks in k-mer analysis include memory efficiency, processing performance, and system scalability.
First, k-mer counting and indexing operations often require handling billions of substrings simultaneously. Although conventional hash tables and Bloom filters are widely employed, their substantial memory requirements constrain their scalability. Python's efficiency in big data processing is constrained by dynamic memory management and higher computational overhead, making it less efficient than C/C++. To address the growing memory pressure in ultra-large-scale k-mer data analysis, researchers have proposed compressed indexing-based processing strategies, employing structures like the Burrows-Wheeler Transform (BWT) and FM-index to achieve low-redundancy, high-query-efficiency k-mer representation and retrieval. For instance, UST-FM, developed in C/C++, encodes string data into compact representation sets (SPSS) and integrates these with the FM-index to construct efficient indices, thereby significantly minimizing memory consumption and expediting k-mer membership queries [11].
Despite Python's flexibility and ease of use, its performance is significantly limited by the Global Interpreter Lock (GIL). This makes traditional multithreading models inefficient for leveraging multi-core resources, especially in compute-intensive tasks like large-scale k-mer counting. In contrast, distributed tools based on high-performance languages (e.g., C++/MPI), such as HySortK [2], optimize memory access patterns through sorting strategies and employ hybrid parallel designs (MPI+OpenMP), achieving notable acceleration in k-mer counting (2x faster than CPU tools) and reduced memory usage (30% lower peak memory). The effectiveness of these tools underscores the critical role that low-level compiled languages play in advancing genomic data analysis. Although Python's ecosystem offers parallel libraries like Dask and Ray for task scheduling or GPU acceleration via PyCUDA and CuPy, its overall performance remains constrained by the inherent overhead of interpreted languages and GIL limitations. For example, HySortK processes human genome data on a 16-node cluster 2x faster with 30% lower memory usage than traditional CPU methods [2]. At the same time, similar optimizations are challenging to achieve in Python's ecosystem due to technical stack limitations.
Facing the challenge of terabyte-scale data, Python tools have begun integrating frameworks like Spark and Hadoop to achieve large-scale parallel processing. Kim et al.'s MapReduce k-mer clustering algorithm was effectively incorporated into the Inchworm module of the Trinity platform, resulting in a substantial decrease in memory consumption and enabling scalable, distributed transcriptome assembly [12]. Meanwhile, cloud computing platforms like AWS and Google Cloud enable real-time k-mer analysis through elastic resources, enhancing workflow scalability. However, current solutions still face issues like network latency and inefficient distributed I/O, necessitating further optimization in parallel scheduling, memory management, and GPU integration strategies.
5. Python-based k-mer analysis solutions
The challenges posed by large-scale datasets have driven continuous advancements in Python's application for k-mer analysis, including sorting optimization, parallel computing, and AI integration.
Initially, conventional hashing techniques exhibit constraints in terms of memory efficiency and scalability. In contrast, sorting-based k-mer counting approaches mitigate memory consumption by segmenting and organizing k-mers through partitioning and sorting processes. Leveraging libraries like Dask and NumPy, Python can handle massive data more efficiently in memory and for sorting. Additionally, research has proposed automatic switching of sorting algorithms under limited memory resources to improve processing performance in external memory sorting techniques.
Secondly, distributed models (such as MapReduce) have been proven effective in improving computational efficiency (e.g., Trinity optimization in bioinformatics [12]). Similar functionality can be achieved in the Python ecosystem using Dask or PySpark to circumvent GIL limitations. Additionally, GPU acceleration technologies (such as PyCUDA and CuPy) are emerging as a trend, significantly reducing the time required for k-mer counting and clustering in large-scale parallel computing, particularly for real-time genome analysis.
Finally, Python's robust machine learning ecosystem has brought breakthroughs in k-mer classification. In contrast to conventional alignment-based techniques and marker gene-dependent methodologies, alignment-free strategies like MT-MAG and DeepMicrobes leverage k-mer frequency-based feature extraction, demonstrating superior efficacy in metagenomic classification applications. Notably, at the species level, MT-MAG's weighted classification accuracy is on average approximately 34.79% higher than DeepMicrobes [4]. Moreover, algorithms like decision trees and SVMs help identify important k-mer features, aiding in mutation prediction and biomarker screening. However, challenges such as insufficient training data and model interpretability remain. Subsequent investigations should prioritize enhancing model generalizability and robustness in scenarios with limited annotated datasets. Leveraging unsupervised, transfer, and active learning strategies within the Python framework will further propel the intelligent utilization of k-mer analysis in genomics research.
6. Future directions of Python-based k-mer analysis
With the advancement of sequencing technologies, the volume of genomic data continues to grow, necessitating improvements in memory efficiency, computational speed, and scalability for Python-based k-mer analysis. To address these challenges, future research must optimise memory usage, leverage GPU acceleration, integrate cloud computing, and apply AI-driven techniques.
A key area for improvement is optimizing memory through compression techniques and efficient indexing structures. Methods such as Bloom filters, Count-Min Sketch, and FM indexes help reduce memory overhead while maintaining accuracy, making large-scale genomic analysis more feasible. Enhancing Python's data management capabilities, including low-level memory handling via Cython and NumPy's structured arrays, can improve k-mer processing performance.
GPU acceleration has become a powerful solution for enhancing the efficiency of Python-based k-mer analysis. Frameworks like CuPy, PyCUDA, and RAPIDS facilitate the delegation of computationally demanding operations to GPUs, resulting in substantial enhancements in processing throughput relative to conventional CPU-centric approaches. Additionally, cloud-based platforms like AWS, Google Cloud Genomics, and Microsoft Azure provide scalable, on-demand computing resources, making large-scale k-mer analysis more accessible and cost-effective.
Beyond hardware-level optimizations such as GPUs and cloud computing, integrating AI-driven approaches opens a new frontier of limitless possibilities for enhancing Python-based k-mer analysis. Machine learning models, specifically convolutional and recurrent neural networks, have demonstrated superior performance compared to conventional approaches in taxonomic classification, mutation detection, and genome annotation. Tools like DeepMicrobes and DeepK-mer showcase the potential of AI in improving microbial species identification, while predictive modeling approaches aid in detecting rare genetic variants associated with disease susceptibility.
Despite these advancements, challenges persist, including but not limited to model interpretability, high computational demands, and the need for large labeled datasets. Subsequent research endeavors should prioritize the advancement of semi-supervised learning methodologies and the optimization of artificial intelligence models to augment their utility within the realm of k-mer analysis. By combining AI, GPU acceleration, and cloud computing, Python-based k-mer analysis can achieve greater scalability, enabling real-time genomic research and advancing the field of bioinformatics.
7. Conclusion
Python is pivotal in k-mer analysis, genome assembly, variant detection, and microbial classification. Its rich library ecosystem and ease of use make it an ideal language for building large-scale bioinformatics pipelines. Through sorting optimizations, parallel computing, and AI model integration, Python has significantly improved computational efficiency in these areas. Nevertheless, challenges such as high memory overhead, limited parallelism, and execution performance remain. Traditional hash-counting methods face high memory consumption, while the GIL restricts multi-core utilization efficiency. Optimisation relies on frameworks like Dask, multiprocessing, and compressed indexing techniques.
In the future, GPU acceleration tools (such as CuPy and PyCUDA) will enhance processing speed. At the same time, deep learning models will also improve the accuracy of k-mer classification and variant detection. Combining greedy algorithms and AI will contribute to more robust assembly path selection. Furthermore, the integration of high-performance computing (HPC), cloud computing platforms, and automated inference systems will enhance Python's utility in petabyte-scale data processing. With the widespread adoption of cloud-based analysis platforms and the deepening application of AI real-time models, Python is poised to continue leading the development of k-mer analysis methods, driving ongoing innovation in precision medicine, pathogen surveillance, and evolutionary genomics research.
References
[1]. Mandlik, J., Patil, A., & Singh, S. (2024). Next-generation sequencing (NGS): Platforms and applications. Journal of Pharmacy & Bioallied Sciences, 16, 41–45. https: //doi.org/10.4103/jpbs.jpbs_838_23
[2]. Li, Y., & Guidi, G. (2024). High-performance sorting-based k-mer counting in distributed memory with flexible hybrid parallelism [Preprint]. arXiv https: //arxiv.org/abs/2407.07718
[3]. Marçais, G., & Kingsford, C. (2011). A fast, lock-free approach for efficient parallel counting of occurrences of k-mers. Bioinformatics, 27(6), 764–770. https: //doi.org/10.1093/bioinformatics/btr014
[4]. Li, W., Kari, L., Yu, Y., & Hug, L. A. (2023). MT-MAG: Accurate and interpretable machine learning for complete or partial taxonomic assignments of metagenome-assembled genomes. PLOS ONE, 18(8), e0283536. https: //doi.org/10.1371/journal.pone.0283536
[5]. Chor, B., Horn, D., Goldman, N., Levy, Y., & Massingham, T. (2009). Genomic DNA k-mer spectra: Models and modalities. Genome Biology, 10(10), R108. https: //doi.org/10.1186/gb-2009-10-10-r108
[6]. Ji, Y., Zhou, Z., Liu, H., & Davuluri, R. V. (2021). DNABERT: Pre-trained Bidirectional Encoder Representations from Transformers model for DNA-language in genome. Bioinformatics, 37(15), 2112–2120. https: //doi.org/10.1093/bioinformatics/btab083
[7]. Liang, Q., Bible, P. W., Liu, Y., Zou, B., & Wei, L. (2020). DeepMicrobes: taxonomic classification for metagenomics with deep learning. NAR Genomics and Bioinformatics, 2(1), lqaa009. https: //doi.org/10.1093/nargab/lqaa009
[8]. Chatterjee, S., Koslicki, D., Dong, S., Innocenti, N., Cheng, L., Lan, Y., Vehkaperä, M., Skoglund, M., Rasmussen, L. K., Aurell, E., & Corander, J. (2014). SEK: Sparsity exploiting k-mer-based estimation of bacterial community composition. Bioinformatics, 30 (17), 2423–2431. https: //doi.org/10.1093/bioinformatics/btu320
[9]. Khezri, S. F., Ebrahimi, A., & Eslahchi, C. (2024). Target controllability: A feed-forward greedy algorithm in complex networks, meeting Kalman’s rank condition. Bioinformatics, 40 (11), 1–9. https: //doi.org/10.1093/bioinformatics/btae630
[10]. Schmidt, S., Khan, S., Alanko, J. N., Pibiri, G. E., & Tomescu, A. I. (2023). Matchtigs: Minimum plain text representation of k-mer sets. Genome Biology, 24(1), 136. https: //doi.org/10.1186/s13059-023-02968-z
[11]. Rahman, A., & Medvedev, P. (2021). Representation of k-mer sets using spectrum-preserving string sets. Journal of Computational Biology, 28 (4), 381–394. https: //doi.org/10.1089/cmb.2020.0431
[12]. Kim, C. S., Winn, M. D., Sachdeva, V., & Jordan, K. E. (2017). K-mer clustering algorithm using a MapReduce framework: Application to the parallelization of the Inchworm module of Trinity. BMC Bioinformatics, 18, 1–15. https: //doi.org/10.1186/s12859-017-1881-8”
Cite this article
Zhang,M. (2025). Efficient K-mer Processing in Genomics: Challenges and Innovations with Python and Greedy Algorithms. Theoretical and Natural Science,129,1-6.
Data availability
The datasets used and/or analyzed during the current study will be available from the authors upon reasonable request.
Disclaimer/Publisher's Note
The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of EWA Publishing and/or the editor(s). EWA Publishing and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
About volume
Volume title: Proceedings of ICBioMed 2025 Symposium: Computational Modelling and Simulation for Biology and Medicine
© 2024 by the author(s). Licensee EWA Publishing, Oxford, UK. This article is an open access article distributed under the terms and
conditions of the Creative Commons Attribution (CC BY) license. Authors who
publish this series agree to the following terms:
1. Authors retain copyright and grant the series right of first publication with the work simultaneously licensed under a Creative Commons
Attribution License that allows others to share the work with an acknowledgment of the work's authorship and initial publication in this
series.
2. Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the series's published
version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgment of its initial
publication in this series.
3. Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and
during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (See
Open access policy for details).
References
[1]. Mandlik, J., Patil, A., & Singh, S. (2024). Next-generation sequencing (NGS): Platforms and applications. Journal of Pharmacy & Bioallied Sciences, 16, 41–45. https: //doi.org/10.4103/jpbs.jpbs_838_23
[2]. Li, Y., & Guidi, G. (2024). High-performance sorting-based k-mer counting in distributed memory with flexible hybrid parallelism [Preprint]. arXiv https: //arxiv.org/abs/2407.07718
[3]. Marçais, G., & Kingsford, C. (2011). A fast, lock-free approach for efficient parallel counting of occurrences of k-mers. Bioinformatics, 27(6), 764–770. https: //doi.org/10.1093/bioinformatics/btr014
[4]. Li, W., Kari, L., Yu, Y., & Hug, L. A. (2023). MT-MAG: Accurate and interpretable machine learning for complete or partial taxonomic assignments of metagenome-assembled genomes. PLOS ONE, 18(8), e0283536. https: //doi.org/10.1371/journal.pone.0283536
[5]. Chor, B., Horn, D., Goldman, N., Levy, Y., & Massingham, T. (2009). Genomic DNA k-mer spectra: Models and modalities. Genome Biology, 10(10), R108. https: //doi.org/10.1186/gb-2009-10-10-r108
[6]. Ji, Y., Zhou, Z., Liu, H., & Davuluri, R. V. (2021). DNABERT: Pre-trained Bidirectional Encoder Representations from Transformers model for DNA-language in genome. Bioinformatics, 37(15), 2112–2120. https: //doi.org/10.1093/bioinformatics/btab083
[7]. Liang, Q., Bible, P. W., Liu, Y., Zou, B., & Wei, L. (2020). DeepMicrobes: taxonomic classification for metagenomics with deep learning. NAR Genomics and Bioinformatics, 2(1), lqaa009. https: //doi.org/10.1093/nargab/lqaa009
[8]. Chatterjee, S., Koslicki, D., Dong, S., Innocenti, N., Cheng, L., Lan, Y., Vehkaperä, M., Skoglund, M., Rasmussen, L. K., Aurell, E., & Corander, J. (2014). SEK: Sparsity exploiting k-mer-based estimation of bacterial community composition. Bioinformatics, 30 (17), 2423–2431. https: //doi.org/10.1093/bioinformatics/btu320
[9]. Khezri, S. F., Ebrahimi, A., & Eslahchi, C. (2024). Target controllability: A feed-forward greedy algorithm in complex networks, meeting Kalman’s rank condition. Bioinformatics, 40 (11), 1–9. https: //doi.org/10.1093/bioinformatics/btae630
[10]. Schmidt, S., Khan, S., Alanko, J. N., Pibiri, G. E., & Tomescu, A. I. (2023). Matchtigs: Minimum plain text representation of k-mer sets. Genome Biology, 24(1), 136. https: //doi.org/10.1186/s13059-023-02968-z
[11]. Rahman, A., & Medvedev, P. (2021). Representation of k-mer sets using spectrum-preserving string sets. Journal of Computational Biology, 28 (4), 381–394. https: //doi.org/10.1089/cmb.2020.0431
[12]. Kim, C. S., Winn, M. D., Sachdeva, V., & Jordan, K. E. (2017). K-mer clustering algorithm using a MapReduce framework: Application to the parallelization of the Inchworm module of Trinity. BMC Bioinformatics, 18, 1–15. https: //doi.org/10.1186/s12859-017-1881-8”