pyCellChat
pyCellChat is a GPU-accelerated Python implementation of CellChat's communication-probability model for atlas-scale single-cell cell-cell communication (CCC) analysis. It reproduces CellChat's core communication-probability model to numerical precision — median relative difference 9.3x10⁻⁸ against R CellChat across 316,412 interactions — while removing the scale ceiling of the reference R workflow, processing atlases up to 19.1 million cells. The package focuses on the validated core required for reproducible CCC inference: a CellChat-parity-validated communication-probability engine, GPU-accelerated permutation testing on CUDA, Apple Silicon MPS, and CPU, multi-sample batch execution, and differential CCC workflows with explicit exchangeability-unit guidance. In cross-subject comparisons, pyCellChat treats donors or samples as the inferential unit through replicated differential testing; cell-level differential testing is retained for within-dataset or deliberately cell-level analyses.
Contents
- What pyCellChat includes
- What is not included
- Installation
- Quick start
- Validation scope
- Save & Load
- Command-Line Interface
- Contributing
- Citation
- Authors
Further reading: BENCHMARKS.md (full parity and timing tables) · DIFFERENTIAL_CCC.md (calibration, power, reachability of the two differential CCC tests) · REPRODUCIBILITY.md (seeding, backend guards, permutation p-value conventions).
What pyCellChat includes
-
Core CellChat-parity-validated CCC —
compute_communication_prob(). Implements triMean expression summary, complex geometric mean (for multi-subunit ligands/receptors), Hill-function probability, mediator/cofactor (co-receptor, agonist, antagonist) modulation, population-size weighting, and permutation p-values. -
GPU permutation engine — CUDA / Apple Silicon MPS / CPU, with reproducible permutation behaviour across backends. Requires
torch >= 2.5.0(earlier releases have a confirmed MPS numerical defect; see Installation). -
Multi-sample batch execution —
run_batch()andrun_batch_backed(). CSV/HDF5 output, resume-safe execution on interrupted runs. -
Cell-level differential CCC —
compute_differential_ccc(). This treats cells as exchangeable and is appropriate only for within-dataset or deliberately cell-level analyses. It is not the recommended default for donor-structured cross-subject inference. -
Subject/sample-level differential CCC —
compute_differential_communication_replicated(). The recommended default when conditions are assigned across donors, subjects, samples, or biological replicates, because donors/samples — not cells — are the exchangeable units in that setting. -
Minimal plotting —
pcc.pl, covering core CCC and differential CCC visualisation only.
What is not included
pyCellChat's validated scope is the core communication-probability engine and the two differential CCC tests above. This package does not include:
- spatial CCC
- RNA velocity integration
- temporal / pseudotime / trajectory workflows
- perturbation / knockout simulation
- ligand-target coupling
- pathway/network enrichment
- NicheNet-like scoring
- OmniPath integration
- LIANA conversion
- a rare-cell annotator
- a broad general-purpose plotting gallery
Installation
Requirements
| Platform | Prerequisites |
|---|---|
| NVIDIA GPU | CUDA Toolkit >= 11.8, PyTorch >= 2.5 |
| Apple Silicon | macOS >= 12.3, PyTorch >= 2.5 |
| CPU only | Python >= 3.10, NumPy |
pyCellChat requires PyTorch >= 2.5. Earlier releases (2.2.2-2.4.x) have a
confirmed, reproducible MPS (Apple Silicon) numerical defect in the
triMean/permutation calculations — not float noise, real errors that
silently inflate significant-interaction counts. pyproject.toml/
environment.yml pin the floor at install time, and it is also enforced
at runtime, so a stale torch fails loudly rather than silently
returning wrong numbers.
From source
git clone https://github.com/alikhadim/pycellchat.git
cd pycellchat
pip install -e .
The software is named pyCellChat; the Python import namespace is pycellchat:
import pycellchat as pcc
Conda (recommended for reproducibility)
conda env create -f environment.yml
conda activate pycellchat
pip install -e .
Verify installation
import pycellchat as pcc
print(pcc.__version__)
import anndata as ad, numpy as np, scanpy as sc
adata = ad.AnnData(
X=np.random.rand(100, 200).astype("float32"),
obs={"celltype": ["A"] * 50 + ["B"] * 50},
)
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
cc = pcc.CellChat(adata, group_by="celltype", species="human", _silent=True)
print("OK:", cc.n_groups, "groups")
Quick start
Single sample
import scanpy as sc
import pycellchat as pcc
adata = sc.read_h5ad("sample.h5ad")
db = pcc.load_cellchat_db("human")
cc = pcc.CellChat(adata, group_by="celltype", species="human", db=db)
cc.compute_communication_prob(n_permutations=500, random_state=42)
cc.aggregate_communication_prob()
pcc.save_CellChat(cc, "sample.h5")
Multi-sample batch
results = pcc.run_batch(
adata,
group_by="sample",
cell_type="celltype",
species="human",
n_perm=500,
out_dir="results",
skip_existing=True,
)
For datasets too large to hold every sample's CellChat object in memory at once, run_batch_backed() provides the same per-sample processing with a memory-efficient/backed execution path.
Differential CCC
For donor/sample-structured comparisons, use the recommended default:
diff = pcc.compute_differential_communication_replicated(
cc_list, condition_labels=["control", "control", "disease", "disease"],
reference="control",
)
For within-dataset cell-level analyses only:
diff_cell = pcc.compute_differential_ccc(cc_a, cc_b)
See Validation scope and DIFFERENTIAL_CCC.md for why these two functions are not interchangeable.
Validation scope
Parity claims apply specifically to the core communication-probability model: triMean expression aggregation, complex geometric mean, Hill-function probability, permutation p-values, and pathway-level aggregation. The parity-locked implementation lives in pycellchat/core/cellchat.py and pycellchat/utils/stats.py.
Validated line-by-line against CellChat v2 (modeling.R) on the integrated human ILD scRNA-seq meta-analysis object accompanying Jaiswal et al. (Cell Genomics 2026), which combines five published lung scRNA-seq studies (Adams et al. 2020; Carraro et al. 2020; DePianto et al. 2021; Habermann et al. 2020; Reyfman et al. 2019): 620,644 cells from 130 donors in 8 diagnostic categories:
| Sample | Cells | Pearson r | Spearman ρ | RMSE |
|---|---|---|---|---|
| uILD | 4,226 | 0.99999999999999840 | 0.999999999998714 | 6.09x10⁻⁸ |
| Myo-ILD | 7,192 | 0.99999999999999770 | 0.999999999995853 | 5.90x10⁻⁸ |
| Sarcoidosis | 7,324 | 0.99999999999999860 | 0.999999999998841 | 5.99x10⁻⁸ |
| NSIP | 9,077 | 0.99999999999999770 | 0.999999999998647 | 6.22x10⁻⁸ |
| Fibrotic HP | 17,685 | 0.99999999999999790 | 0.999999999998026 | 6.16x10⁻⁸ |
| SSC-ILD | 64,742 | 0.99999999999999730 | 0.999999999998302 | 5.93x10⁻⁸ |
| Non-ILD Control | 212,703 | 0.99999999999999830 | 0.999999999997869 | 6.49x10⁻⁸ |
| IPF | 297,695 | 0.99999999999999840 | 0.999999999998767 | 5.93x10⁻⁸ |
Pooled across all 316,412 shared interactions: r = 0.999999999999997 (1 - r = 1.55x10⁻¹⁵), median relative difference 9.3x10⁻⁸. Full methodology and per-cohort tables: BENCHMARKS.md.
Algorithm: p = lr^h / (K^h + lr^h) (Hill function, default K=0.5, h=1), where lr is the triMean of sender ligand expression times the triMean of receiver receptor expression, geometric-mean-aggregated across subunits for complexes.
Scale. On a same-machine, matched-input benchmark (identical exported matrix, 500 permutations), the core engine is substantially faster than R CellChat, and pyCellChat completes atlases R CellChat cannot compute at all — R's sparse dgCMatrix representation fails at a hard 2³¹ non-zero-entry limit before inference begins. Full timing tables and methodology, including engine-only vs. end-to-end comparisons and run-to-run variance: BENCHMARKS.md.
Differential CCC calibration. compute_differential_ccc() (cell-level) has an empirically calibrated false-positive rate near the nominal 0.05 under a cell-level-exchangeable null, but is severely anticonservative under realistic donor-structured data. compute_differential_communication_replicated() (subject-level) controls the error rate under the same donor-structured conditions. This is why subject/sample-level permutation is the recommended default for cross-subject inference, and cell-level testing is reserved for within-dataset or deliberately cell-level analyses. Full calibration, power curves, and reachability tables: DIFFERENTIAL_CCC.md.
Save & Load
pyCellChat uses a compact HDF5 format. The default save omits the expression matrix; all network, pathway, and visualisation functions remain fully functional. Add keep_expression=True to also enable gene-level plots.
pcc.save_CellChat(cc, "sample.h5")
pcc.save_CellChat(cc, "sample.h5", keep_expression=True)
cc = pcc.load_CellChat("sample.h5")
Database version is stored in the HDF5 metadata and restored on load (cc.db_version), ensuring reproducibility across package updates.
Command-Line Interface
pycellchat run \
--input atlas.h5ad --species human --group-by celltype \
--out results/ --n-perms 1000 --gpu
pycellchat plot circle --input results/sample.h5 --output circle.pdf
pycellchat plot heatmap --input results/sample.h5 --output heatmap.pdf
pycellchat db list
pycellchat version
Contributing
pip install -e ".[dev]"
pip install -r requirements-dev.txt
pre-commit install
ruff check pycellchat/
pytest tests/ -x -q
Critical constraint: pycellchat/core/cellchat.py and pycellchat/utils/stats.py are parity-locked to R CellChat. Do not modify any mathematical operation, aggregation logic, permutation semantics, or filtering logic in these files without a full R comparison.
Development assistance
Portions of this project were developed with the assistance of Claude (Anthropic) — for algorithmic optimisation, code cleanup, test scaffolding, and documentation. All AI-assisted code was reviewed and validated by the author, who retains full responsibility for the methods, results, and their scientific interpretation.
Citation
If you use pyCellChat, please cite the manuscript:
Khadim, A., Bartkuhn, M., Seeger, W., El Agha, E. Donors, not cells, are the exchangeable units for differential cell-cell communication analysis. bioRxiv (2026). doi: pending — a preprint will be posted ahead of peer-reviewed submission; this entry will be updated with the bioRxiv DOI once it is assigned.
A peer-reviewed manuscript is in preparation and not yet published. Until a DOI is available, please also cite this repository together with the specific version or commit hash used (see CITATION.cff), so results remain reproducible.
CellChat (algorithm reference):
Jin, S. et al. Inference and analysis of cell-cell communication using CellChat. Nat Commun 12, 1088 (2021). https://doi.org/10.1038/s41467-021-21246-9
Validation datasets used in this repository's benchmarks:
Jaiswal, A., Kooistra, T., Pokatayev, V. et al. Spatial transcriptomics reveals altered communities and drivers of aberrant epithelia and pro-fibrotic fibroblasts in interstitial lung diseases. Cell Genomics (2026). https://doi.org/10.1016/j.xgen.2025.101066
Sikkema, L. et al. An integrated cell atlas of the lung in health and disease. Nat Med 29, 1563-1577 (2023). https://doi.org/10.1038/s41591-023-02327-2
Data and code availability
pyCellChat, captured R failure logs, per-cohort parity tables, term-by-term audits, stratified sampling comparisons, competitor benchmarks, hierarchical null calibration, cross-tool replication, real-data pseudo-null analyses, multiplicity-reachability analyses, developmental-trajectory network screens, timing tables, memory tables, and run-level provenance records are available in this repository (documentation/provenance/, further indexed in that directory's README). pyCellChat is released under the MIT licence and distributed on PyPI as pycellchat.
Authors
Ali Khadim · Institute for Lung Health (ILH), Universities of Giessen and Marburg Lung Center (UGMLC), Giessen, Germany
License: MIT
Metadata
Release files for pycellchat 1.6.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 | Provenance | Actions |
|---|---|---|---|---|
| pycellchat-1.6.0.tar.gz | 823.4 kB | Without provenance | Details for pycellchat-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycellchat-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for pycellchat-1.6.0-py3-none-any.whl |
Total release size: 1.6 MB
Release files / pycellchat-1.6.0.tar.gz
| Download URL | pycellchat-1.6.0.tar.gz |
|---|---|
| Size | 823.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
206417f8dcbe825ab6982c441d973c44691205429d48cca4ff4421d6ef433a8e
|
|
BLAKE2b-256 checksum How to use checksums |
e5ba17d0c7708d88579cc54fa36fb63353af3afbeebaa78c18475c4697546d26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / pycellchat-1.6.0-py3-none-any.whl
| Download URL | pycellchat-1.6.0-py3-none-any.whl |
|---|---|
| Size | 823.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5467a303479b380842a5b26c1b1b9f9b9dd5f029721245c1f07b4a928a0b03d9
|
|
BLAKE2b-256 checksum How to use checksums |
d4c593e9af3fb1fb03bd561ef0a30df2b859dddd2a9ced2420e9e656570fe028
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for pycellchat 1.6.0
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.