Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

TCRi

Information-theoretic analysis of paired single-cell RNA + TCR sequencing.

Documentation · Tutorials · Paper · Issues · Contributing

tests docs license: MIT python 3.12+ built on scverse


TCRi quantifies how T-cell clonotypes relate to transcriptional phenotypes in paired single-cell data. It fits a hierarchical Bayesian model (on top of scvi-tools / Pyro) that ties each clone's phenotype distribution to gene expression, then reads out information-theoretic summaries — clonotypic and phenotypic entropy, clone↔phenotype mutual information, and phenotypic flux across conditions — over the learned clone × phenotype joint distribution.

It is built on the scverse stack (AnnData, scanpy, scvi-tools) and works on a standard AnnData carrying both a clonotype label and a gene-expression matrix.

Key capabilities

  • Joint model of expression + repertoire — a hierarchical VAE (TCRIModel) that learns each clone's phenotype distribution while reconstructing counts with a ZINB decoder.
  • Information-theoretic metrics — clonotypic entropy H(c|φ), phenotypic entropy H(φ|c), normalized mutual information I(c;φ), and phenotypic flux between conditions, all in bits over the posterior joint.
  • Uncertainty-aware — every metric can be reported as a posterior mean ± HDI by drawing from the fitted Dirichlet posterior (n_samples > 0).
  • Group comparisons — paired/unpaired contrasts across cohorts (e.g. disease vs control), with n counting replicates rather than items.
  • Diagnostics — posterior-predictive checks, phenotype calibration, and permutation nulls for the metrics.
  • Contract-governed — the public API, the generative model, the metric definitions, and the training plan are each frozen by a machine-checked contract.

Installation

TCRi targets Python ≥ 3.12.

pip install tcri

The heavy scientific stack (PyTorch, Pyro, scvi-tools, scanpy) is pulled in automatically. A GPU is optional but speeds up model fitting.

For the development version:

git clone https://github.com/nceglia/tcri.git
cd tcri
pip install -e ".[test]"

See the installation guide for details.

Quickstart

import tcri

# 1. register clonotype / phenotype / covariate / batch columns on your AnnData
tcri.ml.TCRIModel.setup_anndata(
    adata,
    layer="counts",
    clonotype_key="clone_id",
    phenotype_key="phenotype",
    covariate_key="condition",
    batch_key="patient",
    replicate="patient",
)

# 2. fit the model and write learned quantities back onto the AnnData
model = tcri.ml.TCRIModel(adata)
model.train(max_epochs=200, batch_size=512)
model.to_anndata(adata)

# 3. fit the permutation references, once: every metric is read against one
tcri.null.all(model, adata)

# 4. read out information-theoretic metrics (bits), each with its own floor
#    -> value, null_value, excess = value - null_value
mi = tcri.tl.mutual_information(adata, covariate="pre", normalize_mode="average")
ce = tcri.tl.clonotypic_entropy(adata, covariate="pre")
flux = tcri.tl.phenotypic_flux(adata, cov_from="pre", cov_to="post")

# 5. ask the fitted model which genes the phenotype calls rest on
tcri.perturb.gene_importance(model, adata, splitby="disease_status")
tcri.pl.gene_importance(adata, quantity="excess")

No paired data yet? tcri.datasets.simulate_cohort() returns a synthetic AnnData with patients as replicates, an ordered condition axis within each, and a disease_status label between them — the basis for the tutorials. tcri.datasets.simulate_tcri() is the single-sample alternative, with a mutual information known in closed form.

Framework

TCRi models the joint distribution of clonotype and phenotype hierarchically: a clonotype-level prior p_c over phenotypes, a covariate-specific p_ct anchored to it, and a per-cell phenotype that fuses a classifier on the latent embedding z with the clone's local prior. The metrics are then pure functions of the learned clone × phenotype joint. The full generative model and its plate diagram are documented under Concepts.

TCRi framework

Citation

If you use TCRi in your research, please cite:

TCRi: An Information Theoretic Framework for Paired Single Cell Gene Expression and TCR Sequencing

Nicholas Ceglia, Sohrab Salehi, et al.

bioRxiv 2022. doi: 10.1101/2022.10.01.510457

BibTeX
@article{ceglia2022tcri,
  title   = {TCRi: An Information Theoretic Framework for Paired Single Cell Gene Expression and TCR Sequencing},
  author  = {Ceglia, Nicholas and Salehi, Sohrab and others},
  journal = {bioRxiv},
  year    = {2022},
  doi     = {10.1101/2022.10.01.510457}
}

License

TCRi is released under the MIT License.

Metadata

Release files for tcri 0.13.0a1

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

Source distribution (sdist)

Source distribution for tcri 0.13.0a1
File Size Uploaded
tcri-0.13.0a1.tar.gz 303.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tcri 0.13.0a1
File Interpreter ABI Platform
tcri-0.13.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 477.1 kB

Release files / tcri-0.13.0a1.tar.gz

Download URL tcri-0.13.0a1.tar.gz
Size 303.0 kB
Tags Source
SHA-256 checksum
How to use checksums
65515e8d34f9680eb193f51efdf817b6ce36c833248716bd17fd6d414243fd14
BLAKE2b-256 checksum
How to use checksums
4ff22d2bd0e51580bdd68ad8c22e862d57c63baf7241bdce6382fe41b5ec5397
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 16, 2026.

Transparency log

Release files / tcri-0.13.0a1-py3-none-any.whl

Download URL tcri-0.13.0a1-py3-none-any.whl
Size 174.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5652845782074b3a954010230fdee78fcf98aef5819eb734ee5d7bed03bc3dcf
BLAKE2b-256 checksum
How to use checksums
2d743a9c557d3aee514d7cbce28eb39d4e1883bf08ae2aa9b8a73d92f2d4c7d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 16, 2026.

Transparency log

Release history Release notifications | RSS feed

0.14.0

2 release files

0.13.1

2 release files

0.13.0

2 release files

This release

0.13.0a1 This release

2 release files

0.12.0

2 release files

0.9.0

2 release files

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