SpatialCore
Standardized spatial statistics for computational biology.
🎯 The Mission
The Problem
Tools for spatial biology analysis are fragmented. Implementations and complex functions often differ between languages (R vs Python) and across packages, making reproducibility difficult and benchmarking impossible. We believe simple statistical tools solve many of the core problems of spatial biology, and we have desinged them to be intuative, easy to use, and scaleable for millions of cells.
The Solution
SpatialCore serves as a package for computational biologists, by computational biologists. It provides robust, standardized implementations of core spatial statistics that ensure identical results across platforms, wrapping high-performance libraries where available.
The Goal
To make spatial analysis engineering boring, so you can focus on the exciting biology. Standardized. Scalable. Reproducible.
📖 See the full documentation: for modules, examples, and benchmarks mcap91.github.io/SpatialCore
⚖️ Philosophy
- Reproducibility: Same inputs = Same outputs. Period.
- Scalability: Built for the era of millions of cells (Xenium/CosMx).
- Transparency: Thin wrappers, not black boxes. We verify, we don't obfuscate.
- Documentation: Clear docstrings with academic references.
What we are NOT:
- Inventing new methods, alogithims, or complex solutions.
- Replacing Scanpy, Seurat, or other methods.
📦 Installation
Recommended: Conda/Mamba Environment
For the best experience, we recommend using a conda or mamba environment:
# Create environment with Python 3.11
mamba create -n spatialcore python=3.11
mamba activate spatialcore
# Install SpatialCore
pip install spatialcore
This installs all core Python dependencies including CellTypist for custom model training for cell type annotation.
Run upgrade to get the latest modules, features, and fixes
# Activate environment
mamba activate spatialcore
# Upgrade
pip install --upgrade spatialcore
R Requirements
SpatialCore uses R for certain operations that are statistically optimized or perform better in R. The r_bridge module handles R integration via subprocess (no rpy2 required).
Install R packages in your environment:
# If using conda/mamba (recommended)
mamba install -c conda-forge r-base r-sf r-concaveman r-dplyr r-purrr r-jsonlite
# If using system R (Linux/macOS)
sudo apt-get install r-base # Ubuntu/Debian
R -e "install.packages(c('sf', 'concaveman', 'dplyr', 'purrr', 'jsonlite'), repos='https://cloud.r-project.org/')"
Verify R is configured correctly:
from spatialcore.r_bridge import check_r_available, get_r_version
print(check_r_available()) # True
print(get_r_version()) # R version 4.x.x
How r_bridge Works
The r_bridge automatically detects your environment:
| Environment | R Execution Method |
|---|---|
| Conda/Mamba | mamba run -n env_name Rscript ... |
| System R | Rscript directly |
No manual configuration needed - it just works.
🚀 Quick Start
import scanpy as sc
import spatialcore
# Check what's available in your installation
spatialcore.print_info()
# SpatialCore v0.4.5
# Available modules: core, annotation, nmf, r_bridge, spatial, ...
# Load your spatial data
adata = sc.read_h5ad("spatial_data.h5ad")
# Spatial domain detection on B cells
from spatialcore.spatial import make_spatial_domains
from spatialcore.plotting import plot_domains
adata = make_spatial_domains(
adata,
filter_expression="hieratype_ontology_name == 'B cell'",
output_column="bcell_domain",
domain_prefix="Bcell",
platform="cosmx",
)
# Visualize spatial domains
plot_domains(adata, domain_col="bcell_domain", title="B Cell Domains")
🧩 Modules & Features
| Module | Status | Features |
|---|---|---|
spatialcore.annotation |
✅ Available | CellTypist wrappers, custom model training, benchmarking |
spatialcore.nmf |
✅ Available | Spatial non-negative matrix factorization (spaNMF) |
spatialcore.spatial |
✅ Available | Moran's I, Lee's L, spatial autocorrelation |
spatialcore.domains |
✅ Available | Neighborhood profiling, niche identification, domain detection |
spatialcore.thresholding |
✅ Available | Cell classification, oncogene thresholding |
spatialcore.r_bridge |
✅ Available | Seurat integration, R interoperability via subprocess |
spatialcore.diffusion |
🔜 Coming soon | Diffusion maps, pseudotime analysis |
📚 Terminology
We strictly define our spatial units to ensure clarity:
| Term | Definition |
|---|---|
| Neighborhood | The immediate spatial vicinity of a cell (e.g., k-Nearest Neighbors or fixed radius). |
| Niche | A functional microenvironment defined by a specific composition of cell types (e.g., "Tumor-immune border"). |
| Domain | A macroscopic, continuous tissue region with shared structural characteristics (e.g., "Cortex", "Medulla"). |
🤝 Ecosystem Integration
SpatialCore is designed to play nice with others. It fits seamlessly into the existing Python spatial biology stack:
- Scanpy: The backbone for single-cell analysis.
- Squidpy: Advanced spatial omics analysis.
- Seurat: Direct R interoperability for teams working across languages.
📝 Citation
If SpatialCore aids your research, please cite:
@software{spatialcore,
title = {SpatialCore: Standardized spatial statistics for computational biology},
url = {https://github.com/mcap91/SpatialCore},
license = {Apache-2.0}
}
License
Apache License 2.0
The SpatialCore name and trademarks are reserved to ensure the community can rely on the "Standardized" quality of the core library. You are free to use, modify, and distribute the code, including for commercial use.
Metadata
Release files for spatialcore 0.5.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 | |
|---|---|---|---|
| spatialcore-0.5.4.tar.gz | 1.1 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spatialcore-0.5.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.3 MB
Release files / spatialcore-0.5.4.tar.gz
| Download URL | spatialcore-0.5.4.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3149b5272a808ca10516cbde02de4a1222e0aba6bfe5716a4dcfcf468b151998
|
|
BLAKE2b-256 checksum How to use checksums |
b1d57ffe8435821eb0ff7732e59612a34fbec7b402edb3529961e053d09761a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 11, 2026.
Transparency logRelease files / spatialcore-0.5.4-py3-none-any.whl
| Download URL | spatialcore-0.5.4-py3-none-any.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c18e51d41ed340fa3aae5e33b860ccbf9433c4992f401617bdaaa4d56a52ebc8
|
|
BLAKE2b-256 checksum How to use checksums |
bb67169a529715c87aa0ef52c4670b0891b42c4aa9ba19f320219af583615cc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 11, 2026.
Transparency log