metagenomics/kraken-classification/SKILL.md
Classifies shotgun metagenomic reads to taxa with Kraken2's minimizer/LCA matching against a chosen reference database, then hands off to Bracken for abundance re-estimation. Covers why the database (not the algorithm) decides what can be detected, the --confidence and --minimum-hit-groups precision levers, unique-minimizer false-positive control, host-read removal, and why raw Kraken2 read counts are not abundances. Use when profiling who-is-there from shotgun reads, choosing a Kraken2 database, setting a confidence threshold, controlling false positives, or feeding reports to Bracken. For marker-gene profiling see metaphlan-profiling; for abundance mechanics see abundance-estimation; for assembly/MAG recovery see genome-assembly/metagenome-assembly.
npx skillsauth add GPTomics/bioSkills bio-metagenomics-krakenInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reference examples tested with: Kraken2 2.1.3+, Bracken 2.9+, KrakenTools 1.2+, pandas 2.2+.
Before using code patterns, verify installed versions match. If versions differ:
kraken2 --version, bracken -h, kraken2 --help to confirm flags and defaultspip show <package> then help(module.function) to check signaturesIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
The DATABASE is the version that matters most. A taxon absent from the database is invisible no matter how the binary is configured. Record the Kraken2 database build (Standard / PlusPF / PlusPFP / nt / GTDB, and whether capped to 8/16 GB) and the Bracken databaseRLENmers.kmer_distrib read length, which must match both the Kraken2 database and the actual read length. --minimum-hit-groups enforcement varied across older 2.x point releases; confirm defaults with kraken2 --help on the installed build.
"What's in my metagenome?" -> Match each read's k-mers to a reference database by lowest-common-ancestor, then re-estimate abundance with Bracken - because the database, not the algorithm, decides what can be found.
kraken2 --db DB --paired R1.fq.gz R2.fq.gz --report out.kreport --confidence 0.1 --output out.krakenScope: read-based, assembly-free taxonomic classification of shotgun reads, plus the Bracken handoff. Marker-gene profiling -> metaphlan-profiling. Bracken command mechanics -> abundance-estimation. Genome/MAG recovery -> genome-assembly/metagenome-assembly. Host removal and read QC -> read-qc/contamination-screening, contamination-controls. Amplicon/16S -> the microbiome category.
Kraken reports what each read most resembles in THIS database - never what is truly present, and never how much. Every number is hostage to three choices made before the run: the database, the confidence threshold, and the assumption that read count means abundance. Three corollaries each common misuse violates:
--confidence 0 with the LCA rule, one shared k-mer labels a read with its nearest database relative even when the true organism is absent. Absence-from-database becomes a confident wrong species.Organize the analysis around defending against these three, not around listing flags. Kraken2 at defaults over-classifies; Kraken2 tuned (right database + confidence + hit-groups + a unique-k-mer floor + host removal) is competitive with any classifier.
Kraken1 (Wood & Salzberg 2014 Genome Biol 15:R46) stored every exact k-mer. Kraken2 (Wood 2019 Genome Biol 20:257) replaced that with three ideas that make it fast and lean but PROBABILISTIC: (a) minimizers collapse each k-mer (default k=35) to the smallest hashed l=31-mer in its window; (b) a spaced seed (s=7 masked positions) tolerates errors at "don't care" positions; (c) a compact hash table stores only high bits of each key. The compact hash can return a wrong or spurious LCA on collision - which is exactly why the precision levers below exist. Calling Kraken2 "exact k-mer" hides where false positives come from.
| Tool | Citation | Mechanism / role | When | |------|----------|------------------|------| | Kraken2 | Wood 2019 Genome Biol 20:257 | minimizer + spaced-seed + compact-hash LCA | fast read classification; database-bound; the default choice | | Bracken | Lu 2017 PeerJ Comput Sci 3:e104 | Bayesian redistribution of reads stranded at higher ranks | always run after Kraken2 for species/genus estimates | | KrakenUniq | Breitwieser 2018 Genome Biol 19:198 | HyperLogLog count of unique k-mers per taxon | false-positive control on hits of interest | | KMCP | Shen 2023 Bioinformatics 39:btac845 | genome-coverage pseudo-mapping | low-depth/clinical/viral where conserved-region FPs hurt | | sourmash gather | Pierce 2019 F1000Res 8:1006 | FracMinHash containment, min-set-cover | "which genomes are present" with calibrated containment | | MetaPhlAn 4 | Blanco-Miguez 2023 Nat Biotechnol 41:1633 | clade-specific marker genes | -> metaphlan-profiling; FP-conservative, abundance directly |
| Scenario | Recommended | Why | |----------|-------------|-----| | Who-is-there, fast, custom database possible | Kraken2 + Bracken | k-mer LCA; Bracken fixes count->rank, not count->cells | | Need species relative abundance with no database build | -> metaphlan-profiling | marker-based; abundance-conservative; no FP tail | | Low-biomass / clinical pathogen ID | Kraken2 (high confidence + hit-groups) + KrakenUniq unique-k-mer floor | the FP tail is the enemy; one unique-k-mer filter cuts phantoms | | Reads not host-depleted / unQC'd | -> contamination-controls, read-qc/contamination-screening first | host reads swamp the profile; references carry human fragments | | Want abundance comparable across studies | state the database + confidence; do not merge with MetaPhlAn percentages | read fraction != cell fraction; different tools = different quantities | | Recover genomes / novel taxa / MAGs | -> genome-assembly/metagenome-assembly | classification is assembly-free and database-bound | | 16S amplicon reads | -> microbiome category | Kraken-on-16S works but amplicon analysis lives there |
# Paired-end, with the precision levers that defaults omit
kraken2 --db "$KRAKEN_DB" \
--paired --gzip-compressed --threads 8 \
--confidence 0.1 \ # raise from default 0 to suppress single-k-mer false positives
--minimum-hit-groups 2 \ # require >=2 distinct hit regions (default 2; raise to 3 for clinical)
--report out.kreport \
--output out.kraken \
R1.fq.gz R2.fq.gz
--paired joins mates with a k-mer-breaking N and classifies the pair as one fragment, raising specificity. The per-read --output (large) can be dropped to /dev/null once the .kreport is what feeds Bracken. --memory-mapping runs without loading the database into RAM (slower; for low-memory hosts).
Goal: Separate a real low-abundance organism from a single-region phantom before believing any tail taxon.
Approach: Enable --report-minimizer-data so the report carries distinct-minimizer counts; a taxon with many reads but few distinct minimizers is hitting one conserved region and is a red flag. KrakenUniq's HyperLogLog unique-k-mer count is the heavier-weight version of the same signal.
kraken2 --db "$KRAKEN_DB" --paired --confidence 0.1 \
--report-minimizer-data \ # inserts 2 columns: total + DISTINCT minimizers (shifts later columns)
--report out.kreport --output /dev/null \
R1.fq.gz R2.fq.gz
# A species with high reads but low distinct-minimizers = false positive (one region lit up repeatedly).
Calibrate a unique-k-mer floor against negative controls rather than hard-coding one; the clinical ">=1024 unique k-mers" cutoff is dataset/database-specific folklore, not a constant.
Goal: Build a database whose contents define exactly the detectable universe (and include human for host capture).
Approach: Download taxonomy, add the libraries the question needs (including human), build the minimizer index, then build the matching Bracken distributions at the actual read length.
kraken2-build --download-taxonomy --db custom_db
for lib in bacteria archaea viral human UniVec_Core; do
kraken2-build --download-library "$lib" --db custom_db
done
kraken2-build --build --db custom_db --threads 16 # writes hash.k2d, opts.k2d, taxo.k2d
kraken2-build --clean --db custom_db # drop library/ + taxonomy/ to shrink
bracken-build -d custom_db -t 16 -k 35 -l 150 # -k MUST equal the Kraken2 k (35); -l = read length
kraken2-build --special gtdb builds a GTDB-taxonomy database (curated; the greengenes/silva/rdp special downloads have rotted). --max-db-size randomly downsamples k-mers to fit a cap - this is how the prebuilt 8gb/16gb databases are made, and the reason confidence collapses classification on them.
Kraken strands reads at the shared genus when species share k-mers; Bracken redistributes them down using genome-derived priors. It fixes the wrong-rank problem only - never genome-size bias, and never false positives (it can amplify or even invent a species by reassigning an absent organism's reads to its nearest congener). Run FP control first. Command mechanics live in abundance-estimation:
bracken -d "$KRAKEN_DB" -i out.kreport -o out.bracken -w out.bracken.kreport \
-r 150 \ # MUST match a built databaseRLENmers.kmer_distrib AND the actual read length
-l S -t 10 # species level; -t is a redistribution floor (drops taxa with fewer than 10 clade-level reads, strict <), not a confidence
Trigger: running --confidence 0 and reporting the species list. Mechanism: one shared k-mer can classify a read; the LCA labels it with its nearest database relative. Symptom: hundreds of low-abundance species, many biologically implausible. Fix: --confidence 0.1-0.4 (database-dependent) plus --minimum-hit-groups >=2; verify the tail with unique minimizers.
Trigger: using the .kreport percentage column as relative abundance. Mechanism: read count is proportional to abundance x genome length x copy number. Symptom: large-genome taxa overstated; downstream diversity/ordination on a non-cell-fraction. Fix: run Bracken for the rank problem; treat even Bracken fraction_total_reads as a read fraction and hand off genome-size/copy-number caveats to abundance-estimation.
Trigger: -r 100 on 150 bp reads, or a database built only for a different length. Mechanism: the redistribution model is fragment-length specific. Symptom: biased abundances with no error (silent) if the .kmer_distrib exists, hard crash if it does not. Fix: -r = actual read length AND a matching databaseRLENmers.kmer_distrib must exist (build it or pick a prebuilt database shipping that length).
Trigger: a Standard-8/16 database with confidence cranked up. Mechanism: capped databases are random k-mer subsamples; few reads can clear a high threshold. Symptom: classification collapses toward zero; "my sample is mostly novel." Fix: use a full/large database for high confidence, or lower confidence on a capped database and accept lower precision.
Trigger: classifying without host depletion, then trusting human and low-level hits. Mechanism: host reads dominate low-biomass samples, and >2 million GenBank entries carry mislabeled human/vector sequence (Steinegger & Salzberg 2020 Genome Biol 21:115). Symptom: confident Homo sapiens plus a long artifactual tail. Fix: include human in the database and/or host-deplete upstream; scrutinize any taxon co-varying with host load; consider Recentrifuge negative-control subtraction.
| Threshold | Source | Rationale |
|-----------|--------|-----------|
| --confidence 0.0 default; use 0.2-0.4 on a comprehensive DB | Liu 2024 aBIOTECH 5:465; Lu 2022 Nat Protoc 17:2815 | species precision rose from ~0.16 to ~0.76 at CS 0.2; default over-classifies |
| --minimum-hit-groups 2 (raise to 3 for clinical) | Kraken2 manual | a single lucky minimizer/collision cannot make a call |
| Bracken -k = 35 | Lu 2017 PeerJ Comput Sci 3:e104 | must equal the Kraken2 database k-mer length |
| Bracken -r = actual read length | Bracken docs | redistribution priors are fragment-length specific |
| Bracken -t 10 default | Bracken docs | redistribution floor; too high deletes real rare taxa, not a confidence |
| Classification rate 30-70% (environmental) | community | low rate = novel taxa OR host contamination OR wrong database - diagnose which |
| Build k/l/s = 35/31/7 (nuc); 15/12/0 (prot) | Kraken2 manual | build-time only; cannot change k at classify time |
| Error / symptom | Cause | Solution |
|-----------------|-------|----------|
| Hundreds of implausible species | --confidence 0, no hit-group floor | raise confidence; --minimum-hit-groups >=2; unique-k-mer filter |
| Bracken: "kmer_distrib file not found" | -r has no matching built distribution | run bracken-build -l <readlen> or use a prebuilt DB shipping that length |
| Report parsing columns misaligned | --report-minimizer-data inserted 2 columns | parse 8-column layout when the flag is on |
| Near-zero classification on a small DB | capped (downsampled) DB + high confidence | larger DB, or lower confidence on the capped DB |
| Confident human + odd tail | host reads + contaminated references | host-deplete first; treat human/tail as suspect |
| Bash example silently truncates flags | inline # comment after a \ line continuation | put comments on their own line |
tools
End-to-end CLIP-seq pipeline from FASTQ to ENCODE-compliant binding sites, single-nucleotide crosslink maps, annotation, motifs, and (optionally) differential binding. Use when running the full Yeo lab eCLIP / iCLIP / iCLIP2 / iCLIP3 / irCLIP / PAR-CLIP analysis with SMInput control, protocol-specific UMI extraction, ENCODE STAR parameters, CLIPper or Skipper peak calling with stringent log2 FC and -log10 p thresholds, IDR rescue and self-consistency QC, and downstream motif registration with mCross or PEKA.
development
Detect, date, and contextualize whole-genome duplication (WGD / paleopolyploidy) events using wgd v2 (Chen et al 2024), KsRates (Sensalari 2022 substitution-rate-corrected Ks dating), DupGen_finder (Qiao 2019), MAPS (Li 2018 phylogenomic), POInT (Conant 2008 ordered-block), SLEDGe (2024 ML-based), Whale.jl (Bayesian DL+WGD), and synteny-anchored paranome construction. Use when identifying ancient polyploidy from Ks distributions and synteny block analysis, positioning WGD events relative to speciation, distinguishing tandem from segmental from WGD duplications, dating the 2R/3R vertebrate / fish / salmonid WGDs, building paranome and Ks-age mixture models, applying KsRates substitution-rate correction across lineages, or testing alternative biased-fractionation / dosage-balance models post-WGD.
tools
Build whole-genome alignments using Progressive Cactus (Armstrong 2020 reference-free clade-level WGA), Minigraph-Cactus (Hickey 2024 pangenome-aware), LASTZ chain/net (UCSC pipeline), MUMmer4 (Marçais 2018 pairwise), minimap2 -x asm5/10/20 (Li 2018 fast pairwise), AnchorWave (Song 2022 WGD-aware), and Mauve / progressiveMauve (bacterial). Operates the HAL toolkit (Hickey 2013) for downstream extraction including halSynteny, halLiftover, halBranchMutations, and hal2maf. Use when constructing multi-species alignments for comparative-annotation projection (TOGA), synteny detection, conservation analyses (phyloP / PhastCons), or pangenome graph construction; selecting between reference-free (Cactus) and reference-anchored (LASTZ chains/nets) approaches; tuning sensitivity for closely vs distantly related genomes; or producing HAL files for genome-wide downstream tools.
development
Detect syntenic blocks and structural rearrangements between genomes using MCScanX (Wang 2012), JCVI/MCScan (Tang 2008 Python), GENESPACE (Lovell 2022) for orthology-anchored riparian visualization, SyRI for structural variation, AnchorWave for sequence-level synteny, i-ADHoRe 3.0 for highly diverged species, SynNet for synteny networks, and ntSynt for multi-genome macrosynteny. Use when identifying collinear gene blocks across species, distinguishing macrosynteny from microsynteny, detecting inversions/translocations/duplications, anchoring orthology in WGD lineages, producing publication riparian plots, computing synteny block age via Ks (cross-references whole-genome-duplication), or running synteny-aware ortholog inference in polyploids.