Work with releases and repertoires#
Current annotation CLI#
vdjmatch annotate is the current cohort entry point. Its default
vX scorer uses the curated reference population and retains exact evidence.
Choose --reference-population all-valid for the uncurated reference,
and select --score-model kernel to replay a previous kernel result.
See Annotate single and paired receptors and Examples for reproducible offline commands.
Use --vdjdb reference.tsv to score a VDJdb-format custom table with
peptide–MHC labels. Supply receptor species, chain, junction and V gene.
For paired evidence, use the same nonzero complex_id on the two
reference chain rows of each observed pair.
To compute complete-score tails from one raw control, run:
vdjmatch annotate sample.tsv --vdjdb reference.zip --control control.tsv --threads 4 -o calibrated
This selects the combined candidate score and produces four flat TSVs. See Directional calibration with one control for control eligibility, paired routing and interpretation. For calibrated vX calls, use a matched bank as described in The VDJmatch annotation score.
Legacy Annotator API: choose a reference#
The following Annotator examples describe the retained candidate/E-value API,
which uses fixed-scope matching. Use annotate_repertoires for the vX
batch workflow.
from vdjmatch import Annotator
latest = Annotator.latest(asset="default", cache="reference-inputs")
pinned = Annotator.version("YOUR_RELEASE_TAG", cache="reference-inputs")
local = Annotator.from_path("reference.zip", asset="default")
extracted = Annotator.from_path("reference-directory", asset="primary")
table = Annotator.from_path("reference.tsv")
Local paths resolve without downloading a release. Supported inputs include legacy tables, release ZIPs and extracted directories, rich records/chains bundles, and AIRR Rearrangement/Reactivity bundles. Bundle manifests and schema metadata identify the appropriate assets and joins. Incomplete or incompatible inputs raise an error rather than silently choosing a different reference.
default selects the release’s default supported representation. primary,
legacy and airr select bundle roles when provided; slim and full
select the corresponding legacy projections. Request a representation that the
chosen release supplies. A new bundle supported by the resolver is not necessarily
available in the latest public release.
Species-filtered annotation requires receptor species metadata. Some VDJdb AIRR exports omit it; use the primary or legacy bundle for those builds. The loader retains missing species and rejects a species filter rather than inferring receptor species from antigen or MHC metadata.
Reference rows with an invalid amino-acid junction are retained with
reference_valid=False and excluded from the search index. The reference report
states retained/excluded counts. Inspect that report when assessing reference coverage.
The legacy Annotator API reference curation excludes KLGGALQAK and the engineered phage-library study
PMID 40498839 from search and background populations. Source rows remain available
with reference_exclusion_reason; natural SLLMWITQV observations from other
studies remain searchable. This legacy policy uses peptide/study identity, never a
sequence-frequency or motif filter on natural receptors. The current annotate CLI uses the same source-curation policy by default.
An HF mirror is selected explicitly with source="hf"; it is distinct from the
GitHub latest/pinned release source. Reuse an Annotator to keep one explicit
reference index across calls.
Filter a reference before indexing#
db.load and Annotator.from_path accept epitope, mhc_a, mhc_b and
reference_id as a string or list of strings. Values within a selector are
alternatives; different selectors must all match. exclude_reference_ids
removes specified studies while retaining rows without a study identifier.
restricted = Annotator.from_path(
"reference.zip", epitope=["GILGFVFTL", "NLVPMVATV"],
mhc_a="HLA-A*02:01", exclude_reference_ids=["study-to-exclude"],
)
evidence_type selects records with any attached evidence observation of a
requested type, retaining every selected source chain and its complete evidence
metadata. It accepts the same string/list convention. For a rich release, for
example, evidence_type="structure_native" requires that type in the attached
evidence. A requested evidence predicate raises when the reference does not supply
an evidence_type field; it never silently ignores an unavailable predicate.
These selectors retain source order and do not deduplicate reference observations.
Read AIRR and custom tables#
from vdjmatch.io import read_rearrangement
queries, report = read_rearrangement(
"repertoire.tsv.gz", source="airr", return_report=True,
)
calls = local.annotate(queries, threads=4)
AIRR junction_aa includes the conserved anchors and is preferred even when
cdr3_aa is also present. AIRR cdr3_aa excludes them; a true AIRR table that
has only that field is rejected. The reader never fabricates anchors.
Legacy VDJdb cdr3 and legacy producer cdr3_aa can already mean a junction.
For an ambiguous custom table, state the convention:
queries = read_rearrangement(
"custom.csv.gz", source="custom", sequence_convention="junction",
)
Both plain and gzipped CSV/TSV tables are supported. Standard repertoire formats
use published vdjtools readers. If a converter collapses or removes source rows
so that original identities cannot be preserved, ingestion raises explicitly.
By default, retained source rows keep their order, query_id, supplied
sequence_id, V/J calls, counts and pairing linkage. Missing or invalid sequences
are counted in the optional report. A supplied count must be a nonnegative integer;
malformed, missing, negative and fractional counts raise an error.
To deliberately collapse matching keys, pass dedup=True. The key includes
junction, V, J, locus and pair linkage; counts are summed, and query_ids and
sequence_ids retain the contributing source identities. This is a different
counting unit from the original row table.
Pair chains by a cell identifier#
from vdjmatch.io import read_cell
cells, report = read_cell(
"cell-rearrangements.tsv", link="cell_id", return_report=True,
)
calls = local.annotate_paired(cells, cdr3a="cdr3a", cdr3b="cdr3b", threads=4)
link can name a custom source column. Every retained chain must have a linkage
value and a TRA/TRB locus. Multiple retained alpha or beta rows for a cell raise by
default. ambiguity="first" explicitly selects the first row in source order.
Missing chains have typed null columns and a descriptive ingestion pair_status.
Paired annotation requires both chains to match the same reference complex with the same peptide–MHC identity. Agreement between two independent chain labels does not establish this paired-reference evidence. Request paired calibration explicitly:
calls = local.annotate_paired(
cells, cdr3a="cdr3a", cdr3b="cdr3b", calibrate=True,
species="human", threads=4,
)
For user-supplied paired controls, pass control={"TRA": alpha_index,
"TRB": beta_index}; both indexes are required. The returned calibration label
paired_independent_fixed_ball states the independent-chain background assumption.
Supply a background explicitly#
from seqtree import Index
controls = {"TRB": Index.build(["CWWWWF", "CYYYYF"], alphabet="aa")}
candidates = local.candidates(queries, control=controls, threads=4)
This tiny background illustrates the interface; use an appropriate versioned
background for an application. The API uses uncalibrated ranking unless
calibrate=True or a control index is supplied. A locus-to-index mapping allows
separate alpha and beta backgrounds. Empty backgrounds and requested background
loading failures raise errors.
Hard V/J matching uses match_v=True or match_j=True. Calibration with
these restrictions requires a gene-labelled control frame (cdr3, v,
j), or a locus-to-frame mapping, so target and control counts apply the
same allele-pooled predicate. Sequence-only control indexes cannot calibrate
these restrictions.
Legacy matching command line#
vdjmatch update --asset default --cache reference-inputs
vdjmatch match --vdjdb reference.zip --input-format airr --threads 4 \
--no-evalue -o results/run repertoire.tsv
vdjmatch match --vdjdb reference-directory --asset primary \
--input-format custom --sequence-convention junction --no-evalue \
-o results/custom custom.csv.gz
vdjmatch match --vdjdb reference.zip --paired --link cell_id \
--input-format airr -o results/cells cell-rearrangements.tsv
For VDJdb references, CLI matching requests background calibration by default.
Use --no-evalue for uncalibrated ranking. Direct label references default
to uncalibrated ranking. The command writes detailed hits, all candidates, calls,
descriptive count summaries, ingestion counts and a manifest. See Command-line interface for
options and Read scores and decide whether to call a match before interpreting the summaries.
Run a reproducible CLI comparison#
Use Examples for offline raw-input scripts and Notebooks for
worked examples. The comparison reruns vX with and without
--exclude-exact against one fixed reference. Join the output on the
source query identities. Choose a new output directory for each run.
Choose a practical thread budget#
The examples request --threads 4; ordinary CLI commands and repertoire
annotation default to 0, resolved once to the job CPU allocation.
Use --threads 1 for serial execution.
Use a smaller explicit budget when the process CPU allocation is below four.
Sequence search is internally batched: samples run sequentially and no outer
pool wraps the native engine. See Thread budgets and recorded laptop measurements for one/four-thread equality,
measured occupied cores and whole-invocation RAM on the worked examples.
Hugging Face input identity#
vdjmatch.db.fetch_hf and the precursor table loaders pin the default mirror
to a fixed repository commit. A dated VDJdb directory selects the database version;
revision= selects the HF repository snapshot. Custom mirrors default to
main unless a revision is supplied explicitly. Downloads and their validated
copies honor the caller-selected cache directory. For an offline job, pre-stage
inputs once, then pass the local reference or table paths to downstream jobs.
The versioned public asset mirror
contains synthetic examples, static model resources and a checksum manifest.
Recombination models remain owned by vdjtools.model.load_bundled.
Choose a repertoire enrichment workflow#
Read Repertoire enrichment: algorithm and parameter choices before choosing matching and aggregation.
Use repertoire-exact for the historical bulk reproduction, and
repertoire-enrichment --null reference for the fixed-sample/mock-reference
question. A paired Hamming1 chain-test export can be requested as follows:
vdjmatch repertoire-enrichment samples.tsv --null reference \
--vdjdb reference.tsv.gz --locus paired \
--control trb-control.tsv.gz --control-tra tra-control.tsv.gz \
--model-source isalgo --pgen-mismatches 0 --mock-policy pgen \
--chain-mode all --mismatches 1 --mock-replicates 200 --seed 42 \
--significance both --nominal-alpha 0.05 --fdr-alpha 0.1 \
--fdr-family cohort --threads 4 --output-prefix fresh-run
This example requests exact V and leaves optional J equality disabled. The metadata table names one raw sample file per row; paired chains retain a shared receptor identity and identical cell abundance. Use a fresh output prefix. Choose the thread budget for the allocated machine; four threads here are an example budget, not a performance recommendation for a forty-core allocation. Inspect TRA/TRB P-values, excess and nominal/BH decisions separately; retain all four reducers to explain counts, pairing and orphan support. Do not interpret union/intersection P-values as calibrated exposure probabilities.