Spatial multiomics primitives (neighbour graphs, Moran's I, nhood enrichment, Ripley, co-occurrence) — Python bindings.
Project description
sm-rust — Python bindings
Spatial multiomics primitives from the sm-rust crate (neighbour graphs, Moran's I, Geary's C, neighbourhood enrichment, Ripley F/G/L, co-occurrence, ligand-receptor, sepal, niche detection), exposed to Python via PyO3 + maturin.
Layout
sm_rust._native— the compiled extension module:Cells,Neighbors, everycompute_*function returning result dataclass-like objects with numpy arrays. Mirrors the Node/wasm binding surface.sm_rust.gr— squidpy-shaped wrappers that consumeAnnDatadirectly:spatial_neighbors,spatial_autocorr,nhood_enrichment,interaction_matrix,centrality_scores,co_occurrence,ripley,ligrec,sepal. The output shape (column names,.unskeys) matchessquidpy.grso existing notebooks can drop this in.
Build (host)
pip install maturin
maturin develop --release --features python-bindings,parallel
Build (docker, recommended)
The repo's docker-compose.yml ships a pyo3 service that builds a wheel
into python/dist/:
docker compose run --rm pyo3
Quick start
Low-level API:
import numpy as np
from sm_rust import _native as sm
cells = sm.cells_from_coords_py(np.random.rand(1000), np.random.rand(1000))
labels = np.random.randint(0, 3, 1000).astype(np.uint8)
neighbors = sm.Neighbors.knn(6)
res = sm.compute_nhood_enrichment_py(cells, labels, neighbors, n_clusters=3)
print(res.count.reshape(3, 3))
print(res.zscore.reshape(3, 3))
squidpy-style API:
import sm_rust as smr
import anndata as ad
smr.gr.spatial_neighbors(adata, coord_type="generic", n_neighs=6)
smr.gr.spatial_autocorr(adata, mode="moran", genes=adata.var_names[:50])
smr.gr.nhood_enrichment(adata, cluster_key="leiden")
Project details
Release history Release notifications | RSS feed
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 sm_rust-0.0.1.tar.gz.
File metadata
- Download URL: sm_rust-0.0.1.tar.gz
- Upload date:
- Size: 2.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b885bc17ca62963f6df1325ef0d878be27be979b7055f654fdceab46d2c3d05f
|
|
| MD5 |
8a7e5b18509da6c3cbbcbfb4078b4fd7
|
|
| BLAKE2b-256 |
09b04417300a7ca396576aca469cf4b7977140234861825f2ae545a4486f29ed
|
File details
Details for the file sm_rust-0.0.1-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sm_rust-0.0.1-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 932.8 kB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b77829cf3a02b7f0637a253eafb220b2f662ee793cca25aef99437eacbbcb2a
|
|
| MD5 |
0d9f44dab80ac8689051ffc1c9b0b0ca
|
|
| BLAKE2b-256 |
4401bdc7a80bb36176c941e127e75e708d5539624ee31fdf42a5b391005032a1
|