spatioloji_s
spatioloji_s is a Python package for image-based spatial transcriptomics analysis, purpose-built for CosMx, MERFISH, and Xenium. It provides an integrated workflow from raw data loading through quality control, processing, spatial analysis, and polygon-native cell-cell communication.
- PyPI: pypi.org/project/spatioloji-s
- GitHub: github.com/gynecoloji/spatioloji_s
- License: MIT
Key Features
- Custom data structure --- A
spatiolojiobject that unifies expression matrices, cell metadata, spatial coordinates, cell polygons, and FOV images under a single master cell index. - Two spatial modes --- Point-based (centroid, fast) and polygon-based (boundary geometry, accurate) analysis with shared interface, gradient, infiltration, and motif APIs.
- Polygon-native CCC --- Cell-cell communication using actual membrane geometry, not centroid distance. Edge-level scoring with exponential distance decay, analytical and permutation significance testing, interface zone stratification, and morphology-aware analysis.
- 80+ visualization functions --- Embedding plots, spatial maps (dot and polygon), neighborhood enrichment, Ripley's K/L, morphology, CCC heatmaps/networks/gradients, motif maps, and more.
- Comprehensive processing --- Normalization, HVG selection (6 methods), PCA/UMAP/tSNE/diffusion maps, Leiden/KMeans/hierarchical clustering, DEG (5 methods), batch correction (ComBat, Harmony, scVI), imputation, and gene set scoring.
Installation
pip install spatioloji-s
Requires Python >= 3.12.
Optional extras:
pip install "spatioloji-s[clustering]" # Leiden (leidenalg + igraph)
pip install "spatioloji-s[reduction]" # UMAP
pip install "spatioloji-s[batch]" # Harmony, ComBat
pip install "spatioloji-s[deg]" # DESeq2, statsmodels
pip install "spatioloji-s[anndata]" # AnnData/scanpy interop
pip install "spatioloji-s[annotation]" # Cell type annotation (CellTypist)
pip install "spatioloji-s[decoupler]" # Pathway scoring
pip install "spatioloji-s[ripley]" # Ripley's K/L
pip install "spatioloji-s[all]" # All of the above
[all] covers every pip-installable analysis feature. The deep-learning
imputation backends are excluded on purpose — scVI and MAGIC are meant to run in
a dedicated environment (pass conda_env= to scvi_impute / magic_impute),
and pulling PyTorch into a default install costs several GB. Install them
in-process with pip install "spatioloji-s[imputation]" if you prefer.
Not sure what you have? spatioloji_s info lists every optional feature and
whether it is available.
Quick Start
import spatioloji_s as sj
# 1. Load data
sp = sj.spatioloji(
expression=expression_df,
cell_meta=cell_meta_df,
spatial_coords=spatial_df,
polygons=polygon_dict,
)
# 2. Process
sj.processing.normalize_total(sp)
sj.processing.log_transform(sp)
sj.processing.pca(sp)
sj.processing.umap(sp)
sj.processing.leiden_clustering(sp)
# 3. Spatial analysis
from spatioloji_s.spatial.polygon import build_buffer_graph, neighborhood_enrichment
graph = build_buffer_graph(sp, buffer_distance=15)
neighborhood_enrichment(sp, graph, "cell_type")
# 4. Cell-cell communication
from spatioloji_s.ccc import CCCConfig, run_ccc
config = CCCConfig(group_col="cell_type", layer="log_normalized")
result = run_ccc(sp, config)
# 5. Visualize
sj.visualization.plot_umap(sp, color_by="cell_type")
sj.visualization.plot_ccc_heatmap(result)
sj.visualization.plot_ccc_network(result)
Module Overview
| Module | Functions | Description |
|---|---|---|
sj.data |
12 | Core spatioloji object, QC, image handling, export |
sj.processing |
44 | Normalization, HVG, dim reduction, clustering, DEG, batch correction, imputation, gene sets |
sj.spatial.point |
30 | Centroid-based: KNN/radius/Delaunay graphs, neighborhoods, Moran's I, Getis-Ord, Ripley's K/L, motifs |
sj.spatial.polygon |
35 | Polygon-based: contact graphs, morphology, boundaries, neighborhoods, interface, gradient, infiltration, motifs |
sj.ccc |
14 | LR database, edge scoring, significance testing, zone/gradient/morphology stratification |
sj.visualization |
74 | Embedding, spatial maps, point/polygon analysis, CCC plots |
Cell-Cell Communication
spatioloji_s uses polygon geometry for biologically accurate CCC inference:
Scoring formula: score(i,j) = sqrt(L_i x R_j) x w_ij
| Signal type | Weight w_ij |
Graph |
|---|---|---|
| Juxtacrine | contact_frac_a x contact_frac_b |
Polygon contact graph |
| Secreted | exp(-distance / sigma) |
Radius graph (default 200 um) |
| ECM | exp(-distance / sigma) |
Radius graph |
Features:
- 50 built-in LR pairs + CellChatDB (3,234 interactions) support
- Analytical z-score (fast) or permutation significance testing with BH-FDR
- Interface zone comparison --- interface vs. interior enrichment
- Communication gradient --- OLS regression of score vs. signed distance
- Morphology stratification --- CCC by sender cell shape (round/elongated)
| Feature | CellChat | COMMOT | SpatialDM | spatioloji_s |
|---|---|---|---|---|
| Single-cell resolution | Partial | Yes | Partial | Yes |
| Polygon contact geometry | No | No | No | Yes |
| Spatial edge scoring | No | OT (centroid) | Moran's I | sqrt(LR) x w |
| Interface zone analysis | No | No | No | Yes |
| Communication gradient | No | No | No | Yes |
| Morphology stratification | No | No | No | Yes |
| Significance testing | Permutation | No | Permutation | Both |
Spatial Analysis Highlights
Interface & Gradient
from spatioloji_s.spatial.polygon import identify_interface, compute_gradient
iface = identify_interface(sp, group_col="cell_type", region_a="Tumor", region_b="Stroma")
grad = compute_gradient(sp, iface, genes=["TGFB1", "VIM"])
Morphology
from spatioloji_s.spatial.polygon import compute_morphology, classify_morphology
compute_morphology(sp, store=True) # area, circularity, elongation, solidity, ...
classify_morphology(sp) # round / intermediate / elongated
Spatial Motifs
from spatioloji_s.spatial.polygon import run_motif_pipeline
motifs = run_motif_pipeline(sp, graph, group_col="cell_type", match_builtin="TME")
# Built-in: TLS, tumor buds, immune aggregate, perivascular niche, immune desert
Data Structure
The spatioloji object stores all data aligned to a master cell index:
| Component | Type | Description |
|---|---|---|
sp.expression |
ExpressionMatrix |
Sparse/dense gene x cell matrix (auto-switched) |
sp.cell_meta |
pd.DataFrame |
Per-cell metadata, QC metrics, cluster labels |
sp.gene_meta |
pd.DataFrame |
Per-gene metadata (NegProbe flags, HVG status) |
sp.spatial |
SpatialData |
Global and local x/y coordinates |
sp.polygons |
GeoDataFrame |
Cell boundary polygons (Shapely) |
sp.images |
ImageHandler |
Lazy-loaded FOV images with LRU cache |
sp.embeddings |
dict |
PCA, UMAP, tSNE, diffusion map coordinates |
sp.layers |
dict |
Named expression layers (raw, normalized, scaled) |
Examples
Example notebooks are being reworked alongside the documentation rebuild. The workflows they cover:
- Basic Workflow --- Loading, QC, normalization, clustering, visualization
- Spatial Analysis --- Graphs, neighborhoods, Moran's I, interface detection
- CCC Analysis --- LR scoring, significance, zone comparison, morphology
- Interface Detection --- Tumor-stroma boundary, gradient analysis
- Pathway Scoring --- Gene set analysis via decoupler
Citation
If you use spatioloji_s in your research, please cite it. Use the "Cite this
repository" button on the GitHub repository page (generated from
CITATION.cff), or cite the archived release on Zenodo via the
DOI badge above --- the concept DOI always resolves to the latest version.
License
MIT License --- see LICENSE for details.
Contributing
Contributions are welcome! See CONTRIBUTING.md.
git clone https://github.com/gynecoloji/spatioloji_s.git
cd spatioloji_s
pip install -e ".[test]"
pytest tests/ -v
ruff check src/ tests/ --fix
Commits follow Conventional Commits;
versioning, CHANGELOG.md, and releases are automated with
release-please. See RELEASING.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spatioloji_s-0.4.4.tar.gz.
File metadata
- Download URL: spatioloji_s-0.4.4.tar.gz
- Upload date:
- Size: 363.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c05cfd74adbf36921dcea821c6ac811fa50db41153ab58239a2bd620ddf0ba0
|
|
| MD5 |
f96c377a953c3619c53bb12af6225eb4
|
|
| BLAKE2b-256 |
038592debe62264db5f5f9b6f0b4ac50cf2808a9ed34a4cfc828deae2b77e8f4
|
Provenance
The following attestation bundles were made for spatioloji_s-0.4.4.tar.gz:
Publisher:
publish.yml on gynecoloji/spatioloji_s
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatioloji_s-0.4.4.tar.gz -
Subject digest:
1c05cfd74adbf36921dcea821c6ac811fa50db41153ab58239a2bd620ddf0ba0 - Sigstore transparency entry: 2336206751
- Sigstore integration time:
-
Permalink:
gynecoloji/spatioloji_s@57e79c4b52034d03d9e275a9d0e176610e712f83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gynecoloji
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57e79c4b52034d03d9e275a9d0e176610e712f83 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spatioloji_s-0.4.4-py3-none-any.whl.
File metadata
- Download URL: spatioloji_s-0.4.4-py3-none-any.whl
- Upload date:
- Size: 335.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
203b165ec4e80cc6585b3b44798e778d9901f5c97c9685308ddc36786fec0ec4
|
|
| MD5 |
23bff675318e353e16df36de7529d125
|
|
| BLAKE2b-256 |
616e15761189a840eaee17bbdfe3f6cc7c1d1ea91413ccbb18e78560ad0f21fb
|
Provenance
The following attestation bundles were made for spatioloji_s-0.4.4-py3-none-any.whl:
Publisher:
publish.yml on gynecoloji/spatioloji_s
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spatioloji_s-0.4.4-py3-none-any.whl -
Subject digest:
203b165ec4e80cc6585b3b44798e778d9901f5c97c9685308ddc36786fec0ec4 - Sigstore transparency entry: 2336206831
- Sigstore integration time:
-
Permalink:
gynecoloji/spatioloji_s@57e79c4b52034d03d9e275a9d0e176610e712f83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/gynecoloji
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57e79c4b52034d03d9e275a9d0e176610e712f83 -
Trigger Event:
workflow_dispatch
-
Statement type: