rctd-py
Spatial transcriptomics deconvolution, 10–57x faster than R spacexr on a GPU (doublet mode)
New in v0.4.0: rctd-py now gives the same results as R spacexr wherever both use the same sigma. Getting there aligned a few details of the fit with R (bulk platform-effect fit, sigma sampling, singlet labels, cell-type order, QP solver), so results can differ from 0.3.9, mostly on sequencing-based data such as Visium. On imaging data (Xenium, CosMx, Atera) spot classes are almost unchanged. Numbers are in the changelog;
rctd-py==0.3.9stays available to reproduce earlier results.
A Python reimplementation of the spacexr RCTD algorithm (Cable et al., Nature Biotechnology 2022) with GPU acceleration via PyTorch.
Deconvolve spatial transcriptomics spots (Visium, Xenium, MERFISH, Slide-seq, …) into cell type proportions using a scRNA-seq reference — in minutes instead of hours.
Documentation: rctd-py.readthedocs.io (installation, tutorials, CLI, API reference, coming from R spacexr)
✨ Highlights
| ⚡ 10–57x faster than R spacexr | Doublet mode on 19 datasets, one GPU vs 8 R cores. Xenium Prime 5K, 503k cells fitted: 34 min vs 31 hours in R |
| 🎯 Matches R spacexr | Same calls as R wherever both pick the same sigma (11 of 19 datasets); 99.0–99.9% of spot classes on the rest, where sigma differs by 0.01–0.02, as it does between two R runs (details) |
| 🔧 Familiar to spacexr users | Same algorithm and, with a few exceptions, the same parameter names (mapping) |
📦 pip install rctd-py |
Pure Python, works on CPU out of the box (3.7–14x faster than R in doublet mode), uses a GPU when there is one |
| 🧬 Whole-transcriptome ready | 10x Atera WTA (18,028-gene panel): 714k cells deconvolved in 9 min on GPU (doublet mode, 7 cell types) |
Installation
uv pip install rctd-py # or: pip install rctd-py
GPU builds of PyTorch, older NVIDIA drivers and offline / HPC installs (the 404 MB Q-matrices file) are covered in the installation guide.
Quick Start
from rctd import Reference, run_rctd
import anndata
reference = Reference(anndata.read_h5ad("reference.h5ad"), cell_type_col="cell_type")
spatial = anndata.read_h5ad("spatial.h5ad")
# normalisation, sigma estimation and deconvolution in one call
result = run_rctd(spatial, reference, mode="doublet")
# or write the results into the AnnData (obs["rctd_first_type"], obsm["rctd_weights"], ...)
from rctd import deconvolve
deconvolve(spatial, reference, mode="doublet")
scverse style, AnnData in and out (layer= for raw counts kept in a layer, key_added= for the key prefix). Both steps need raw counts:
import rctd
ref = rctd.pp.reference(ref_adata, cell_type_key="cell_type", layer="counts")
rctd.tl.deconvolve(spatial, ref, mode="doublet", layer="counts")
| Mode | What it does | Best for |
|---|---|---|
full |
Weights for all K cell types per pixel | Visium spots, continuous mixtures |
doublet |
Singlet or doublet call per pixel, top 1–2 types | Slide-seq, Visium HD bins, segmented cells (Xenium, MERFISH, CosMx) |
multi |
Greedy selection of up to 4 types per pixel | Spots expected to hold more than 2 types (an alternative to full) |
📓 Tutorial (marimo notebook) · 🤖 Claude Code skill (copy the .claude/skills/rctd-py/ folder into ~/.claude/skills/ for assisted coding with rctd-py)
Command Line
rctd info # versions, GPU availability
rctd validate spatial.h5ad reference.h5ad # fast input checks
rctd run spatial.h5ad reference.h5ad --mode doublet -o results.h5ad
rctd run experiment.zarr reference.h5ad --table cell_table # SpatialData stores work too
All options and the output layout: command line reference.
Benchmarks
rctd-py on one NVIDIA L40S or 8 CPU threads, R spacexr 2.2.1 on 8 cores; rctd-py points are the median of 3 runs. Full and multi mode, per-dataset tables and memory: benchmarks.
Citation
If you use rctd-py, please cite the original RCTD paper:
@article{cable2022robust,
title={Robust decomposition of cell type mixtures in spatial transcriptomics},
author={Cable, Dylan M and Murray, Evan and Zou, Luli S and Goeva, Aleksandrina and Macosko, Evan Z and Chen, Fei and Irizarry, Rafael A},
journal={Nature Biotechnology},
volume={40},
number={4},
pages={517--526},
year={2022},
doi={10.1038/s41587-021-00830-w}
}
Contributing
Contributions welcome! See CONTRIBUTING.md for setup instructions, or open an issue.
License
Metadata
Release files for rctd-py 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rctd_py-0.4.4.tar.gz | 611.6 kB | Without provenance | Details for rctd_py-0.4.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rctd_py-0.4.4-py3-none-any.whl | Python 3 | none | any | Details for rctd_py-0.4.4-py3-none-any.whl |
Total release size: 684.9 kB
Release files / rctd_py-0.4.4.tar.gz
| Download URL | rctd_py-0.4.4.tar.gz |
|---|---|
| Size | 611.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1da5dda4676fed8341327254c9cc350ebdb768182fbe43be0cb9da9de8140182
|
|
BLAKE2b-256 checksum How to use checksums |
cc70bc9d466e0c895cf5d6b7b2a11eebc92656e466a6c56db01921a8d431fbfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / rctd_py-0.4.4-py3-none-any.whl
| Download URL | rctd_py-0.4.4-py3-none-any.whl |
|---|---|
| Size | 73.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ea46fdf8dbac01f5189cf7e80ff402fbff2ae4536fec8358c74e22dba18d41b
|
|
BLAKE2b-256 checksum How to use checksums |
c885ef3cf12dd1a37dcdfe4e53bd711547cdc9cdc10033c959f933f9004d7818
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for rctd-py 0.4.4
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.