Installation¶
kdomainbench is a Python package on PyPI. The ten
methods run in three environments: two conda environments for the Python methods and your own
R for the R methods. kDomainBench starts each method in the right one.
| You need | For |
|---|---|
| Linux (x86-64) | running the methods. The environments are built for it |
| conda or mamba (Miniforge) | the two Python environments, about 12 GB of disk |
A C++ compiler, cmake and git |
building louvain for SpaGCN, fetching SpatialDE2, and the R packages |
| R ≥ 4.4 | the six R methods. The four Python methods run without it |
| R ≥ 4.5 with Bioconductor ≥ 3.22 (optional) | the twelve metrics of the paper (The metric packages) |
| An NVIDIA GPU with driver ≥ 525 (optional) | CellCharter, DeepST and SpatialDE2 can use one. The GPU libraries come with the environments |
macOS and Windows
The methods run on Linux only. Scoring and plotting finished runs works on any system with Python 3.10 or later, and needs only the package:
Summary
Step 1: Install the package¶
Any Python 3.10 or later will do, for example a conda environment of your own. The package brings one script per method, the two environment files and the installer of the R packages.
From the repository
The repository holds the same package (src/kdomainbench/) and the example file (data/).
Its script creates the two conda environments of step 2 and installs kdomainbench into
kdb_py, so that one environment holds the package and three of the methods:
git clone https://github.com/PYangLab/domainNumber.git && cd domainNumber
bash envs/install_envs.sh
conda activate kdb_py
KDB_ENVS_DIR=/project/envs bash envs/install_envs.sh creates them in that folder instead
of conda's default one. Activate kdb_py then by its path:
conda activate /project/envs/kdb_py. Continue with R in step 2.
Step 2: Create the environments¶
Which method runs where:
| Environment | Methods | Main contents |
|---|---|---|
kdb_py |
CellCharter, DeepST, SpaGCN | Python 3.12.8, torch 2.5.1 + CUDA 12.4, torch_geometric 2.8.1, scanpy 1.10.3, scvi-tools 1.4.1, cellcharter 0.3.7, deepstkit 2.0.3, SpaGCN 1.2.7, squidpy 1.8.3 |
kdb_spatialde |
SpatialDE2 | Python 3.10, tensorflow[and-cuda] 2.15.1, tensorflow-probability 0.23.0, gpflow 2.9.2, numpy 1.26.4, SpatialDE 2.0.0 |
| your R | PRECAST, SC.MEB, BayesSpace, BNPSpace, DR.SC, iSC.MEB | R ≥ 4.4 with the packages below |
The Python environments¶
This creates the conda environments kdb_py and kdb_spatialde, with the package versions
fixed in their environment files. The same environments run on machines with and without a
GPU. An environment that is there already is left as it is.
The two environments hold the methods. Keep working in the Python of step 1, which has
kdomainbench.
With KDB_ENVS_DIR=/project/envs set, the environments are created in that folder instead of
conda's default one. Keep the variable set afterwards: it is where they are looked for.
R¶
The R methods use the R you already have (R ≥ 4.4, with Bioconductor 3.19 or later). Install the packages the methods need:
The command installs only what is missing, from CRAN and Bioconductor, at their current versions. It installs into R's main library, or into your personal library when the main one is read-only, as with an R from a module.
| Source | Packages |
|---|---|
| CRAN | PRECAST, DR.SC, Seurat, Rcpp, RcppArmadillo, flexclust, philentropy, fastcluster, dynamicTreeCut, purrr, deldir, glue, ggplot2, mclust (plus remotes and BiocManager to install the rest) |
| Bioconductor | BayesSpace, zellkonverter, SingleCellExperiment, SummarizedExperiment, scran, scater, scuttle, BiocSingular |
| CRAN archive | SC.MEB 1.1 (no longer on CRAN) |
| GitHub | iSC.MEB 1.0, from its authors' repository (no longer on CRAN) |
BNPSpace is not a package. Its C++ code ships with kDomainBench and is compiled at the start of each run.
A separate R library
To keep these packages apart from your other R work, name a folder in KDB_R_LIB. The
packages are installed there, and the R methods then see only this library and base R.
The metric packages¶
This step is optional. kdb.evaluate scores a run with k error, ARI and NMI and needs nothing
more. The twelve metrics of the paper (Evaluate a run)
are computed by the paper's own code, whose R part needs these packages:
| Source | Packages |
|---|---|
| CRAN | clevr, aricode, ClusterR |
| Bioconductor | spARI, zellkonverter, SummarizedExperiment, HDF5Array, rhdf5 |
| GitHub, at the commits used for the paper | lisi, SPARK, SpatialPCA |
spARI is in Bioconductor from release 3.22, which needs R ≥ 4.5. The command that installs them depends on your R:
Your R (Rscript -e 'BiocManager::version()' gives the Bioconductor release) |
What to do |
|---|---|
| R ≥ 4.5 on Bioconductor ≥ 3.22 | kdomainbench install metrics. With KDB_R_LIB set, they go to that library |
| R ≥ 4.5 on Bioconductor 3.21 | update Bioconductor first: Rscript -e 'BiocManager::install(version = "3.22")' |
| R 4.4 or older | install R ≥ 4.5 next to it, export KDB_METRICS_RSCRIPT=/path/to/R-4.5/bin/Rscript, then kdomainbench install metrics |
kdomainbench check --metrics computes the twelve metrics on a small test sample.
Step 3: Verify the install¶
python -c "import kdomainbench as kdb; print(kdb.__version__)" # the package version
kdomainbench check
kdomainbench check starts each environment once and prints what it finds:
[py] /opt/conda/envs/kdb_py/bin/python
torch 2.5.1+cu124 | CUDA available: False
[spatialde] /opt/conda/envs/kdb_spatialde/bin/python
tensorflow 2.15.1 | GPUs: 0
[r] /usr/bin/Rscript
PRECAST 1.7
SC.MEB 1.1
BayesSpace 1.14.0
DR.SC 3.6
iSC.MEB 1.0
zellkonverter 1.14.1
reads .h5ad files: 3 spots
For R it checks every package the method scripts load, then reads a small .h5ad file. The
first read downloads the reader that zellkonverter uses, which needs internet access once
(Troubleshooting).
An environment that is missing or broken prints MISSING or FAILED with the reason, and the
command exits with an error. On a GPU machine, kdomainbench check --gpu should report
CUDA available: True and GPUs: 1, and fails when no GPU is visible.
Example data¶
The tutorials use the DLPFC Visium sample 151509 from the spatialLIBD study (Maynard et al., Nature Neuroscience 2021 and spatialLIBD). Each spot carries the study's manual annotation of six cortical layers (Layer1–Layer6) and white matter (WM). This is the reference annotation. It has 7 domains, so the reference domain number is k = 7.
The file is data/D3_151509_5k.h5ad (14 MB), and kdb.example_data() downloads it: D3 is the number of the
dataset in the benchmark, and 5k its rounded number of spots. It is the benchmark's copy of
the sample, filtered beforehand. It holds 4,786 spots and the 10,486 genes that had at least
100 UMIs when the file was built (var["n_counts"]). The script that built it is not in this
repository. A cloned folder already has the file.
What the file contains
X: raw UMI countsobs_names: the spot barcodes. Most carry a.1or.2suffix from the benchmark's copy (AAACAAGTATCTCCCA-1.2), so they differ from the original Space Ranger barcodesobs["array_row"],obs["array_col"]: Visium grid coordinatesobsm["spatial"]: 2-D spot coordinatesobs["clusters"]: the annotated domain of each spot (Layer1…Layer6,WM)obs["pixel_row"],obs["pixel_col"]: pixel coordinates (read by SpaGCN)
Run a method lists which field each method reads.
When a step fails, see Troubleshooting.