Metadata-Version: 2.4
Name: sm-rust
Version: 0.0.1
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Dist: numpy>=1.22
Requires-Dist: anndata>=0.10 ; extra == 'anndata'
Requires-Dist: pandas>=2.0 ; extra == 'anndata'
Requires-Dist: scipy>=1.10 ; extra == 'anndata'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: anndata>=0.10 ; extra == 'test'
Requires-Dist: pandas>=2.0 ; extra == 'test'
Requires-Dist: scipy>=1.10 ; extra == 'test'
Provides-Extra: anndata
Provides-Extra: test
License-File: LICENSE
Summary: Spatial multiomics primitives (neighbour graphs, Moran's I, nhood enrichment, Ripley, co-occurrence) — Python bindings.
Keywords: spatial,multiomics,bioinformatics,squidpy,anndata
Author-email: Francisco Couzo <franciscouzo@gmail.com>
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# sm-rust — Python bindings

Spatial multiomics primitives from the [sm-rust](https://github.com/nadeemlab/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](https://pyo3.rs/) + [maturin](https://www.maturin.rs/).

## 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)

```bash
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/`:

```bash
docker compose run --rm pyo3
```

## Quick start

Low-level API:

```python
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:

```python
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")
```

