Kallisto bustools

From swaruplab/operon · View interactive version

Kallisto bustools is an AI agent skill from the GitHub repository swaruplab/operon. scRNA-seq quantification with kallisto + bustools via kb-python. Pseudoalignment-based — orders of magnitude faster than full alignment (STAR / cellranger) while producing comparable count matrices. Covers index generation (kb ref), per-sample quantification (kb count), supported chemistries (10X v1

How to use this skill

Skill file

kallisto | bustools: Pseudoalignment-Based scRNA-seq Quantification

Overview

kallisto + bustools is a pseudoalignment-based quantification pipeline for single-cell RNA-seq. The standard tools (cellranger, STARsolo, alevin-fry) do full alignment of reads to the genome; kallisto skips that and only determines which transcripts are compatible with each read. The result: 5–20× faster than cellranger, comparable accuracy, much lower memory footprint.

The toolkit has three components:

| Tool | What it does |

|---|---|

| kallisto | The pseudoaligner (also handles non-single-cell quantification) |

| bustools | Processes BUS files — barcode correction, UMI dedup, count matrix generation |

| kb-python | Thin wrapper that runs kallisto + bustools end-to-end with one command |

For most users, kb-python is the only entry point you need. This protocol uses kb throughout.

When to Use This Skill

Not for:

Prerequisites

Installation

# pip (recommended)
pip install kb_python

# OR conda
conda install -c bioconda kb-python

# Verify
kb --version
kb --list                              # supported single-cell technologies

kb-python bundles the kallisto + bustools binaries — no separate install needed for them.

For very large indexes (whole genome with introns, atlas-scale references), you may need to build kallisto from source for the v0.50+ features:

git clone https://github.com/pachterlab/kallisto && cd kallisto && mkdir build && cd build
cmake .. -DUSE_HDF5=ON && make && make install

Pipeline 1 — Build the Reference Index

You only do this once per genome. Reuse for all your samples.

Standard transcriptome (most users)

# Inputs: genome FASTA + GTF (matching versions)
# Example with GENCODE human v44:
kb ref \
    -i  index.idx \
    -g  t2g.txt \
    -f1 cdna.fasta \
    GRCh38.primary_assembly.genome.fa.gz \
    gencode.v44.annotation.gtf.gz

Output files:

This takes ~30-60 minutes for human/mouse on a typical workstation. Index files are reusable across all your samples.

Pre-built indexes (skip the build)

For common references, kb-python can download pre-built indexes:

kb ref -d human  -i index.idx -g t2g.txt
kb ref -d mouse  -i index.idx -g t2g.txt
kb ref -d zebrafish -i index.idx -g t2g.txt

Faster than building, identical result. Recommended unless you have a custom genome.

nac workflow — nascent + mature RNA (for snRNA-seq and RNA velocity)

Single-nucleus RNA-seq captures predominantly intronic reads (from pre-mRNA in the nucleus). Standard transcriptome indexes only handle exonic/mature mRNA, so you lose those reads. The nac workflow indexes both.

kb ref \
    --workflow nac \
    -i  index.idx \
    -g  t2g.txt \
    -c1 cdna.txt          \
    -c2 nascent.txt       \
    -f1 cdna.fasta        \
    -f2 nascent.fasta     \
    GRCh38.primary_assembly.genome.fa.gz \
    gencode.v44.annotation.gtf.gz

Additional outputs vs standard:

Required when:

For RNA velocity specifically, also consider the older lamanno workflow which produces the spliced/unspliced layout scVelo expects:

kb ref --workflow lamanno -i index.idx -g t2g.txt \
    -f1 cdna.fasta -f2 intron.fasta \
    -c1 cdna_t2c.txt -c2 intron_t2c.txt \
    GRCh38.primary_assembly.genome.fa.gz gencode.v44.annotation.gtf.gz

Convenience: bash scripts/kb_ref.sh --genome GRCh38.fa --gtf annotation.gtf --out-dir reference/. See references/advanced.md for nac vs lamanno trade-offs and how to choose.

Source: Index generation docs.

Pipeline 2 — Quantify a Sample

# Standard 10X v3 (cellranger output style)
kb count \
    -i index.idx \
    -g t2g.txt \
    -x 10xv3 \
    -o output_dir \
    --h5ad \
    sample_R1.fastq.gz sample_R2.fastq.gz

Key arguments

| Argument | Purpose | Notes |

|---|---|---|

| -i index.idx | Path to the index | From kb ref |

| -g t2g.txt | Transcript-to-gene mapping | From kb ref |

| -x <tech> | Chemistry / sequencing technology | See kb --list |

| -o output_dir | Output directory | Created if missing |

| --workflow nac | Use nascent+mature index | Match the kb ref workflow |

| --h5ad | Write .h5ad directly (scanpy-ready) | Recommended |

| --filter bustools | Apply knee-plot cell filtering | Optional — usually do this in scanpy |

| -t N | Threads | Default 8; bump on big machines |

| -m 8G | Max RAM | Default 4G; bump for big indexes |

Supported chemistries (`-x` values)

| Chemistry | -x value | FASTQ layout |

|---|---|---|

| 10X Chromium v2 (3') | 10xv2 | R1 = barcode (16 bp) + UMI (10 bp); R2 = cDNA |

| 10X Chromium v3 (3' / multiome) | 10xv3 | R1 = barcode (16 bp) + UMI (12 bp); R2 = cDNA |

| 10X Chromium v1 (legacy) | 10xv1 | I1, R1, R2 — index file is the barcode |

| Drop-seq | DROPSEQ | R1 = barcode (12 bp) + UMI (8 bp); R2 = cDNA |

| inDrops v1 | INDROPSV1 | (custom — see kb --list) |

| CEL-Seq | CELSEQ | UMI + barcode in R1 |

| SMART-Seq v2 / v3 | SMARTSEQ2 / SMARTSEQ3 | full-length, --parity paired |

| BD Rhapsody | BDWTA | barcode + UMI |

| Slide-seq, Visium HD, etc. | various | run kb --list |

Full list: kb --list after installation. For unsupported chemistries, define one in seqspec and pass via -x <seqspec.yaml>.

Input FASTQ layout

For paired-end droplet chemistries, file order is R1 first, R2 second, repeated per lane:

kb count -i index.idx -g t2g.txt -x 10xv3 -o out --h5ad \
    L001_R1.fastq.gz L001_R2.fastq.gz \
    L002_R1.fastq.gz L002_R2.fastq.gz \
    L003_R1.fastq.gz L003_R2.fastq.gz

For 10X v1 (legacy), also include the I1 file: I1 R1 R2 I1 R1 R2 ....

For SMART-Seq2 / full-length protocols where both reads are biological, use --parity paired:

kb count -i index.idx -g t2g.txt -x SMARTSEQ2 -o out --parity paired \
    SAMPLE1_1.fastq.gz SAMPLE1_2.fastq.gz \
    SAMPLE2_1.fastq.gz SAMPLE2_2.fastq.gz

Output structure

output_dir/
├── counts_unfiltered/                 # cell × gene matrix BEFORE cell calling
│   ├── cells_x_genes.mtx               # sparse matrix (Matrix Market format)
│   ├── cells_x_genes.barcodes.txt     # cell barcodes (one per row)
│   ├── cells_x_genes.genes.txt        # gene IDs (Ensembl)
│   ├── cells_x_genes.genes.names.txt  # gene symbols
│   └── adata.h5ad                     # AnnData (if --h5ad was passed)
├── inspect.json                        # QC metrics from bustools
├── run_info.json                       # kallisto run info (alignment rate, etc.)
├── output.bus                          # raw BUS file
├── output.unfiltered.bus               # barcode-corrected
└── matrix.ec                           # equivalence classes

The counts_unfiltered/ directory is your handoff point. Empty droplets are NOT filtered out at this stage — call cells with DropletUtils::emptyDrops or CellBender downstream.

Convenience: bash scripts/kb_count.sh --index index.idx --t2g t2g.txt --tech 10xv3 --out-dir sample1_out fastq/R1.fastq.gz fastq/R2.fastq.gz.

Source: pseudoalignment + output files docs.

Pipeline 3 — Handoff to Downstream (scanpy / Seurat / SCE)

scanpy / Python

import scanpy as sc
import anndata

# Easiest: load the .h5ad written by kb count --h5ad
adata = anndata.read_h5ad('output_dir/counts_unfiltered/adata.h5ad')

# Or load the .mtx manually if --h5ad wasn't passed
adata = sc.read_mtx('output_dir/counts_unfiltered/cells_x_genes.mtx')
barcodes = open('output_dir/counts_unfiltered/cells_x_genes.barcodes.txt').read().splitlines()
genes    = open('output_dir/counts_unfiltered/cells_x_genes.genes.txt').read().splitlines()
gene_names = open('output_dir/counts_unfiltered/cells_x_genes.genes.names.txt').read().splitlines()
adata.obs_names = barcodes
adata.var_names = gene_names
adata.var['gene_id'] = genes

# Standard preprocessing (see scanpy protocol for the full pipeline)
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)

Seurat / R

library(Seurat)
library(Matrix)

mtx <- readMM("output_dir/counts_unfiltered/cells_x_genes.mtx")
barcodes <- readLines("output_dir/counts_unfiltered/cells_x_genes.barcodes.txt")
genes    <- readLines("output_dir/counts_unfiltered/cells_x_genes.genes.names.txt")

# kb writes cells × genes; Seurat expects genes × cells — transpose
mtx <- t(mtx)
rownames(mtx) <- genes
colnames(mtx) <- barcodes
mtx <- as(mtx, "CsparseMatrix")

obj <- CreateSeuratObject(counts = mtx, min.cells = 3, min.features = 200)
# Now standard Seurat from here — see seurat protocol

SingleCellExperiment / R

library(SingleCellExperiment)
library(Matrix)

mtx <- t(readMM("output_dir/counts_unfiltered/cells_x_genes.mtx"))
rownames(mtx) <- readLines("output_dir/counts_unfiltered/cells_x_genes.genes.names.txt")
colnames(mtx) <- readLines("output_dir/counts_unfiltered/cells_x_genes.barcodes.txt")

sce <- SingleCellExperiment(assays = list(counts = mtx))
# Now standard SCE pipeline — see singlecellexperiment protocol

Source: kb → scanpy notebook.

nac Workflow — Loading Nascent + Mature Counts

When you ran kb count --workflow nac, the output has BOTH a mature (cdna) and nascent matrix:

import scanpy as sc

# Each matrix is loaded separately
mature  = sc.read_mtx('output_dir/counts_unfiltered/cells_x_genes.mature.mtx')
nascent = sc.read_mtx('output_dir/counts_unfiltered/cells_x_genes.nascent.mtx')

# For RNA velocity, stash both as layers of one AnnData
import anndata
adata = anndata.AnnData(
    X      = mature.X,
    layers = {'spliced': mature.X, 'unspliced': nascent.X},
    obs    = mature.obs,
    var    = mature.var,
)
# Then pass to scVelo (see scvelo protocol)

For snRNA-seq (no velocity, just better gene counts), sum spliced + unspliced before downstream — nuclei reads come from both.

Multi-Sample Batch Processing

# Create a batch file: SAMPLE_ID<TAB>R1_PATH<TAB>R2_PATH per row
cat > samples.txt <<EOF
sample1	/data/s1_R1.fastq.gz	/data/s1_R2.fastq.gz
sample2	/data/s2_R1.fastq.gz	/data/s2_R2.fastq.gz
sample3	/data/s3_R1.fastq.gz	/data/s3_R2.fastq.gz
EOF

# Run all samples in one kb count call — preserves sample identity
kb count -i index.idx -g t2g.txt -x 10xv3 -o multi_out --h5ad \
    --batch-barcodes \
    --tcc \
    batch.txt

Each cell's barcode gets prefixed with its sample ID, so you can split later.

Key Parameters to Adjust

`kb ref`

`kb count`

Memory considerations

Best Practices

Common Pitfalls

End-to-End Template

assets/kallisto_template.sh — single parameterized script. Edit FASTQ paths, technology, and reference paths, then run end-to-end ref → count → handoff message.

Convenience Scripts

For downstream analysis, switch to one of:

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.