See which single cells send and receive each ligand-receptor signal, with no clustering.
hypercom gives every cell a sender and receiver score for each ligand-receptor pair, then ranks the pairs that drive communication in your data. With a condition column, pairs whose cells concentrate in some conditions rank higher. Start from an AnnData or a counts table. It is the Python version of the R package HyperCom: the same method and results.
- Optional GPU acceleration: on an NVIDIA GPU, about 10× faster (timings).
Paper: HyperCom: a hypergraph-based method to infer cell-resolved cell-cell communication (bioRxiv, 2026).
Using R? Install the R package HyperCom instead: the same method and results, from a Seurat object, a SingleCellExperiment or a counts matrix. GPU acceleration is in Python only.
Python 3.10 or newer, on Windows, macOS (Intel or Apple) or Linux:
pip install hypercom --find-links https://github.com/pawelab/HyperCom-py/releases/expanded_assets/v0.2.1
pip install scanpy # optional: plots and 10x readersCheck that it works: run the quick start (under a minute).
Install from source (latest code; needs a C++ compiler)
pip install "hypercom @ git+https://github.com/pawelab/HyperCom-py"| System | C++ compiler |
|---|---|
| Windows | Visual Studio Build Tools, workload "Desktop development with C++" |
| macOS | xcode-select --install in the Terminal |
| Linux | sudo apt install build-essential (Ubuntu, Debian) or sudo dnf install gcc-c++ (Fedora, RHEL) |
GPU (optional, NVIDIA): about 10× faster
pip install "cupy-cuda12x[ctk]"- Needs an NVIDIA GPU of the RTX 30 series, A100 or newer, with driver 527.41 or newer (Windows) or 525.60.13 (Linux). No CUDA
toolkit:
[ctk]brings NVIDIA's compiler (about 2.3 GB). - CUDA 13 works too:
pip install "cupy-cuda13x[ctk]"instead, with a driver of the 580 series or newer. Install only one of the two. - Automatic: hypercom uses the GPU when it finds one and the data are big enough.
backend="cpu"orbackend="gpu"chooses. Same results either way. - First run compiles the GPU code (15 to 30 s); later runs reuse it.
- Not working?
hypercom.kernel_gpu.gpu_status()says what is missing. On Windows, keep the Python environment in a folder whose path has only plain (ASCII) letters. CuPy's warning "CUDA path could not be detected" is harmless.
On the bundled example: 1,000 mouse heart cells, two conditions (SHAM, TAC). Takes under a minute.
import hypercom
adata = hypercom.load_example() # an AnnData: log-normalized counts, metadata in adata.obs
lrdb = hypercom.load_lrdb("mouse") # CellChat ligand-receptor pairs; "human" for human data
res = hypercom.run_anndata(adata, lrdb, sample="sample", group="condition", significance=True, seed=1)
print(res.priority[1].head()) # pairs ranked by priority, with p and p_adj
scores = res.score("Thbs1", "Sdc4") # every cell as sender and receiver of one pair
hypercom.add_scores(adata, scores, key="thbs1_sdc4") # into adata.obs, e.g. adata.obs["thbs1_sdc4_hypercom"]Plot the cell scores (needs scanpy):
import scanpy as sc
sc.pl.umap(adata, color="thbs1_sdc4_hypercom", cmap="coolwarm", vcenter=0) # senders < 0 < receiversCheck these four things first:
- Database matches your species:
hypercom.load_lrdb("human")(genes likeTGFB1) or"mouse"(Tgfb1). Genes are gene symbols, not Ensembl IDs. sample(optional) names theadata.obscolumn that holds the sample (library or replicate). Cells are compared only within their sample; withoutsample, all cells are one sample.group(optional) names the condition column: pairs whose cells concentrate in some conditions rank higher. There is one ranking for the whole dataset, not one per condition.- No negative expression values: raw or log-normalized counts are fine; scaled data is not. If X is scaled,
run_anndatareadsadata.raw, or the layer you name:layer="counts". - Cell names are unique. When you merge samples, add the sample name to each barcode:
anndata.concat({"s1": a1, "s2": a2}, label="sample", index_unique="-")does both.
Then pick the line that matches your data:
import anndata
import hypercom
import scanpy as sc
lrdb = hypercom.load_lrdb("human")
# AnnData, e.g. from an .h5ad file
adata = anndata.read_h5ad("data.h5ad")
res = hypercom.run_anndata(adata, lrdb, sample="sample", group="condition")
# 10x Cell Ranger output: read it, then run_anndata as above
adata = sc.read_10x_mtx("filtered_feature_bc_matrix") # or sc.read_10x_h5("filtered_feature_bc_matrix.h5")
# SpatialData (Xenium, CosMx, MERFISH, Visium through spatialdata-io)
res = hypercom.run_anndata(sdata.tables["table"], lrdb, sample="sample")
# Counts table (cells as rows) and a metadata table (one row per cell)
res = hypercom.run(lrdb, counts, metadata, sample="sample", group="condition")
# One sample, no conditions: counts alone
res = hypercom.run(lrdb, counts)Then look at the results:
res.priority[1] # ligand-receptor pairs, ranked (one table per weight; the default is 1)
scores = res.score("TGFB1", ["TGFBR1", "TGFBR2"]) # score per cell- Cell scores only:
prioritize=Falseskips ranking the pairs, which takes most of the run time; thenres.score()scores the pairs you choose. - P-values: add
significance=True, seed=1. - Output files: every result is also saved to
outdir(defaultHyperCom/in the working directory;outdir=Nonewrites none).run_anndataalso keeps the tables inadata.uns["hypercom"]. - Run stopped? Run the same call again. It continues where it stopped.
- Seurat or SingleCellExperiment? Use the R package, or save an
.h5adin R:zellkonverter::writeH5AD(Seurat::as.SingleCellExperiment(obj), "obj.h5ad"). - Imaging panels (a few hundred genes): many pairs drop out because their genes are not measured; the run says how many remain.
- All options (weights, threads, memory):
help(hypercom.run).
Time and memory grow with the square of the number of cells per sample: 1,000 cells take seconds, 20,000 cells in three
samples about a minute on 16 CPU threads. hypercom fits its scoring to the memory it has and is fastest with about 20 bytes per
pair of cells in the same sample, plus about 1.1 GB. It uses 90% of the computer's memory, or on Linux of the cluster job's limit;
on a cluster, give the job's memory: memory_gb=64.
| Scoring 20,000 cells | 16 CPU threads | GPU | Speed-up |
|---|---|---|---|
| without p-values | 55 s | 4.1 s | 13× |
| with p-values | 241 s | 22 s | 11× |
prioritize_lr on 104 ligand-receptor pairs (every 10th of the CellChat mouse pairs expressed) for 20,000 cells in three samples,
resampled from a mouse single-cell dataset. Intel i9-12900K (16 threads) vs NVIDIA RTX 5070 Ti (16 GB); the same results on both.
- Tutorial: the notebook docs/tutorial.ipynb walks through every step, the scores and how to plot them.
- Help:
help(hypercom.run),help(hypercom.run_anndata),help(hypercom.score_hypercom),help(hypercom.prioritize_lr). - Questions or bugs: open an issue.
- Cite: Moy and Przytycki, 2026, doi:10.64898/2026.09.30.755742.
Outputs
In res |
File in outdir |
Contents |
|---|---|---|
res.priority[1] |
6.priority/priority.1.csv |
pairs ranked by priority: interaction, ligand, receptor subunits r1, r2, ..., priority; with significance, p and p_adj |
res.score(ligand, receptors) |
per cell: sender, receiver, dif, avg, max and hypercom (negative for senders, positive for receivers) | |
res.metadata |
5.metadata.csv |
cell, sample, group (and keep columns) of every node; genes have "gene" |
res.inf_mat |
4.inf_mat.npz |
influence matrix (hypercom.load_inf_mat) |
res.adj |
3.adj.npz |
adjacency of the hypergraph (hypercom.load_adjacency) |
res.lrs |
1.lrs.csv |
interactions whose genes are all expressed |
0.counts.h5ad, 2.hyperedges.csv |
counts of the ligand and receptor genes; hyperedges |
In adata.uns["hypercom"] the tables are keyed by the weight as text: adata.uns["hypercom"]["priority"]["1"].
Coming from R
| R | Python |
|---|---|
HyperCom(), HyperCom_seurat(), HyperCom_sce() |
hypercom.run(), hypercom.run_anndata() |
res$priority[["1"]], res$infMat |
res.priority[1], res.inf_mat |
score_hypercom(res$infMat, res$metadata, ...) |
res.score(...) or hypercom.score_hypercom(res.inf_mat, res.metadata, ...) |
generate_infMat(), infmat.method |
generate_inf_mat(), inf_mat_method |
exact.priority, memory.gb |
exact_priority, memory_gb |
column p.adj |
p_adj |
cellchat.mm.lrdb, alexanian2021.counts |
load_lrdb("mouse"), load_example() |
| gene x cell counts | cell x gene (AnnData) |
files .rds |
.h5ad, .npz, .csv |
The steps run one by one as in R: filter_counts, generate_lrs_table, generate_hyperedges, generate_adjacency_matrix,
generate_inf_mat, generate_metadata, prioritize_lr (no files unless given outfile / outdir). A run stopped in R cannot
be resumed in Python or the reverse.
How exact is it?
- The same as R. Scoring, ranking and the influence matrix use the R package's own C++ code. Started from the same data, the scores, priorities, p-values and order are R's to the last bit (rarely, a screened priority differs by 1 in the last digit); the test suite checks this against R's outputs.
- P-values use numpy's random numbers, so with the same
seedthey differ from R's by sampling. For R's exact p-values, pass R's background pairs:hypercom.prioritize_lr(..., background=r_background).
5C65
- Results do not depend on
threadsor on CPU vs GPU. - R HyperCom 0.3.2 and older inverted the influence matrix with LAPACK, so their results differ from today's in the last bits (about 1e-14).