Skip to main content

Tests Coverage Status PyPI

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

The normal install includes Isovar for RNA-derived protein fragments, PirlyGenes and OncoRef for cancer-testis antigens and tissue expression, and WEIRDO for peptide foreignness. No installation extras are needed. See installation details for choosing a different Ensembl release and compatible 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

Install development tools with pip install -r requirements-dev.txt. 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

Run the synthetic Isovar integration tests without downloading Ensembl data:

pip install . pytest pytest-cov pytest-xdist
./test.sh -m isovar --strict-markers

License

Apache License 2.0. See LICENSE.

Metadata

Release files for topiary 5.108.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for topiary 5.108.3
File Size Uploaded Provenance Actions
topiary-5.108.3.tar.gz 2.6 MB Without provenance Details for topiary-5.108.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for topiary 5.108.3
File Interpreter ABI Platform Actions
topiary-5.108.3-py3-none-any.whl Python 3 none any Details for topiary-5.108.3-py3-none-any.whl

Total release size: 3.0 MB

Release files / topiary-5.108.3.tar.gz

Download URL topiary-5.108.3.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
da97f0e95a37023337ea1dde4205954fba405fa5e95398a2ce5632b5f8d0b45a
BLAKE2b-256 checksum
How to use checksums
e417fc165c0eac4f305ac1496d38dc62a24b8d7770a1590ec9687b75ea673dd1
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.108.3-py3-none-any.whl

Download URL topiary-5.108.3-py3-none-any.whl
Size 394.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
265229eef70f4e468b1f00e5e4836ac4b5e1560c6881da595f884b66c1a84e42
BLAKE2b-256 checksum
How to use checksums
34f93541d9f2274f98de151da4dca6b17852b5df8356818cacf674b5fd380771
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.108.3

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.

Release history Release notifications | RSS feed

This release

5.108.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page