Information-theoretic analysis of paired single-cell RNA + TCR sequencing.
Documentation · Tutorials · Paper · Issues
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 entropyH(φ|c), normalized mutual informationI(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. responders vs non-responders) with direction probabilities.
- 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.10. Install from source:
git clone https://github.com/nceglia/tcri.git
cd tcri
pip install .
The heavy scientific stack (PyTorch, Pyro, scvi-tools, scanpy) is pulled in automatically. A GPU is optional but speeds up model fitting. 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="timepoint",
batch_key="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. read out information-theoretic metrics (bits)
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")
No paired data yet? tcri.datasets.simulate_tcri() returns a synthetic AnnData whose
true mutual information is known in closed form — the basis for the
tutorials.
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.
Governance
The public interface, the generative mathematics, the metric definitions and the training plan are each frozen by a machine-checked contract. A published number only means something if the definition behind it is stable, so a metric cannot be silently redefined and the model the package claims to implement is the model it does implement.
A failing conformance test means stop and decide — never loosen a contract to make it pass.
See Governance for what each
contract covers, and governance/ in the repository for the contracts themselves.
Related tools
| Tool | Relationship |
|---|---|
| scirpy | AIRR/TCR repertoire handling and analysis |
| scvi-tools | probabilistic modelling backbone TCRi builds on |
| scanpy / AnnData | single-cell data structures and workflows |
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.9.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 | |
|---|---|---|---|
| tcri-0.9.0.tar.gz | 160.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tcri-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 278.4 kB
Release files / tcri-0.9.0.tar.gz
| Download URL | tcri-0.9.0.tar.gz |
|---|---|
| Size | 160.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c3f9b4c1dfcf331915f64c3453208a7647074e318f5581b1018f77abdf2b4e7
|
|
BLAKE2b-256 checksum How to use checksums |
ba765c18f011fe24e27d4b18659812c8b5c3db8df895bb72da5316d643b6b1bc
|
| 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 Aug 26, 2026.
Transparency logRelease files / tcri-0.9.0-py3-none-any.whl
| Download URL | tcri-0.9.0-py3-none-any.whl |
|---|---|
| Size | 118.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93491eca0dab1d0938b7db40e62add0e0416e864075a28664a60c370a7e6e271
|
|
BLAKE2b-256 checksum How to use checksums |
f895bead85b45781696b4dda1695fa42c1eedc6a64d450f1595adb51a43ed39d
|
| 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 Aug 26, 2026.
Transparency log