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

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.100.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.100.3
File Size Uploaded Provenance Actions
topiary-5.100.3.tar.gz 2.6 MB Without provenance Details for topiary-5.100.3.tar.gz

Built distribution (wheel)

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

Total release size: 3.0 MB

Release files / topiary-5.100.3.tar.gz

Download URL topiary-5.100.3.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
e8f0908bfe9cb536d84e07435c6271feeab363ded1b803101f84f9c9c84f2e1f
BLAKE2b-256 checksum
How to use checksums
c14aeadc8116d0cb461736e358b96e92b67b685af0a642e2feac0defce08909b
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.100.3-py3-none-any.whl

Download URL topiary-5.100.3-py3-none-any.whl
Size 378.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb6d4da5ad2721753e8bbb1f13d577f1a5a27b8865fa857bea802b37c7a0cbef
BLAKE2b-256 checksum
How to use checksums
b9864e6c0e75f573d46dc53eb18f81018a986f66180222c7854f9853c64d764c
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.100.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.100.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