Skip to main content

mirpy

mirpy — ML embeddings for immune repertoires

PyPI Python CI docs License

Get started · Guides · Commands · API · Theory · Examples · Glossary

Turn T- and B-cell receptor tables into clonotype coordinates, sample RFF vectors, or published corpus signatures. PyPI package mirpy-lib, Python import mir. Native alignment and repertoire IO come from seqtree and vdjtools.

mirpy workflow: inputs, batched processing and outputs. Schematic illustrations.

Install

pip install mirpy-lib

Optional extras: [parquet] for streaming clonotype Parquet, [ann] for approximate neighbours, [ml] for Torch codecs, [bench] for evaluation, and [examples] for marimo notebooks. See installation and first steps.

Native Windows installation uses the same pip install command; WSL is not required. The Windows workflow builds and installs a wheel, then checks batched receptor embedding and sample PCA with the native dependencies.

Choose your output

Command Output
mir embed clonotypes Clonotype coordinates with sample/clonotype IDs
mir embed repertoires One weighted RFF vector per sample, plus separate channels
mir pca Optional sample PCs from an RFF table
mir embeddings / mir signature Corpus-standardised rsig PCs and pass-through channels
mir embed clonotypes samples/*.tsv -o clonotypes.tsv
mir embed repertoires samples/*.tsv --save-basis basis -o rff.tsv
mir embed repertoires held_out/*.tsv --basis basis -o held_out_rff.tsv
mir pca rff.tsv --fit rotation.npz --n-components 32 -o pcs.tsv
mir pca held_out_rff.tsv --rotation rotation.npz -o held_out_pcs.tsv

The sample path is clonotype coordinates → shared clonotype basis → RFF → weighted mean → optional sample PCA. Every sample must use the same basis and weighting. Save and reuse the basis and, if fitted, the sample rotation. RFF is applied before averaging. rsig is a different representation; its corpus rotations cannot rotate RFF.

The embedding guide covers fitting on input rows, compatible control rows or a saved rotation, output columns and memory limits. Signatures explains published rsig corpora and joining vdjtools' vsig on sample_id.

Frozen reference bundles, vdjtools models and examples are hosted in AIRR feature signatures. Run mir reference rna-blood to print a checksum-verified local bundle directory; use its matching basis and rotation as described in the embedding guide.

Python quickstart

import mir                       # establish runtime limits before numerical libraries
import polars as pl
from mir.embedding.tcremp import TCREmp

sample = pl.DataFrame({
    "v_call": ["TRBV10-3*01", "TRBV20-1*01"],
    "j_call": ["TRBJ2-7*01", "TRBJ1-2*01"],
    "junction_aa": ["CASSIRSSYEQYF", "CSARVSGYYGYTF"],
})
model = TCREmp.from_defaults("human", "TRB")
coordinates = model.embed(sample)  # interleaved V, J, junction distances per prototype

Find the right page

Task Guide
RFF tables, shared bases and sample PCA Embeddings
Filtering before embedding Pre-processing
Density, MMD, digital donors, codecs and CPU budgets User guide
Corpus signatures and pass-through channels Signatures · Channels
Functions, flags, examples and terminology API · Commands · Examples · Glossary
Mathematical derivations Theory

Resource budgets

Logical CPUs are hardware threads, not physical cores: a 40-logical-CPU node may have 20 physical cores. Automatic sizing uses visible topology and respects affinity, SLURM and container limits; unknown topology falls back to the logical allocation. Explicit positive budgets may use SMT threads within that allocation.

Import mir before numerical libraries in a fresh interpreter. Sample workers use serial inner kernels and retain one sample each; only compact RFF rows survive. The final table still grows with cohort size and RFF width, and a deep input sample can dominate memory. Automatic budgets use the physical cores visible within the CPU allocation and manage inner kernels automatically. An explicit positive count overrides the automatic budget within your allocation. Known large allocations check container memory. See the resource contract and embedding memory guide.

Advanced models and fitted references

Reference bundles can opt into vdjtools' basic or joint statistical features and their IMGT11/BLOSUM62 motif variants via feature_definition=. The bundle records the definition and vocabulary for compatible saved-PCA application. Configured fitting delegates to vdjtools' sparse TablePCA.fit_features, preserving raw median-impute/StandardScaler coordinates without a dense training table. Sample workers join before the BLAS phase. Existing rsig and sample RFF behavior stays unchanged; see the embedding guide.

New synthetic reference/background calls default to vdjtools' isalgo family. Use olga-legacy (olga alias) for frozen OLGA parameters and reference sampler streams. learned and arda alias fresh isalgo; old fitted weights require a pinned previous release. Existing corpus, prototype and embedding artifacts remain unchanged; changing a default does not refit a saved reference.

Agent skill

The mirpy skill routes embedding, density and signature workflows to the public APIs and guides. Copy skills/mirpy into your agent’s skill directory or read it in this checkout.

Development

bash setup.sh --dev-parents --docs --tests
source .venv/bin/activate
python -m pytest tests/ -q -m "not integration and not benchmark"
env -C docs make html

Uses a repo-local uv environment. Public APIs and architecture are documented in the API reference; no private agent files are needed to use the package.

Citing

Method: Kremlyakova et al., TCREMP: A Bioinformatic Pipeline for Efficient Embedding of T-cell Receptor Sequences from Immune Repertoire and Single-cell Sequencing Data, J Mol Biol 437(15) (2025) 169205. PubMed · DOI.

See the mathematical foundations for derivations.

License

ISALGO LAB Academic and Non-Commercial Research License v1.0. See LICENSE.

The classical v1.x/v2 repertoire toolkit — parsing, overlap, diversity, TCRnet, GLIPH — is frozen on the legacy-v2 branch (mirpy-lib 2.x); its functionality lives on in vdjtools and vdjmatch.

Metadata

Release files for mirpy-lib 4.10.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 mirpy-lib 4.10.3
File Size Uploaded Provenance Actions
mirpy_lib-4.10.3.tar.gz 5.8 MB With provenance Details for mirpy_lib-4.10.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mirpy-lib 4.10.3
File Interpreter ABI Platform Actions
mirpy_lib-4.10.3-py3-none-any.whl Python 3 none any Details for mirpy_lib-4.10.3-py3-none-any.whl

Total release size: 8.0 MB

Release files / mirpy_lib-4.10.3.tar.gz

Download URL mirpy_lib-4.10.3.tar.gz
Size 5.8 MB
Tags Source
SHA-256 checksum
How to use checksums
30d3189d463010bd792e71f9d71bf7550a3861aa68c282c4c7f73d47d7cd9d93
BLAKE2b-256 checksum
How to use checksums
d2e430ebe9ac6ea46e317c59163752486de44f7bdf8dbb6003cdbc8106cdc0af
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 6, 2026.

Transparency log

Release files / mirpy_lib-4.10.3-py3-none-any.whl

Download URL mirpy_lib-4.10.3-py3-none-any.whl
Size 2.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5243c20d57c82446ca8f6e7f357d24ef98c25b5c092553842e571b8f8dddaf1c
BLAKE2b-256 checksum
How to use checksums
b8cf89b283f9ced30523a2c520754a3e1dad174bd3812f1d4384c9bd218eb850
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 6, 2026.

Transparency log

Security for mirpy-lib 4.10.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mirpy_lib-4.10.3.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 6, 2026.

Transparency log

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

4.10.3 This release

2 release files Full 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