k-mer based classification

Kraken 1, Kraken 2, KrakenUniq and Bracken

Four tools, one idea: index every k-mer of every reference genome, map each one to the lowest common ancestor of the genomes that contain it, then classify a read by looking up its k-mers and walking the taxonomy. What separates the versions is how that index is stored, how false positives are controlled, and whether the output is a read count or an abundance.

The algorithm

sp Asp B sp Csp D root reference taxonomy k-mer → LCA ACGTTGACC… → sp A GTTGACCAT… → genus TTGACCATG… → phylum TGACCATGA… → sp A GACCATGAC… → (absent) query read sliding k-mers 524 5 k-mers at sp A · 4 at the genus · 2 at the root root-to-leaf path scores root→genus→sp A = 2+4+5 = 11 root→genus→sp B = 2+4+0 = 6 assigned: species A confidence = C / Q C = k-mers in the clade under the label Q = unambiguous k-mers in the read --confidence default: 0.0 --minimum-hit-groups default: 2 more than one group of overlapping k-mers sharing a minimizer, before anything is called classified A read count is not an abundance. A 6 Mb genome yields twice the reads of a 3 Mb one at the same cell abundance, and a genome with few unique regions loses its reads upward to the genus.

Kraken 1 → Kraken 2: what actually changed

Kraken 1 (Wood & Salzberg, Genome Biology, 2014) stored every k-mer of every reference genome, exactly, in a sorted structure. It was fast and accurate and it needed an enormous amount of memory. Kraken 2 (Wood, Lu & Langmead, Genome Biology, 2019) changed the storage, and that one change produces every other difference.

Kraken 1Kraken 2
What is storedevery k-merminimizers — one representative ℓ-mer per window of k-mers
Structureexact, sortedcompact hash table, storing a truncated hash rather than the full key
Consequenceexact lookupsprobabilistic: two different keys can collide, producing a small rate of false-positive assignments
Accuracy aid—spaced seeds in the storage and querying of minimizers
Memory / diskvery largemuch smaller — the standard database (bacteria, archaea, viruses, human, UniVec_Core) needs roughly 100 GB of disk to build
Speedfastfaster
The trade nobody states

Kraken 2's speed and size come from a data structure that can be wrong. The documented database false-positive rate is under 1% of queries, and the stated mitigation is the confidence threshold — which is off by default. So the out-of-the-box configuration is the one with the least protection against exactly the failure mode the design introduced. Setting a confidence threshold is not tuning; it is completing the setup.

KrakenUniq, and the distinct-minimizer idea

KrakenUniq extended Kraken 1 with one additional statistic per taxon: an estimate of the number of distinct k-mers from that taxon seen in the data. That number separates two situations a read count cannot.

taxon A · 4,000 reads taxon B · 4,000 reads spread across the genome — many distinct k-mers piled on one short region — very few distinct k-mers what makes a pile a conserved gene shared far outside this taxon a mobile element or low-complexity repeat contaminating sequence inside the reference genome a hash collision in the compact table report distinct k-mers, not just reads KrakenUniq: HyperLogLog cardinality estimate Kraken 2: --report-minimizer-data adds total and distinct minimizers per taxon kraken2 --report-minimizer-data → filter on distinct minimizers → bracken One of the few false-positive controls that costs nothing and requires no guessed threshold. Filter before Bracken, not after — Bracken redistributes reads, and a spurious taxon spreads its reads around.

Bracken is not a classifier

This is the most common misunderstanding in the family. Bracken (Bayesian Reestimation of Abundance after Classification with KrakEN) does not re-classify anything and does not change any read's taxonomic label. It takes Kraken's output and redistributes the counts.

  1. The problem it solves Kraken assigns a read to the LCA of everything its k-mers match. For genomes that share a lot of sequence with close relatives, that means most reads pile up at the genus or family node — so the species rows are empty even though the species is abundant.
  2. What it does Reads sitting above the species level are pushed down to species; reads sitting at strain level are pulled up to their parent species. The probabilities come from the Kraken database itself: how much of each genome is identical to each other genome.
  3. Which is why it is read-length specific bracken-build must be run for the k-mer length used to build the Kraken database and for the read length you will analyse. A distribution file built for 100 bp reads is the wrong file for 150 bp reads.
  4. And why it cannot rescue a bad classification Bracken redistributes whatever Kraken gave it. If Kraken produced spurious taxa — no confidence threshold, a contaminated database, hash collisions — Bracken will faithfully redistribute reads into them, and give the artefact a confident-looking abundance. Filter first, then Bracken.

The database is the method

Ranked roughly by how much each decision moves the answer, which is not the order most people spend their attention in:

DecisionEffectDefault
Which reference databaseLargest. Standard (bacteria, archaea, viral, human, UniVec_Core) versus a PlusPF-style build with protozoa and fungi versus a full nt build are different experimentswhatever you downloaded
Confidence thresholdLarge. Trades recall for precision; raising it walks labels up the tree rather than discarding them0.0 — none
Distinct-minimizer filteringModerate and cheap. Removes the pile-on-one-region artefactsoff
Minimum hit groupsSmall but free2
Host and vector removalLarge in host-associated or low-biomass samplespartly handled by including human and UniVec_Core in the standard DB
Bracken read lengthModerate; wrong file means wrong redistributionmust match your reads

Pre-built indexes are published and versioned, which is the reproducible way to do this: cite the index build you used, by date, alongside the tool version. "Kraken 2 standard database" without a build date is not reproducible — the standard database is a moving target, because RefSeq is.