Topiary
Topiary predicts which peptides from an antigen source are presented by a patient's MHC molecules, then filters and ranks them. Inputs are protein sequences, peptides, somatic variants or a pipeline's report, plus a list of HLA alleles; output is a DataFrame (or CSV/TSV/HTML) with one row per peptide-allele-prediction. Binding predictions come from mhctools models such as NetMHCpan and MHCflurry.
It is used for personalized cancer vaccine design, viral epitope mapping, and characterizing T-cell responses.
Documentation: openvax.github.io/topiary
Installation
Topiary requires Python 3.11 or newer and pandas 3.x (pandas>=3,<4).
pip install topiary
MHC binding predictors are installed separately and called through mhctools. MHCflurry installs with pip:
pip install mhcflurry && mhcflurry-downloads fetch
NetMHCpan and the other DTU tools require a license from DTU Health Tech.
Variant annotation, gene lookups and SelfProteome need a local Ensembl
annotation database:
pyensembl install --release "$(python -c 'from pyensembl import ensembl_grch38; print(ensembl_grch38.release)')" --species human
Two optional extras add input sources: pip install 'topiary[pirlygenes]' for
cancer-testis antigens and tissue expression, and
pip install 'topiary[isovar]' for protein fragments assembled from RNA reads.
See installation details
for choosing a different Ensembl release and for the optional-package versions.
Predict binding for a few peptides
from topiary import TopiaryPredictor
from mhctools import NetMHCpan
predictor = TopiaryPredictor(
models=[NetMHCpan],
alleles=["HLA-A*02:01"],
)
df = predictor.predict_from_named_peptides({
"peptide_1": "YLQLVFGIEV",
"peptide_2": "LLFNILGGWV",
"peptide_3": "GILGFVFTL",
})
Each row of df is one peptide, allele and prediction kind, with value (the
raw prediction, IC50 in nM for binding affinity), score (normalized, higher is
better) and percentile_rank (lower is better). Several models can run
together — models=[NetMHCpan, MHCflurry] — and each contributes its own rows.
To scan whole proteins with a sliding window instead of scoring peptides as
given, use predict_from_named_sequences({"BRAF": "MAALSGGGG..."}).
Predict from somatic variants
The CLI runs the same pipeline from a VCF, translating each variant, tiling peptides across the mutated region, and keeping only peptides that overlap it:
topiary \
--vcf somatic.vcf \
--mhc-predictor netmhcpan \
--mhc-alleles HLA-A*02:01,HLA-B*07:02 \
--filter-by "ba <= 500 | el.rank <= 2" \
--only-novel-epitopes \
--output-csv epitopes.csv
The equivalent Python call is predictor.predict_from_variants(variants) on a
varcode variant collection.
Filter and rank
Filters and ranking expressions are written the same way in Python and as strings for the CLI:
from topiary import TopiaryPredictor, Affinity, Presentation
from mhctools import NetMHCpan
predictor = TopiaryPredictor(
models=[NetMHCpan],
alleles=["HLA-A*02:01"],
filter_by=(Affinity <= 500) | (Presentation.rank <= 2.0),
sort_by=Affinity.logistic(350, 150),
)
Affinity, Presentation, Stability and Processing each read a prediction
kind, through .value, .rank or .score. Expressions combine with
arithmetic and boolean operators, normalizing transforms, and any column in the
DataFrame — RNA expression, peptide properties, custom annotations. The string
forms (affinity <= 500 | el.rank <= 2) go to --filter-by and --sort-by.
The ranking DSL guide has the
full grammar.
Where to read more
| Guide | Covers |
|---|---|
| Quickstart | Input formats, Ensembl lookups, exclusion filtering, peptide-only models |
| Command-line interface | Predictor names, input modes, output columns, exit status |
| Ranking DSL | Filter and ranking expressions, multi-model disambiguation |
| Protein fragments | One antigen record for variants, fusions, ERVs, CTAs, viral and synthetic sources |
| RNA expression | Annotating predictions with Salmon, Kallisto, RSEM and other quantification |
| Cached predictions | Replaying stored scores instead of calling a predictor |
| Peptide properties | Charge, hydrophobicity, manufacturability and TCR-facing signals |
| Cross-reactivity | Nearest-self search and presentation evidence |
| Reading pVACseq, Exacto, combining sources | Importing other pipelines' reports and ranking them together |
| SV evidence reports | Complete structural-variant nomination inventories, including candidates with no recovered protein |
| API reference | Classes, functions and complete column lists |
Contributing
Run ./lint.sh and ./test.sh before submitting changes. The full suite uses
real Ensembl annotations and external MHC predictors; collecting tests does not
load either:
python -m pytest tests --collect-only
The synthetic Isovar integration tests need only the optional package:
pip install '.[isovar]' pytest pytest-cov pytest-xdist
./test.sh -m isovar --strict-markers
License
Apache License 2.0. See LICENSE.
Metadata
Release files for topiary 5.105.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 |
|---|---|---|---|---|
| topiary-5.105.0.tar.gz | 2.6 MB | Without provenance | Details for topiary-5.105.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| topiary-5.105.0-py3-none-any.whl | Python 3 | none | any | Details for topiary-5.105.0-py3-none-any.whl |
Total release size: 3.0 MB
Release files / topiary-5.105.0.tar.gz
| Download URL | topiary-5.105.0.tar.gz |
|---|---|
| Size | 2.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b460bccf8ebeeb09c910dfa48bd4c76fc8f94c9c27462db95506ce4f370f24c
|
|
BLAKE2b-256 checksum How to use checksums |
d60ee48fba12f4457dd8d23ce4abfa651200e8109194ade2832692de8ba71b03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Release files / topiary-5.105.0-py3-none-any.whl
| Download URL | topiary-5.105.0-py3-none-any.whl |
|---|---|
| Size | 389.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dec807130b8086951712dd841801a5d4a7c7396eacfe0fcd46542ba99cc708b
|
|
BLAKE2b-256 checksum How to use checksums |
da53f7de8dd07652d8f1298834fe486bc4b0e4fb8b6af75a1da05f41a9a75146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Security for topiary 5.105.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.