Metadata-Version: 2.5
Name: spatial-rx
Version: 0.1.0
Summary: Tools for exploring spatial omics data in notebooks
Project-URL: Homepage, https://github.com/ckmah/spatial-rx
Project-URL: Repository, https://github.com/ckmah/spatial-rx
Project-URL: Issues, https://github.com/ckmah/spatial-rx/issues
Author: ckmah
License: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.11
Requires-Dist: anywidget>=0.9.2
Requires-Dist: matplotlib>=3.0
Requires-Dist: numpy>=1.24
Requires-Dist: traitlets>=5.0
Provides-Extra: demo
Requires-Dist: altair>=6.2.2; extra == 'demo'
Requires-Dist: geopandas>=1.1.4; extra == 'demo'
Requires-Dist: marimo>=0.24.0; extra == 'demo'
Requires-Dist: pandas>=3.0.5; extra == 'demo'
Requires-Dist: scipy>=1.17.1; extra == 'demo'
Requires-Dist: shapely>=2.1.2; extra == 'demo'
Requires-Dist: tifffile>=2026.3.3; extra == 'demo'
Provides-Extra: test
Requires-Dist: pytest>=8.3.3; extra == 'test'
Description-Content-Type: text/markdown

# spatial-rx

Tools for exploring spatial omics data in notebooks — reactive widgets that stay  
in sync with your Python analysis.


| Tool                | Role                                                                           |
| ------------------- | ------------------------------------------------------------------------------ |
| **LandmarksWidget** | Draw selections and landmarks on tissue coordinates; measure from the notebook |
| **GalleryWidget**   | Compact card gallery (e.g. analysis recipes / use cases)                       |


More widgets and helpers may land here over time.

## Install

Library only:

```bash
pip install spatial-rx
```

From source (includes demo notebook deps and test tools):

```bash
uv sync --extra demo --group dev
```

## LandmarksWidget

An [anywidget](https://anywidget.dev/) for spatial coordinates: top tool bar, left
sidebar, drawing-only synced state.

- **Selections** — lasso, rectangle, rotatable ellipse
- **Landmarks** — point, line, spline, shape
- **Layer tools** — spline tension; directional buffer on lines/splines (`left` / `both` / `right`)

Use `get_mask` / `get_indices(selection_id=...)` to restrict points. Distance,
composition, gradient, and other tables belong in the notebook.

### Matplotlib (static figure)

```python
from spatial_rx import LandmarksWidget

w = LandmarksWidget(fig)
idx = w.get_indices(x, y, selection_id="selection 1")
```

### Scatter (pan / zoom)

Interactive points use [regl-scatterplot](https://github.com/flekschas/regl-scatterplot)
(same WebGL engine as [jupyter-scatter](https://github.com/flekschas/jupyter-scatter)).
In **Pan/Zoom** mode, navigate the scatter; switch to lasso / landmark tools to draw.

```python
from spatial_rx import LandmarksWidget

w = LandmarksWidget.from_points(x, y, color=cell_type, width=900, height=900)
w.set_color(gene_expression)  # update colors without rebuilding
idx = w.get_indices(x, y, selection_id="selection 1")
```

## Demo

Spatial transcriptomics playground (`demos/landmarks.py`; data under `demos/data/`):

[![Open in molab](https://marimo.io/molab-shield.svg)](https://molab.marimo.io/github/ckmah/spatial-rx/blob/main/demos/landmarks.py)

Or run locally:

```bash
git clone https://github.com/ckmah/spatial-rx.git
cd spatial-rx
uv sync --extra demo
uv run marimo edit demos/landmarks.py
```

