vdjtools#

Immune-repertoire analysis for T- and B-cell receptor sequencing: read any format, measure diversity and overlap, correct batch effects, score generation probability against a native V(D)J model, and reduce a whole repertoire to one comparable feature vector.

vdjtools is a Python library and a command-line tool. It reads the output of every common repertoire pipeline into one canonical AIRR table backed by polars. Repertoire analyses consume that schema and return Polars result tables, so results feed into the next step without a format converter.

Get started

Install, load a real sample, and get your first diversity and overlap numbers. Start here if you have not used vdjtools before.

Getting started
Guides

Guides by task: loading data, pre-processing, diversity, overlap, dynamics, biomarkers, single cell, and the recombination model workshop.

User guide
Raw features and PCA

Export diversity, isotype and usage features, then fit or reuse a sample rotation.

Raw features and sample PCA
Command reference

Every command and every flag, with the defaults. No Python needed.

Command reference
Python API

Every module, class and function, with signatures and types.

API reference
Worked examples

Fifteen runnable notebooks, several reproducing a published result — repertoire ageing, CMV and HLA association, vaccination time courses, single-cell pairing.

Worked examples
Glossary

Every term this documentation uses, and which convention vdjtools follows where the field disagrees — junction against CDR3, productive against functional.

Glossary

Install#

pip install vdjtools

That is the whole installation. Wheels are prebuilt for CPython 3.10-3.13 on Linux, macOS (Apple Silicon) and Windows, with the native C++ extension included; a source install compiles it.

Core repertoire analytics and the model engine work from that one command. Single-cell bridges and interactive examples use the extras below. The three engines vdjtools delegates to are base dependencies, imported lazily so that import vdjtools stays light:

Engine

Powers

arda

the germline reference (V/D/J segments and CDR3 anchors), the model engine, annotation

seqtree

fuzzy search and e-values: error correction, similarity overlap, TCRnet

vdjmatch

sample overlap, TCRnet, metaclonotypes

Extras for optional workflows:

pip install "vdjtools[overlap]"   # scikit-learn, for cluster_samples(method="mds")
pip install "vdjtools[sc]"        # single-cell bridges: anndata, awkward, mudata, pyyaml
pip install "vdjtools[examples]"  # interactive marimo notebooks

MMseqs2 is needed only for arda’s alignment and annotation path, never for germline lookup, Pgen, generation or the analytics.

Your first result#

from vdjtools import io as vio, stats, overlap

sample = vio.read("clones.tsv")          # MiXcr, immunoSEQ, AIRR, Parquet -- detected
stats.diversity_stats(sample)            # richness, Chao1, Shannon, Simpson, d50
stats.segment_usage(sample, "v")         # V-gene usage

cohort = vio.read_samples(vio.read_metadata("metadata.txt"), base_dir="samples/")
overlap.overlap_matrix(cohort)           # pairwise repertoire overlap
vdjtools diversity     sampleA.tsv sampleB.tsv -o diversity.tsv
vdjtools segment-usage *.tsv --segment v -o usage.tsv
vdjtools overlap       *.tsv -o overlap.tsv

Every command writes to -o – TSV, or Parquet when the path ends in .parquet or .pq – or to stdout, so commands pipe. Getting started walks through this with a synthetic repertoire.

Choose your path#

You want to

Go to

Get a first result from a file you already have

Getting started

Clean, filter, downsample or batch-correct a cohort

Data pre-processing

Measure diversity, overlap, gene usage or spectratype

User guide

Score generation probability, or fit a model to your own reads

Recombination model workshop

Export raw statistical features and fit or reuse PCA

Raw features and sample PCA

Reduce each sample to one fixed feature vector for a classifier

Repertoire signatures

Work with 10x or single-cell data, or hand off to scirpy or dandelion

Single-cell

Look up a command, a flag or a function

Command reference | API reference

Understand a term used in these pages

Glossary

Performance#

Native Pgen, generation, EM and batched rarefaction kernels are reached through pybind11; the surrounding analytics use Python, NumPy and Polars. Engine comparisons use identical probability tables and raw germlines, with a strict relative tolerance and zero absolute tolerance. Imported germline repairs and an OLGA insertion-workspace boundary can change comparisons with unmodified OLGA; see Known quirks of the OLGA models.

Earlier single-thread measurements, Apple M3, bundled human TRB model. The generation rows below use the reference sampler; --engine native selects the newer native sampler:

Operation

Throughput

Relative to OLGA

Nucleotide Pgen, single-D VDJ

0.5 ms per sequence

9x

Amino-acid Pgen

0.6-0.9 ms per sequence

8.6x

Amino-acid Pgen over the Hamming-1 ball

15 ms per sequence

8.7x

Sequence generation, raw draws

32,100 per second

not applicable

Sequence generation, productive_only=True

8,960 per second

not applicable

The productive filter costs 3.6x on TRB and 5.1x on IGH (19,900 raw draws per second against 3,930 productive), because out-of-frame and stop-codon draws are discarded and redrawn rather than repaired. Quote whichever of the two your pipeline uses.

Earlier batched Pgen measurements over many junctions showed sequence parallelism (pgen_aa_batch(), 11x on 16 cores, and identical to the serial result to the last bit); the EM E-step parallelises over reads (6.7x on 8 threads). Memory stays modest: 63 MB resident for import vdjtools plus one model, 123 MB with all seven bundled models loaded.

Release 5.3.0 comparisons on a 16-core Apple Silicon host also include OLGA’s warmed FastPgen path. Across seven loci, three-repeat single-core medians favored native scoring in all 56 tested conditions: short and long amino-acid junctions with exact or Hamming-1 scoring, and short and long nucleotide junctions with marginal or V/J-conditioned scoring. Short amino-acid batches contained 64 queries per locus (1.71–21.69x faster); short nucleotide batches contained 16 queries per locus (1.23–167.11x faster). These are batch timing ratios on the tested inputs, not a guarantee for every query or machine. Each workload drew 192 productive junctions per locus from unchanged OLGA model parameters and selected short or long queries; timings exclude JIT warmup.

On fresh streams of 2,048 junctions per locus, native amino-acid scoring at 16 threads was 6.47–10.35x faster than one thread for exact scoring and 9.46–10.82x for Hamming-1 scoring, with bit-identical outputs at every tested budget (1, 2, 4, 8 and 16). File-backed cohort operations also depend on I/O and process startup; see User guide for choosing the sample-map backend and keeping inner kernels serial.

Citing#

For the v2 rewrite, cite this repository. For the original tool, cite Shugay et al., PLoS Computational Biology 2015. The VDJtrack recapture model in vdjtools.dynamics is Pavlova, Zvyagin and Shugay (2024).

Licensed ISALGO LAB Academic and Non-Commercial Research License. The legacy Groovy/Java v1.x tool lives on the legacy-1.x branch, with its releases under the repository tags v0.0.1 through 1.2.1.

Choose a documentation path#

vdjtools workflow overview: inputs, processing and outputs. vdjtools workflow overview: inputs, processing and outputs.