tcr-pmhc-analyzer
Analyzer for TCR-pMHC binding predictor outputs. Merges predictions from multiple models into a unified table, detects data leakage against each model's training set (downloaded from the authors' repositories on first use), identifies seen/unseen peptides, and benchmarks model performance via ROC curves.
Installation
pip install tcr-pmhc-analyzer
For development:
git clone https://github.com/qbic-pipelines/tcr-pmhc-analyzer.git
cd tcr-pmhc-analyzer
pip install -e ".[dev]"
python -m pytest tests/ # full suite; downloads the training data
python -m pytest tests/ -m "not gated_data" # what CI runs: skips tests needing licence-gated data
Tests marked gated_data use the NetTCR, MixTCRpred, TCRen or TABR-BERT training data, whose licences do not allow downloading it on public CI runners.
Input format
create-analyzer-table and benchmark --input accept a TSV configuration file with two required columns (model, file) and one optional column (training_data):
| Column | Required | Description |
|---|---|---|
model |
Yes | Name of the prediction model |
file |
Yes | Path to the model's prediction output |
training_data |
No | Path to a training-data file, used for leakage and seen-peptide detection. Required for every custom (non-built-in) model row. Ignored on built-in rows, which always use their built-in training data (see Training data). Omit the column when you use only built-in models. See Custom models. |
Example input.tsv:
model file
ergo2 results/ergo2_predictions.csv
mixtcrpred results/mixtcrpred_predictions.csv
mixtcrpred-pan results/mixtcrpred_pan_predictions.csv
t2pmhc-gcn results/t2pmhc_gcn_predictions.csv
Each prediction file must contain the following columns:
| Column | Description |
|---|---|
identifier |
Unique sample identifier (used for merging) |
binding_score |
Model's predicted binding score |
binder |
Ground truth label (0/1), required for benchmarking |
peptide_sequence_aa |
Peptide sequence |
junction_aa_tra |
CDR3 alpha chain sequence |
junction_aa_trb |
CDR3 beta chain sequence |
v_call_tra, v_call_trb |
V gene alpha/beta |
j_call_tra, j_call_trb |
J gene alpha/beta |
mhc_allele_1 |
MHC allele |
species |
Source species |
mhc_class |
MHC class |
Commands
create-analyzer-table
Merges predictions from multiple models into a single table with data leakage annotations and seen-peptide flags.
tcr-pmhc-analyzer create-analyzer-table [OPTIONS]
| Option | Short | Required | Description |
|---|---|---|---|
--input PATH |
-i |
Yes | Path to TSV config file with model and file columns |
--output PATH |
-o |
Yes | Output file path (.csv or .tsv) |
--ergo-version |
If ergo2 | ERGO training data version: vdjdb, mcpas, or both |
|
--strict-leakage |
No | Stop with an error when a leakage check is skipped. Default: log a warning. See --strict-leakage. |
|
--training-data-dir DIR |
No | Directory of raw upstream training files (see fetch-training-data). The command verifies each file by sha256 and downloads nothing. Default: download on first use into the cache. See Training data. |
|
--accept-nettcr-license |
For nettcr-* |
Confirm the NetTCR-2.2 licence. | |
--accept-mixtcrpred-license |
For mixtcrpred and mixtcrpred-pan |
Confirm the MixTCRpred licence. | |
--accept-tcren-license |
For tcren |
Confirm the TCRen licence. | |
--accept-tabr-bert-license |
For tabr-bert |
Confirm the TABR-BERT licence. |
Each --accept-*-license flag confirms that you have read the licence and that your use complies. See Licence acceptance.
Example:
tcr-pmhc-analyzer create-analyzer-table \
-i input.tsv \
-o analyzer_table.csv \
--ergo-version vdjdb
Output columns added:
binding_score_{model}: raw binding score per modelsample_in_train_{model}:Trueif a training row of the model matches the sample (data leakage).Falseif the sample was checked and no training row matches. Empty if the sample could not be checked. Empty does not mean clean. See Data leakage detectionseen_in_{model}:Trueif the peptide was seen in the model's training data
The command prints a leakage summary with three counts per model. The percentage is the share of flagged rows among the checked rows:
sample_in_train_m: 1 flagged, 1 clean, 1 unchecked (50.0% of the 2 checked rows flagged)
When no row was checked, the brackets read (no row was checked) instead of a percentage.
benchmark
Generates ROC curve plots comparing model performance, split by seen vs unseen peptides. Samples that are flagged or unchecked for data leakage are removed from the leakage-removed curves.
tcr-pmhc-analyzer benchmark [OPTIONS]
| Option | Short | Required | Description |
|---|---|---|---|
--input PATH |
-i |
* | Path to TSV config file with model and file columns |
--table PATH |
* | Path to a pre-created analyzer table (alternative to --input) |
|
--output PATH |
-o |
Yes | Output directory for ROC curve plots |
--ergo-version |
If ergo2 | ERGO training data version: vdjdb, mcpas, or both |
|
--models |
-m |
No | Space-separated list of models to benchmark (default: all available) |
--strict-leakage |
No | Stop with an error when a leakage check is skipped. With --table, an empty sample_in_train_{model} cell is an unchecked row. The check runs before any plot. See --strict-leakage. |
|
--training-data-dir DIR |
No (only with --input) |
As for create-analyzer-table. |
|
--accept-nettcr-license |
For nettcr-* with --input |
As for create-analyzer-table. |
|
--accept-mixtcrpred-license |
For mixtcrpred and mixtcrpred-pan with --input |
As for create-analyzer-table. |
|
--accept-tcren-license |
For tcren with --input |
As for create-analyzer-table. |
|
--accept-tabr-bert-license |
For tabr-bert with --input |
As for create-analyzer-table. |
* Either --input or --table must be provided.
Examples:
# Benchmark from raw predictions
tcr-pmhc-analyzer benchmark -i input.tsv -o results/
# Benchmark from a pre-created analyzer table
tcr-pmhc-analyzer benchmark --table analyzer_table.csv -o results/
# Benchmark specific models only
tcr-pmhc-analyzer benchmark -i input.tsv -o results/ -m "ergo2 mixtcrpred tabr-bert"
Leakage in the benchmark. Every leakage-removed curve drops the flagged rows (True) and the unchecked rows (empty) of the model. An unchecked row could be a leak, so the clean curve must not keep it. The log reports both counts per model. A model whose whole sample_in_train_{model} column is empty has no curve in the leakage-removed regimes. The other models keep their curves. The model stays in entire_dataset/ and seen_unseen/. See Data leakage detection.
Output files: the command writes ROC and PR curves for four regimes. Each regime has its own subdirectory of --output. Files carry the prefix ROC_ or PR_.
| Subdirectory | Files | Samples in the curve |
|---|---|---|
entire_dataset/ |
ROC_curve.png, PR_curve.png |
All samples. No leakage removal. Seen and unseen peptides are mixed. |
seen_unseen/ |
ROC_curve_seen.png, ROC_curve_unseen.png, and the PR_ pair |
Each model on the peptides it has seen or not seen. No leakage removal. |
seen_unseen_no_leakage/ |
the same four file names | As seen_unseen/. Each model also drops its own flagged and unchecked rows. A model that cannot be checked has no curve. |
shared_seen_unseen/ |
the same four file names | One shared sample set for all models. The peptide must be seen (or unseen) by all models. Flagged and unchecked rows of any model are dropped. |
The "leakage-removed" regimes are seen_unseen_no_leakage/ and shared_seen_unseen/.
fetch-training-data
Downloads and verifies the raw upstream training files of the built-in models. Optional: create-analyzer-table and benchmark --input download missing files themselves. Use it to pre-fill the cache, or to fill a directory for an offline machine and pass that directory with --training-data-dir.
tcr-pmhc-analyzer fetch-training-data [OPTIONS]
| Option | Short | Required | Description |
|---|---|---|---|
--dir DIR |
No | Directory to fill with the raw upstream files (default: the cache, see Training data) | |
--models |
-m |
No | Space-separated list of built-in models; ergo2 fetches both ERGO-II variants. Default: every model whose licence needs no flag, plus every licence-gated model whose flag is set. The command lists skipped gated models with the flag they need. |
--accept-nettcr-license |
For nettcr-* |
As for create-analyzer-table. |
|
--accept-mixtcrpred-license |
For mixtcrpred and mixtcrpred-pan |
As for create-analyzer-table. |
|
--accept-tcren-license |
For tcren |
As for create-analyzer-table. |
|
--accept-tabr-bert-license |
For tabr-bert |
As for create-analyzer-table. |
The command does not download files that are already present with the right sha256. It ends by printing the --training-data-dir argument to use.
Example (offline machine):
# On a machine with network access
tcr-pmhc-analyzer fetch-training-data --dir tcr_training_data --accept-nettcr-license
# Copy tcr_training_data/ to the offline machine, then
tcr-pmhc-analyzer create-analyzer-table -i input.tsv -o table.csv \
--training-data-dir tcr_training_data --accept-nettcr-license
create-dashboard
Builds one self-contained, offline interactive HTML dashboard from a directory of analyzer tables. Each .csv or .tsv file in the directory becomes one selectable dataset. The browser recomputes everything live. The dashboard offers:
- a model toggle and filter regimes
- a dataset overview: positive, negative and peptide counts, split into seen and unseen
- per-model ROC and per-peptide AUC
- a dataset composition & filtering section: positive/negative and leakage-removed rows per peptide, and a peptide-attrition funnel
The HTML inlines Plotly and the full tables. It makes no external requests (no CDN) and works air-gapped.
tcr-pmhc-analyzer create-dashboard [OPTIONS]
| Option | Short | Required | Description |
|---|---|---|---|
--analyzer_dir PATH |
Yes | Directory of analyzer-table files (*.csv / *.tsv); one dataset per file |
|
--dashboard_path PATH |
No | Output HTML file path (default: dashboard.html) |
|
--models |
-m |
No | Space-separated models to include (default: every model with data on any dataset) |
--colors |
No | Per-model color overrides as space-separated model=hex pairs (e.g. 'ergo2=#123456') |
The command reads the analyzer tables that create-analyzer-table produces. It uses the binding_score_{model}, sample_in_train_{model} and seen_in_{model} columns.
- Custom and arbitrarily named models work. The command detects the model set across all files and gives unknown names fallback colors.
- A dataset with no results for a model omits that model from its plots.
- A file named
<id>_analyzer_table.tsv(as the upstreamtcrpmhcbindingpipeline emits it) appears in the dropdown as<id>. - A row with an empty
sample_in_train_{model}flag shows asNot checked. The dashboard excludes that row from the leakage-removed regimes. It leaves a model with no checked row out of those regimes.
Examples:
# Build a dashboard from every analyzer table in a directory
tcr-pmhc-analyzer create-dashboard --analyzer_dir analyzer_tables/ --dashboard_path dashboard.html
# Restrict to specific models
tcr-pmhc-analyzer create-dashboard --analyzer_dir analyzer_tables/ -m "ergo2 mixtcrpred"
Note: each
dashboard.htmlinlinesplotly.min.js(~4.85 MB) plus the full tables as JSON, so expect multi-megabyte output that grows with dataset size.
Licence acceptance
The training data of some models comes from tools under restrictive licences. When you download and use it, you are subject to those licences. Each licence restricts use, generally to academic, non-commercial or non-profit use. Read the licence of each model you want to analyse. Then set its flag to confirm that you have read it and that your use complies. Without the flag, the command fails before it reads or downloads any file and lists every missing flag.
| Model | Flag | Licence |
|---|---|---|
nettcr-pan, nettcr-peptide |
--accept-nettcr-license |
DTU Health Tech Academic Software License Agreement, at the pinned commit |
mixtcrpred, mixtcrpred-pan |
--accept-mixtcrpred-license |
MixTCRpred licence, at the pinned commit. Commercial applications require buying the MixTCRpred licence. |
tcren |
--accept-tcren-license |
TCRen licence, at the pinned commit: educational, research and non-profit use by non-profit institutions only. |
tabr-bert |
--accept-tabr-bert-license |
TABR-BERT licence, at the pinned commit |
The flags apply to create-analyzer-table, benchmark --input and fetch-training-data, the commands that download or load training data. benchmark --table and create-dashboard read an existing analyzer table and need no flag. Other models and custom models need no flag.
The package ships the full text of every licence in src/tcr_pmhc_analyzer/data/licenses/.
Cite every model you use, see Citations. In particular, you must cite NetTCR-2.2 when using the nettcr-* models. After the licences are accepted, the command prints the citation of every licence-gated tool it used.
tcr-pmhc-analyzer create-analyzer-table -i input.tsv -o analyzer_table.csv \
--accept-nettcr-license --accept-tcren-license
Supported models
| Model | Training data |
|---|---|
ergo2 |
mcpas or vdjdb (specify with --ergo-version vdjdb|mcpas) |
ergo2-vdjdb |
vdjdb (use with --ergo-version both, alongside ergo2-mcpas) |
ergo2-mcpas |
mcpas (use with --ergo-version both, alongside ergo2-vdjdb) |
mixtcrpred |
146 pMHC training set |
mixtcrpred-pan |
146 pMHC training set (shares mixtcrpred's training set and --accept-mixtcrpred-license; single pan-epitope checkpoint instead of 146 epitope-specific models) |
t2pmhc-gcn |
t2pmhc core training set |
t2pmhc-gat |
t2pmhc core training set |
tabr-bert |
TCR-pMHC training set |
tulip-tcr |
TULIP training set |
atm-tcr |
ATM-TCR training set |
nettcr-peptide |
NetTCR-2.2 training set (peptide-specific strategy) |
nettcr-pan |
NetTCR-2.2 training set (pan-specific strategy) |
tcren |
TCRen PDB-based structural training set |
stag-llm |
STAG-LLM structural training set (final_dataset_modeled.csv) |
Note on score direction. Most models output
binding_scoresuch that higher = more likely binder.tcrenis the exception: lower (more negative) score = more likely binder. The analyzer table holdsbinding_score_{model}exactly as the model reported it, sobinding_score_tcrenstays inverted there. Both consumers correct for it in memory.benchmarknegates the scores before it computes ROC and PR curves.create-dashboardnegates them when it serializes the table into the HTML. AUC and AUPRC are therefore directly comparable across all models. Code that reads the table itself must account for the direction.
Note on the
stag-llmtraining set. STAG-LLM trains in two stages. First, a self-supervised ESM-2 masked-language-model pretraining on a large sequence-only corpus (full_seq_df_new.csv, binders only, no labels). Second, the supervised binding classifier (the deployed checkpoint), trained with labels only on the structurally modeled set (final_dataset_modeled.csv, 46,201 pairs). Thestag-llmtraining data is that supervised structural set, because it holds the labeled pairs that the model actually learned. The analyzer treats the MLM pretraining corpus like ESM-2's own pretraining and does not count it as label leakage. To experiment with the full sequence corpus, add a row under a distinct model name (e.g.stag-llm-mlm) withtraining_datapointing at that file, see Custom models. Settingtraining_dataon thestag-llmrow itself has no effect: the samplesheet override is only read for custom models.
ERGO-II "both" variant mode
The upstream tcrpmhcbinding Nextflow pipeline can run ERGO-II against both training-database variants (vdjdb and mcpas) in one run with --ergo2_variant both. The pipeline then emits two prediction columns, ergo2-vdjdb and ergo2-mcpas, instead of the single ergo2 column.
When you pass that predictions TSV to this tool, use --ergo-version both:
tcr-pmhc-analyzer create-analyzer-table \
-i input.tsv \
-o analyzer_table.csv \
--ergo-version both
Each ERGO column is checked against its own training set:
sample_in_train_ergo2-vdjdbandseen_in_ergo2-vdjdbuse the vdjdb training data.sample_in_train_ergo2-mcpasandseen_in_ergo2-mcpasuse the mcpas training data.
--ergo-version both requires the input config to contain both ergo2-vdjdb and ergo2-mcpas model rows. Single-variant inputs continue to use --ergo-version vdjdb or --ergo-version mcpas with the legacy ergo2 model name. That path is unchanged.
Training data
Leakage and seen-peptide detection compare each prediction against the training set of each built-in model. The analyzer does not ship these training sets. On first use it downloads each model's raw training file from the authors' own repository at a pinned commit or tag. It verifies the file against a stored sha256 and converts it in memory to the column names that the analyzer uses. A file that fails its checksum is never used: the command stops with an error that names the file, its URL and the affected models.
| Model(s) | Upstream file (pinned) | Size | Conversion applied at runtime |
|---|---|---|---|
ergo2 (--ergo-version mcpas), ergo2-mcpas |
IdoSpringer/ERGO-II 85d320a, Samples/mcpas_train_samples.pickle |
5.4 MB | Pickle flattened to a table (loaded with an unpickler that refuses every class reference); UNK becomes empty; V/J/MHC cells garbled upstream with U+FFFD are kept; a garbled V/J cell is cut at U+FFFD and compared by gene family (TRBV06- + U+FFFD reads as TRBV6) or as a gene without allele, and only a garbled MHC cell (H-2Db + U+FFFD) is a wildcard |
ergo2 (--ergo-version vdjdb), ergo2-vdjdb |
same repository, Samples/vdjdb_train_samples.pickle |
12.5 MB | Pickle flattened to a table; UNK becomes empty |
mixtcrpred, mixtcrpred-pan |
GfellerLab/MixTCRpred tag v1.0, full_training_set_146pmhc.csv |
1.7 MB | Header renamed |
nettcr-peptide, nettcr-pan |
mnielLab/NetTCR-2.2 7cead3f, data/nettcr_2_2_limited_dataset.csv |
4.5 MB | Header renamed |
t2pmhc-gcn, t2pmhc-gat |
qbic-pipelines/t2pmhc tag v1.1.4, data/t2pmhc_train.tsv |
8.2 MB | None |
tabr-bert |
Freshwind-Bioinformatics/TABR-BERT d0fe4a7, data/train_tcr_pmhc.csv |
3.0 MB | Header renamed |
tulip-tcr |
barthelemymp/TULIP-TCR 798fab9, data/SeenPeptides.zip and data/UnseenPeptides.zip |
58.3 MB | Three CSVs from the two zips concatenated and deduplicated; <MIS> becomes empty |
atm-tcr |
Lee-CBG/ATM-TCR a1e02e1, data/combined_dataset.csv |
7.4 MB | Header line added |
tcren |
antigenomics/tcren cf1e1f0, data/summary_PDB_structures.csv |
18 KB | Header renamed |
stag-llm |
final_dataset_modeled.csv from the STAG-LLM Rice Box folder (unversioned, pinned by sha256 only) |
20.9 MB | Columns peptide, CDR3a, CDR3b kept and renamed |
The command downloads only the files of the models in your samplesheet.
Negatives count as seen. Several upstream files contain the negative (non-binding) pairs that the model trained on: ERGO-II, ATM-TCR, NetTCR-2.2, t2pmhc and STAG-LLM. The analyzer keeps them. A prediction that matches a training negative is flagged in sample_in_train_{model}, and its peptide counts in seen_in_{model}, because the model saw that pair during training.
Cache. The analyzer stores downloaded files unchanged in $TCR_PMHC_ANALYZER_CACHE if set, else $XDG_CACHE_HOME/tcr-pmhc-analyzer, else ~/.cache/tcr-pmhc-analyzer. It verifies each file on every use and downloads a corrupt cached file again once. A download goes to a temporary .part file and moves into place only after its checksum matches. Downloads time out after 60 s and are retried once.
Offline use. Run fetch-training-data --dir DIR on a machine with network access. Copy DIR, and pass --training-data-dir DIR to create-analyzer-table or benchmark. With --training-data-dir, nothing is downloaded: a missing file or a checksum mismatch is an error.
Library use. The CLI commands check the licence flags. Analyzer.read_training_data and tcr_pmhc_analyzer.training_data.load_training_source download without a licence check when you call them directly from Python. The licences under Licence acceptance still bind you.
Custom models
Any model name that is not in the Supported models table is a custom model. This section covers what is specific to custom models. For the matching rules, see Data leakage detection.
When you need a custom model
A model name in the samplesheet is a custom model when it is not in the Supported models table and is not ergo2, ergo2-vdjdb or ergo2-mcpas. The analyzer detects it automatically. No registration step exists.
A custom model gets the same treatment as a built-in one:
- It merges into the analyzer table on
identifier, like every other model. sample_in_train_{model}holds the data-leakage flag (True,False, or empty when the row could not be checked).seen_in_{model}holds the seen-peptide flag.benchmarkandcreate-dashboardsupport it fully.
You must supply one thing that built-in models get for free: a training-data file, in the training_data column.
Samplesheet
training_data is required for custom rows. It may be blank or omitted for built-in rows, so one samplesheet can mix both. Each custom row needs its own training_data entry. The number of custom rows has no limit.
model file training_data
ergo2 results/ergo2_predictions.csv
my_model_1 results/my_model_1_predictions.tsv training/model1_train.tsv
my_model_2 results/my_model_2_predictions.tsv training/model2_train.tsv
Missing
training_data. If thetraining_datacell of a custom model is missing, blank, or NaN,create-analyzer-tablefails immediately with:Custom model '{model}' requires a 'training_data' column with a valid file path in the input samplesheet.
training_dataon a built-in row is currently ignored.load_model_results()reads thetraining_datacell only when the row's model is custom. A path on a built-in row (e.g.ergo2) has no effect, and that model still uses its built-in training data with no warning. Use a distinct model name to force the custom path.
Prediction file
The file of a custom model must contain the same columns as every model, see the table under Input format. All of those columns are mandatory verbatim. The analyzer keeps only them and drops everything else, so extra columns are harmless. A missing column raises a raw pandas KeyError at load time.
Training-data file
Built-in models get their training data automatically (see Training data). A custom model must provide it here. The file feeds both sample_in_train_{model} (data leakage) and seen_in_{model} (seen-peptide) detection.
Format. The analyzer reads the file by extension: lowercase .csv (comma-separated) or .tsv (tab-separated) only.
Peptide column. seen_in_{model} needs a peptide_sequence_aa column.
Leakage match keys. A custom model uses the __custom__ row of src/tcr_pmhc_analyzer/data/leakage_keys.tsv. That row lists every candidate column. A column takes part in the match only when the prediction table and your training file both hold it. Both values must be usable (see Data leakage detection). The columns of your training file therefore decide the effective match rule:
| Columns your training file ships | Resulting match rule | Same as |
|---|---|---|
peptide_sequence_aa, junction_aa_tra, junction_aa_trb, v_call_tra, v_call_trb, j_call_tra, j_call_trb, mhc_allele_1 |
all eight columns | t2pmhc-gcn, t2pmhc-gat |
peptide_sequence_aa, junction_aa_trb, mhc_allele_1 (beta only) |
(peptide_sequence_aa, junction_aa_trb, mhc_allele_1) |
tabr-bert |
peptide_sequence_aa, junction_aa_tra, junction_aa_trb (no MHC) |
(peptide_sequence_aa, junction_aa_tra, junction_aa_trb) |
stag-llm |
peptide_sequence_aa, junction_aa_trb (beta only, no MHC) |
(peptide_sequence_aa, junction_aa_trb) |
atm-tcr |
peptide_sequence_aa, mhc_allele_1 only |
no anchor column: every row stays unchecked and sample_in_train_{model} is empty |
none |
The column mhc_class also takes part when both sides hold it. An absent optional column is dropped from the match without a warning. An empty value in a present column is a wildcard for that row.
A training file with no peptide_sequence_aa column leaves every row unchecked. So does a training file with none of the anchor columns that the prediction table holds. The anchor columns are junction_aa_tra, junction_aa_trb, anarcii_cdr3a and anarcii_cdr3b. A table written by create-analyzer-table holds only the two junctions, because it keeps the KEY_COLS columns and drops the rest. The warning names the column to rename. With --strict-leakage, the command stops instead.
Column names. The training file must use the AIRR names junction_aa_tra, junction_aa_trb, v_call_tra, v_call_trb, j_call_tra and j_call_trb. The matcher does not see a column with another name. Rename the columns before you set training_data.
No samplesheet equivalent for MODEL_MATCH_COLS. A custom model cannot pull anarcii_* columns out of its prediction file. The __custom__ key still matches on them when the table it is given already holds them. See Step 2.
Benchmarking and dashboards
benchmark and create-dashboard have no model allowlist and no registration step. Both discover models from binding_score_{model} columns (_get_available_models in benchmark.py). A custom model is therefore fully benchmarkable and appears in the dashboard next to the built-in models. create-dashboard gives it a fallback color unless you set one with --colors (see create-dashboard).
One ordering constraint exists. benchmark requires sample_in_train_{model} and seen_in_{model} in its input. Run create-analyzer-table first, or pass benchmark --table with its output.
Limitations
- Score direction is not configurable. The analyzer treats only the hardcoded
tcrenas lower-is-better (see the note on score direction). No samplesheet or CLI flag marks a custom model the same way. If the raw score of your model is lower-is-better, negate it before you feed it in. Otherwise the ROC/PR curves and the dashboard plots come out inverted. - A missing peptide column fails differently in the two checks. The leakage check leaves every row unchecked. The seen-peptide check raises a raw
KeyError: 'epitope'instead of a helpful message. - A wrong file extension fails confusingly. Only lowercase
.csvand.tsvare recognized. Any other extension returns a string instead of raising an error. This surfaces downstream as an unrelatedTypeErrororAttributeError. - A built-in model name is never custom. A model named like an entry of the Supported models table loads the built-in training data and its
leakage_keys.tsvrow. Atraining_datacell on that row is ignored.
End-to-end worked example
model file training_data
ergo2 predictions/ergo2_predictions.csv
my_model predictions/my_model_predictions.csv training/my_model_train.csv
tcr-pmhc-analyzer create-analyzer-table \
-i input.tsv \
-o analyzer_table.csv \
--ergo-version vdjdb
tcr-pmhc-analyzer benchmark \
--table analyzer_table.csv \
-o results/ \
-m "ergo2 my_model"
For my_model, analyzer_table.csv gains three new columns:
binding_score_my_model: raw score frompredictions/my_model_predictions.csvsample_in_train_my_model:True,Falseor empty from the leakage matcher. It uses the key columns thattraining/my_model_train.csvand the prediction file both carry (see the table above). Empty means the row could not be checked.seen_in_my_model:TrueorFalse, from whether thepeptide_sequence_aaof the row appears in the peptide column oftraining/my_model_train.csv
Walkthrough. Assume training/my_model_train.csv ships only peptide_sequence_aa and junction_aa_trb (a beta-only training set). Per the match-key table, sample_in_train_my_model then uses (peptide_sequence_aa, junction_aa_trb), the same rule as atm-tcr.
- A prediction row is
Truewhen its peptide equals a training peptide and its beta junction matches the junction of that training row. See the junction rule in Step 4. - The analyzer ignores
mhc_allele_1,junction_aa_traand the V/J columns, because the training file does not have them. - A prediction row with no beta junction is not checked, so its flag is empty.
seen_in_my_modeldoes not depend on the match-key table. It isTruewhenever thepeptide_sequence_aaof the row alone is present in the peptide column of the training file.
The benchmark -m "ergo2 my_model" command above consumes these three columns. create-dashboard picks them up automatically from the same analyzer_table.csv, as for any built-in model.
How it works
- Merge: The analyzer merges prediction outputs from multiple models on the
identifiercolumn into a single DataFrame. - Data leakage detection: The analyzer checks each sample against the training data of each model (see Training data) and flags samples that appear in a training set. One matcher serves every model. A sample that cannot be checked gets an empty flag. See Data leakage detection.
- Seen peptide detection: The analyzer checks each peptide against the training data to identify whether the model saw it during training.
- Benchmarking: The analyzer generates ROC curves after it removes leaked samples, separately for seen and unseen peptides.
Data leakage detection
sample_in_train_{model} says whether a training row of the model matches a test row. One matcher serves every model. Two data files decide which columns each model uses: the pattern file (Step 1) and the key file (Step 2).
Terms in this section:
- Test table: the merged analyzer table. It has one row per sample.
- Training table: the converted training data of one model.
- Key: the set of columns that a model was trained on.
- Anchor column: one of
junction_aa_tra,junction_aa_trb,anarcii_cdr3aandanarcii_cdr3b. These columns identify the clonotype.
The three values of sample_in_train_{model}
| Value | Meaning |
|---|---|
True |
At least one training row matches the sample. The sample is a leak. |
False |
The sample was checked and no training row matches. |
| empty | The sample could not be checked. Empty does not mean clean. |
A plain sum over the column hides the empty rows. Count True, False and empty rows separately. A written CSV or TSV file holds an empty cell for each unchecked row. The commands treat the empty rows as follows:
create-analyzer-tableprints a count of each value per model (seecreate-analyzer-table).benchmarkdrops flagged and unchecked rows from every leakage-removed curve (seebenchmark).create-dashboardshows an unchecked row asNot checkedand excludes it from the leakage-removed regimes (seecreate-dashboard).
A row stays empty for one of these reasons:
- The model key has no
peptide_sequence_aacolumn, or no anchor column. Nothing can be compared. - The row has no usable
peptide_sequence_aavalue. Or the row has no usable value in any anchor column of the key. A non-canonical cell is not usable, see Step 1. - The training table cannot answer the question. It has no
peptide_sequence_aacolumn, no anchor column of the key, no rows, or no usable peptide. - The training table holds a chain in an anchor column that the prediction table does not have, and a training row fills only that column. The matcher never compared that row against the prediction row.
- The row holds a non-canonical value in an anchor column, and a training row of the same peptide holds its chain only in that column. The matcher never compared that row either.
The warning gives the reason as a sentence. For reason 3, it names the column to rename. For reason 4, it names the column to add to the prediction file. For reason 5, it names the column to repair.
Reasons 4 and 5 ask the question inside the peptide group. A training row with a different peptide can never match, so it never makes a row unchecked.
A training table can have only some of the anchor columns of the key. The matcher then keeps every True flag. A False flag becomes empty for a row only when some training row has no usable value in any anchor column that both tables hold and the test row fills. That training row may hold its TCR in the missing column. Every other False flag stays False. Example: a custom model with a beta-only training file. A row with a beta junction stays False when every training row has a beta junction.
Step 1: the canonical pattern gate
The analyzer checks every cell of a candidate column of the test table against a canonical pattern before it matches. A candidate column is any column in at least one model key. The patterns are in src/tcr_pmhc_analyzer/data/leakage_columns.tsv. In an installed package, run python -c "import tcr_pmhc_analyzer, pathlib; print(pathlib.Path(tcr_pmhc_analyzer.__file__).parent / 'data')" to find the data directory.
That file is the catalogue of every leakage column. Each row gives one column its role (peptide, anchor or context), its comparator, its readable rule, its canonical pattern and its chain_name. An empty pattern means the gate does not check that column. The six anarcii_* columns have an empty pattern. The patterns mirror the rows of the pipeline's assets/input_rules.tsv that leakage uses, except the junction patterns. They accept any amino acid string, so a trimmed CDR3 is checked.
| Column | Pattern | Passes | Fails |
|---|---|---|---|
mhc_allele_1 |
^HLA-[A-Z0-9]+\*\d{2,3}:\d{2,3}$ |
HLA-A*02:01 |
HLA-A*02:01:01, A*02:01, HLA-A*02 |
peptide_sequence_aa |
^[ACDEFGHIKLMNPQRSTVWY]+$ |
GILGFVFTL |
GILGFVFTLX, GIL GFV |
junction_aa_tra |
^[ACDEFGHIKLMNPQRSTVWY]+$ |
CAASGGGSQGNLIF |
CAASGG-GSQGNLIF |
junction_aa_trb |
^[ACDEFGHIKLMNPQRSTVWY]+$ |
ASSIRSSYEQY |
CASS IRSSYEQYF |
v_call_tra |
^TRAV\d+(-\d+)?(/DV\d+)?\*\d{2}$ |
TRAV29/DV5*01 |
TRAV29/DV5 (no *NN) |
j_call_tra |
^TRAJ\d+\*\d{2}$ |
TRAJ42*01 |
TRAJ42 |
v_call_trb |
^TRBV\d+(-\d+)?\*\d{2}$ |
TRBV20-1*01 |
TRBV20-1 |
j_call_trb |
^TRBJ\d-\d\*\d{2}$ |
TRBJ2-7*01 |
TRBJ2-7 |
mhc_class |
^(MHC-I|MHC-II|MHC-nonclassical)$ |
MHC-I |
MHCI, I |
The six anarcii_* columns have no pattern. They always pass.
- The check ignores case and surrounding whitespace. It ignores empty values.
- The check is per cell. A bad cell is a wildcard for its own row only. Every other row keeps its value in that column.
- The warning names the column, the number of bad cells, the first three bad values with their identifiers, and the models whose key uses the column. Use them to repair the input.
- Example:
A*02:01without theHLA-prefix failsmhc_allele_1. - Test values must be in the pipeline format. A value outside its pattern, such as
A*02:01withoutHLA-orTRBV19without an allele, is ignored for its own row. - Training values are parsed tolerantly by the comparison rules in Step 4. The gate does not check them.
A bad cell differs from an empty cell in one way. An empty junction means the row has no such chain. A bad junction means a chain the analyzer cannot read.
| Bad cell | Effect on its row |
|---|---|
context column, such as mhc_allele_1 |
Matches any value, so the match of that row is wider. |
| anchor column | Matches any value. If a training row of the same peptide holds its chain only in that column, the row is unchecked instead of clean. |
peptide_sequence_aa |
The row is unchecked. |
The unchecked-rows warning that follows names the model and its reason.
Step 2: the model keys
The file src/tcr_pmhc_analyzer/data/leakage_keys.tsv holds the keys. It is in the same data directory as the pattern file. It has one row per training key. The columns are training_key and key_columns (comma-separated). A model with no row uses the __custom__ row. The hyphenated ERGO-II names use the underscored training key (ergo2-vdjdb uses ergo2_vdjdb).
| Model | Key |
|---|---|
ergo2_mcpas, ergo2_vdjdb |
peptide, both junctions, V and J of both chains, MHC allele, mhc_class |
mixtcrpred, mixtcrpred-pan, t2pmhc-gcn, t2pmhc-gat, tcren, stag-llm |
peptide, both junctions, V and J of both chains, MHC allele |
tulip-tcr |
peptide, both junctions, MHC allele |
tabr-bert |
peptide, beta junction, MHC allele |
atm-tcr |
peptide, beta junction |
nettcr-peptide, nettcr-pan |
peptide, MHC allele, the six anarcii_* loops |
custom models (__custom__) |
every candidate column |
To change a model key, edit its row in leakage_keys.tsv. To add a built-in model, add a row. Use only column names that have a row in leakage_columns.tsv. To use a new column, add its row there first. The analyzer reads the file once per run and checks every row. A bad row raises an error that names the file and the line. The __custom__ row must stay. The file is package data. Edit it in the source tree, and reinstall unless you use an editable install. An edit to the copy in an installed package also works, but the next reinstall overwrites it.
nettcr-peptide and nettcr-pan read their six anarcii_* loops from the prediction file. The analyzer derives that list from leakage_keys.tsv: it is the key columns of the model that are not analyzer table columns. The analyzer carries them in memory and never writes them to the analyzer table. The registry is built-in only and has no samplesheet knob.
Step 3: the row check
The matcher checks each test row once per model before it reads a training row.
- The row must have a non-empty
peptide_sequence_aa. - The row must have a non-empty value in at least one anchor column of the key.
A row that fails stays empty. Example: a row with no beta junction cannot be checked for atm-tcr. The atm-tcr key holds only the peptide and the beta junction.
Step 4: the comparison
The matcher compares one test row with one training row as follows.
- Start from the model key. A non-canonical test cell is empty for this comparison.
- Keep a column only when both values are usable. A value is unusable when it is empty. It is also unusable when its rule cannot read it. Example: a free-text
mhc_allele_1such as a cell line name, or a V or J value that no rule can read. An unusable value is a wildcard. - The peptide must survive. At least one anchor column must survive. Otherwise the training row does not match.
- Compare each surviving column with the rule for its type.
- The training row matches when all surviving columns agree.
Every rule strips whitespace and ignores case first.
| Column type | Rule |
|---|---|
peptide, mhc_class, anarcii_* loops |
Exact match. |
| junction | The sets of variants must intersect. A variant is the value, the value without a leading C, without a trailing F or W, or without both. The rule removes at most one trailing residue. CASSIRSSYEQYF matches CASSIRSSYEQYW. |
| V and J gene | Split the call into gene and allele. The allele follows * or :, so TRBJ2-7:01 reads as TRBJ2-7*01. Leading zeros in a gene number are removed, so TRBV06-05 reads as TRBV6-5. Compare gene and allele when both values have an allele. Otherwise compare the gene. A list such as TRBV6-1/6-5 or TRBV12-3,12-4 matches when any of its calls matches. A garbled value is read up to the first U+FFFD: TRBV06- compares at gene family (TRBV6), TRAV12-2 as the gene. A value that no rule can read, such as TRBJ1-1/2, is a wildcard. |
mhc_allele_1 |
Strip HLA-. Expand A2 to A*02. Split on :. Compare the first n fields, where n is the smaller field count. A bare locus such as HLA-A is a wildcard. |
The rule never pads a missing field. A*02 does not become A*02:01, because that would invent a field.
The analyzer compares a V or J call at allele level when both sides carry an allele. TRBV19*01 and TRBV19*02 are different alleles, so they do not match. The old mixtcrpred matcher stripped the suffix and treated them as the same call. The new rule is stricter on purpose. The mixtcrpred and mixtcrpred-pan training file is the one that mixes calls with and without the suffix, so this is where the change is visible.
--strict-leakage
The flag exists on create-analyzer-table and on benchmark. It turns every skip into an error. A skip is a non-canonical cell in a key column or an unchecked row. Without the flag, each skip is a warning. With the flag, the command stops with exit code 2.
benchmark --table reads the flags from the file. An empty sample_in_train_{model} cell counts as an unchecked row. The benchmark check runs before any plot, so a strict run leaves no partial output.
Known limitations
- Anarcii numbering drift. The six
anarcii_*columns in the NetTCR training file and in a NetTCR prediction file come from two separate anarcii runs. If the numbering schemes of the two runs disagree, the loop boundaries shift and the match silently under-counts true leakage. The canonical pattern gate cannot detect this, because theanarcii_*columns have no pattern. - Column name and content of
junction_aa_*. The namejunction_aa_tra/junction_aa_trbstates that the value is a junction (with anchors). Some training sources store the trimmed CDR3 without anchors, andtabr-bertis mixed. The converter still writes these values tojunction_aa_*, so the column name does not match the content for these sources. The junction rule tolerates a missing leadingCor trailingForW, so the match still works. - Leakage uses the original input values. The analyzer matches leakage on the values in your input file. It does not use the values each model received. The pipeline parser changes some values. It applies
normalize_hlato the MHC for ERGO-II, TABR-BERT and TULIP-TCR. It center-crops the CDRs for NetTCR (A3 maximum 22, B3 maximum 23). The analyzer matches NetTCR on the six uncroppedanarcii_*loops.
Citations
If you use tcr-pmhc-analyzer in your research, please cite the underlying prediction models:
-
Croce G, Bobisse S, Moreno DL, Schmidt J, Guillame P, Harari A, Gfeller D. Deep learning predictions of TCR-epitope interactions reveal epitope-specific chains in dual alpha T cells. Nature Communications. 2024;15:3211. doi: 10.1038/s41467-024-47461-8
Licence: https://github.com/GfellerLab/MixTCRpred/blob/acd6f57444bde675840890207c74ca3b0c7ffac2/LICENSE.md
Run as
mixtcrpredand, with a pan-epitope checkpoint retrained by the user, asmixtcrpred-pan. -
Springer I, Tickotsky N, Louzoun Y. Contribution of T Cell Receptor Alpha and Beta CDR3, MHC Typing, V and J Genes to Peptide Binding Prediction. Frontiers in Immunology. 2021;12:664514. doi: 10.3389/fimmu.2021.664514
-
Zhang J, Ma W, Yao H. Accurate TCR-pMHC interaction prediction using a BERT-based transfer learning method. Briefings in Bioinformatics. 2024;25(1):bbad436. doi: 10.1093/bib/bbad436
-
Meynard-Piganeau B, Feinauer C, Weigt M, Walczak AM, Mora T. TULIP: A transformer-based unsupervised language model for interacting peptides and T cell receptors that generalizes to unseen epitopes. Proceedings of the National Academy of Sciences. 2024;121(24):e2316401121. doi: 10.1073/pnas.2316401121
-
Cai M, Bang S, Zhang P, Lee H. ATM-TCR: TCR-Epitope Binding Affinity Prediction Using a Multi-Head Self-Attention Model. Frontiers in Immunology. 2022;13:893247. doi: 10.3389/fimmu.2022.893247
-
Polster M, Stadelmaier J, Ball E, Scheid J, Bauer J, Nelde A, Claassen M, Dubbelaar ML, Walz JS, Nahnsen S. t2pmhc: A Structure-Informed Graph Neural Network to predict TCR-pMHC Binding. bioRxiv. 2026. doi: 10.64898/2026.02.27.708137
Run in its
t2pmhc-gcnandt2pmhc-gatvariants. -
Karnaukhov VK, Shcherbinin DS, Chugunov AO, Chudakov DM, Efremov RG, Zvyagin IV, Shugay M. Structure-based prediction of T cell receptor recognition of unseen epitopes using TCRen. Nature Computational Science. 2024;4:510-521. doi: 10.1038/s43588-024-00653-0
Licence: https://github.com/antigenomics/tcren/blob/cf1e1f0fd562fda1fc9f33c4385f9cffe5536413/LICENSE
-
Slone JK, Zhang M, Jiang P, Montoya A, Bontekoe E, Rausseo BN, Reuben A, Kavraki LE. STAG-LLM: Predicting TCR-pHLA binding with protein language models and computationally generated 3D structures. Computational and Structural Biotechnology Journal. 2025;27:3885-3896. doi: 10.1016/j.csbj.2025.09.004
-
Jensen MF, Nielsen M. Enhancing TCR specificity predictions by combined pan- and peptide-specific training, loss-scaling, and sequence similarity integration. eLife. 2024;12:RP93934. doi: 10.7554/eLife.93934.3
Licence: DTU Health Tech Academic Software License Agreement, https://github.com/mnielLab/nettcr-2.2/blob/7cead3fe6dcb539ff8e2d9121586dafca1e059c2/academic_software_license_agreement.pdf
License
The code of tcr-pmhc-analyzer is released under the MIT licence.
The training data of the built-in models is not MIT licensed. The analyzer downloads it from the upstream tools (see Training data), and it is under their licences. Several of these licences are restrictive (academic or non-commercial use only), as the table below lists. The package ships the full licence texts verbatim in src/tcr_pmhc_analyzer/data/licenses/. Its README maps each licence to its models, training file and pinned source URL.
| Model(s) | Training data licensed under | Use |
|---|---|---|
nettcr-pan, nettcr-peptide |
DTU Health Tech Academic Software License Agreement | Publicly funded academic, educational or research institutions only, for internal research; no commercialisation. Requires --accept-nettcr-license; cite NetTCR-2.2. |
mixtcrpred, mixtcrpred-pan |
MixTCRpred academic non-commercial licence | Academic non-commercial research only; commercial applications require buying the MixTCRpred licence. Requires --accept-mixtcrpred-license. |
tcren |
TCRen licence. Training data derived from antigenomics/tcren; mhc.class column renamed to mhc_class, see the licences README. |
Educational, research and non-profit use by non-profit institutions only. Requires --accept-tcren-license. Cite the TCRen repository. |
tabr-bert |
TABR-BERT licence (Apache 2.0 text with non-commercial terms) | Non-commercial only. Requires --accept-tabr-bert-license. |
ergo2, ergo2-vdjdb, ergo2-mcpas |
MIT | See licence text. |
atm-tcr |
CC BY 4.0 | Attribution required. The training data is data/combined_dataset.csv of Lee-CBG/ATM-TCR (Cai et al. 2022) with one header line added at runtime; the data rows are unchanged. |
tulip-tcr |
GPL 3.0 | See licence text. |
stag-llm |
MIT | See licence text. |
t2pmhc-gcn, t2pmhc-gat |
MIT | See licence text. |
Metadata
Release files for tcr-pmhc-analyzer 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tcr_pmhc_analyzer-0.4.0.tar.gz | 1.7 MB | With provenance | Details for tcr_pmhc_analyzer-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tcr_pmhc_analyzer-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for tcr_pmhc_analyzer-0.4.0-py3-none-any.whl |
Total release size: 3.3 MB
Release files / tcr_pmhc_analyzer-0.4.0.tar.gz
| Download URL | tcr_pmhc_analyzer-0.4.0.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3536c05d13d7aad044018a0aa528e0fa81f1c2888ea3f0d080900607c4513843
|
|
BLAKE2b-256 checksum How to use checksums |
5628673a94bbad527cdca6b771f855812e2ea074dc2049afb4b5d4a62d54dd82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / tcr_pmhc_analyzer-0.4.0-py3-none-any.whl
| Download URL | tcr_pmhc_analyzer-0.4.0-py3-none-any.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be2fb5ce38920b508d0f74fb2b96c6b635177d6e2329f97dd2472d58e68d2cd3
|
|
BLAKE2b-256 checksum How to use checksums |
899b0c9e85fa4c526b2b7a8347889402536e1649033113fe3b024710cf5b852c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for tcr-pmhc-analyzer 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tcr_pmhc_analyzer-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.