Marginal junction generation probability#

The pgen command computes the amino-acid generation probability of each full, anchor-inclusive AIRR junction_aa under an explicitly selected raw vdjtools model directory:

vdjmatch pgen input.airr.tsv --model-path /path/to/raw/model \
    --species human --locus TRA --threads 12 --output-prefix result

Use a model whose manifest matches the declared species and locus. The command loads and validates that directory directly; it neither selects a bundled model implicitly nor collapses its alleles. vdjtools.load_model applies its documented anchor repairs. The manifest records the consumed model-file hashes, model metadata, loader and native binary hashes, options, input hash, row dispositions and timing. No model download or new model fitting occurs.

This is marginal P(junction_aa): all V/J alleles and recombination scenarios in the model contribute. The default --mismatches 0 uses exact amino-acid identity; --mismatches 1 sums the inclusive Hamming ball (same length, at most one substitution, no indels). All junction positions, including anchors, enter this calculation. Input V/J annotations are preserved but do not condition the probability. This is neither an antigen specificity probability nor a probability calibrated from the annotation score. The model’s generative mass does not include post-recombination selection merely because the input repertoire was observed or productive. Paired input remains one result per chain row; the command does not infer a joint pair probability.

result.scores.tsv preserves all raw rows, metadata and supplied unique, non-null query_id values. If absent, query_id is the zero-based raw row ordinal. junction_aa_normalized records uppercase, whitespace-stripped input; anchors are never fabricated from bare cdr3_aa. Canonical amino-acid junctions of the selected species/locus are deduplicated and sent to one native batch, then joined back to every input observation. Missing locus metadata uses the explicit --locus; missing V/J calls do not prevent marginal Pgen. Explicitly different species/loci, missing junctions and noncanonical sequences remain in the table with an explanatory status and null probabilities.

pgen is the marginal probability and log10_pgen is its base-10 logarithm when positive. available is true for a valid numeric result, including zero. zero_mass records a returned zero, with null logarithm; it does not distinguish impossible model mass from numerical underflow. Negative, nonfinite or greater-than-one native probabilities fail the command instead of being clipped or exported. result.manifest.json records the exact computation contract. Positive --threads caps native workers and the CLI’s table-thread budget; no outer worker pool or computed-intermediate cache is used.

VDJdb reference observations#

Use --vdjdb to read a frozen local legacy or rich reference ZIP through the same database loader used for annotation:

vdjmatch pgen reference.zip --vdjdb --model-path /path/to/raw/model \
    --species human --locus TRA --threads 12 --output-prefix reference-tra

The loader selects the declared receptor species and locus. Every normalized reference observation in that selection is retained, including repeated junctions and its reference_id, peptide, MHC and other metadata. The command projects internal cdr3/v/j/gene fields to junction_aa/v_call/j_call/locus without renaming or dropping the original columns. Legacy VDJdb cdr3 is a full anchor-inclusive junction under the database loader’s source contract. Nested rich metadata is exported as JSON cells using the existing flat-table exporter. query_id is the selected loader row ordinal when not supplied.

The manifest declares input_format=vdjdb and records db.provenance together with the reference loader/normalizer hashes. Row counts refer to the selected normalized reference observations, rather than all records in the archive. Pgen remains marginal over the model’s V/J alleles; database V/J annotations, epitopes and study metadata do not condition it. Local reference tables and release directories are also supported by the existing loader. AIRR remains the default when --vdjdb is absent.

Reusable junction features#

To compute the reference/control union once, supply a native vdjtools control AA table. Its legacy cdr3aa contains the conserved anchors:

vdjmatch pgen reference.zip --vdjdb --control control.aa.vdjtools.tsv.gz \
    --model-path /path/to/raw/model --species human --locus TRB \
    --mismatches 1 --threads 12 --output-prefix human-trb

The additional human-trb.features.parquet contains one row per distinct canonical junction in that population, with junction_aa, pgen, species and locus. The manifest records the control input hash, excluded noncanonical row count and feature-table hash. Control read counts and AA incidence do not weight the generative mass. Shared TRA/TRD V genes and contradictory V/J calls do not remove canonical AA keys; conflicting gene rows are counted in the manifest. Other-chain first V/J calls in pooled AA data are also counted, without rejecting the sequence keys. The feature-table species/locus identify the selected generative model; they do not reassign observed receptors to a chain. Downstream observed controls retain their separate raw NT/V/J normalization and chain selection. scores.tsv still retains every selected reference observation and its full pMHC metadata. Models remain separate by species and chain. The requested feature table is a versioned input to subsequent diagnostics; those consumers validate it against its companion manifest. Use --features-only to write the feature table and manifest without a row-wise score table, either for the input alone or for its union with --control.