Skip to content

Article image
K-mer Analysis: Sequence Composition and Frequency

May 16, 2026 · Updated: May 25, 2026

Overview

K-mer analysis decomposes biological sequences into all possible substrings of a fixed length k and counts their frequencies. This simple yet powerful technique captures the compositional properties of genomes and transcriptomes without requiring alignment, making it computationally efficient and reference-free. K-mer frequency distributions reveal genome size, heterozygosity, repeat content, and sequencing error rates from raw reads before any assembly step. The choice of k involves a trade-off: small k values (k < 20) provide robust counts but limited discriminative power, while large k values (k > 50) offer high specificity but lower coverage.

Key Concepts

The k-mer spectrum: a histogram of k-mer occurrence frequencies, follows a Poisson-like distribution in ideal data. Erroneous k-mers from sequencing errors appear as singletons (frequency 1), while genuine genomic k-mers form a peak at the expected coverage depth. Genomic repeats produce additional peaks at higher multiplicities. Tools such as Jellyfish and KMC efficiently count k-mers using hash tables or suffix arrays. Beyond counting, k-mer-based methods include k-mer distance (the fraction of shared k-mers between two samples) for phylogeny, k-mer coverage for estimating genome size, and k-mer spectra for error correction by removing k-mers below a coverage threshold.

Applications

K-mer analysis is integral to next-generation sequencing quality control, detecting contamination and estimating coverage before assembly. In bacterial genetics, k-mer-based methods distinguish strains by their unique compositional signatures. Metagenomic binning uses k-mer frequency vectors to cluster contigs from the same organism. DNA sequencing projects use k-mer counting to correct sequencing errors by replacing erroneous bases that create low-frequency k-mers.

Practical Protocol

For k-mer counting with Jellyfish, start from raw FASTQ files: jellyfish count -m 21 -s 100M -t 8 -C -o kmers.jf reads.fastq. Parameters: -m 21 sets k-mer size to 21 (a common default balancing specificity and coverage), -s 100M sets initial hash size (increase for large genomes), -C counts both strands (canonical k-mers), -t 8 uses 8 threads. For large genomes (human, ~3 Gb), increase hash size: -s 3G. Generate a k-mer frequency histogram: jellyfish histo -o kmers.histo kmers.jf. Plot the histogram to visualize the k-mer spectrum: the first peak at frequency 1 represents sequencing errors (singletons), the main peak at the expected coverage depth represents authentic genomic k-mers, and additional peaks at higher frequencies indicate repetitive sequences. Estimate genome size using the formula: genome_size = total_k_mers / peak_frequency. For example, if the main peak is at coverage 20× and total k-mers are 60 million, then genome size ≈ 3 million bp. Use GenomeScope (web tool) to fit a k-mer spectrum model and estimate genome size, heterozygosity, and repeat content. For contamination detection, run KMC for very large datasets: kmc -k21 -m64 -t8 -ci1 reads.fastq kmc_output workdir. Compare the k-mer spectrum to known reference signatures; unexpected high-frequency k-mers that do not match the expected genome may indicate bacterial or adapter contamination. For metagenomic binning, compute k-mer frequency vectors (typically tetranucleotide frequencies, k=4) in 5 kb windows along assembled contigs using seqtk comp or custom scripts, then cluster contigs by compositional similarity using k-means or hierarchical clustering implemented in MetaBAT2. For strain discrimination, use Mash to compute k-mer distances between query sequences and reference databases: mash sketch genome.fasta; mash dist genome.msh reference.msh > distances.txt. The Mash distance approximates mutation rate between genomes.


resource: Lab Lexicon K-mer Composition Analyzer