Skip to main content

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, every compute_* function returning result dataclass-like objects with numpy arrays. Mirrors the Node/wasm binding surface.
  • sm_rust.gr — squidpy-shaped wrappers that consume AnnData directly: spatial_neighbors, spatial_autocorr, nhood_enrichment, interaction_matrix, centrality_scores, co_occurrence, ripley, ligrec, sepal. The output shape (column names, .uns keys) matches squidpy.gr so 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sm_rust-0.0.1.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sm_rust-0.0.1-cp39-abi3-manylinux_2_34_x86_64.whl (932.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

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

Hashes for sm_rust-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b885bc17ca62963f6df1325ef0d878be27be979b7055f654fdceab46d2c3d05f
MD5 8a7e5b18509da6c3cbbcbfb4078b4fd7
BLAKE2b-256 09b04417300a7ca396576aca469cf4b7977140234861825f2ae545a4486f29ed

See more details on using hashes here.

File details

Details for the file sm_rust-0.0.1-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for sm_rust-0.0.1-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1b77829cf3a02b7f0637a253eafb220b2f662ee793cca25aef99437eacbbcb2a
MD5 0d9f44dab80ac8689051ffc1c9b0b0ca
BLAKE2b-256 4401bdc7a80bb36176c941e127e75e708d5539624ee31fdf42a5b391005032a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page