This release is a pre-release and may not be stable for production use.
spatialrna
Spatial RNA graph data processing and analysis for single-molecule spatial transcriptomics (10x Xenium and Atera): transcripts → tile graphs and subgraphs → any graph neural network (train / validate / embed) → clusters → spatial maps.
This continues the lab's spatialrna 0.2 (Ruqian Lyu) with the same scope and adds
reading of raw Xenium / Atera outputs, zarr storage, a fast KD-tree graph builder,
balanced grid tiling for large sections, and GPU Gaussian mixtures. The ISTIST
pipeline builds on it with its own model (CrossSampleGAT), transcript-level
annotation, statistics and an HTML report.
Install
pip install -e . # readers, graph builders, clustering, maps (no torch)
pip install -e ".[gnn]" # + SpatialRNA dataset, datasets, train_val
# (install torch + PyG for your CUDA first)
Python >= 3.10, zarr-python >= 3.
Modules
| module | what it does | 0.2 equivalent | needs torch |
|---|---|---|---|
readers |
Xenium / Atera transcripts.zarr.zip → transcripts (layout auto-detected) |
– | no |
graph_build |
KD-tree radius graphs, subgraph sampling, plan_tiles (grid tiling) |
– | no |
graph_zarr_io |
SpatialRNA: tiles (strips or grid) + padding → radius graphs → subgraphs, zarr I/O |
spatialrna.py |
yes |
datasets |
ZarrGraphDataset over many tile / subgraph stores |
spatialrna_ondisk.py |
yes |
train_val |
model-agnostic link-prediction training / validation, embed_tile |
train_val.py |
yes |
cluster |
gmm (GPU or numpy EM), kmeans |
run_kmeans.py |
optional |
viz |
pixel_map, two-panel overviews, one panel per label |
viz.py |
no |
Quick start
import numpy as np, torch
import spatialrna as sr
df = sr.readers.load_transcripts("/path/to/output") # x, y, z, qv, gene
print(sr.readers.describe("/path/to/output"))
# tile graphs (here: 100 near-square tiles with equal transcript counts)
# SpatialRNA(root="data/S01.zarr", sample_name="S01", cohort_zarr_path="data/cohort.zarr",
# num_tiles=100, tile_mode="grid", one_hot_encoding=enc, ...)
# train any model(x, edge_index) on the tiles / subgraphs
from spatialrna import train_val as tv
from spatialrna.datasets import ZarrGraphDataset
graphs = ZarrGraphDataset.from_sample_store("data/S01.zarr", kind="subgraphs")
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
loss, acc = tv.train_link_prediction(model, graphs, opt, device, num_genes)
emb, tx_id = tv.embed_tile(model, graphs[0], device, num_genes)
# clusters and a map
labels, gmm = sr.cluster.gmm(emb.numpy(), 12)
fig = sr.viz.pixel_map(x, y, labels)
Tiling
SpatialRNA(tile_mode="strips") (default, as in 0.2) cuts num_tiles equal-width
bands along tile_by_dim. tile_mode="grid" cuts near-square tiles with equal
transcript counts: no empty tiles in irregular tissue and little padding with many
tiles (~5–7 % at 500 tiles, vs ~40 % for 500 strips).
Tests
pip install -e ".[dev]"
pytest # test_zarr_roundtrip needs the [gnn] extra
Note on the name
spatialrna 0.1–0.2 on PyPI is maintained by Ruqian Lyu; this is 0.3.0.dev0.
Coordinate with her before uploading to PyPI under the same name.
Metadata
Release files for spatialrna 0.3.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| spatialrna-0.3.0.dev0.tar.gz | 46.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spatialrna-0.3.0.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 90.5 kB
Release files / spatialrna-0.3.0.dev0.tar.gz
| Download URL | spatialrna-0.3.0.dev0.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a9bf54057ec7ee88b840c47878c807f01381f53437a840b8d3734eeec5999f0
|
|
BLAKE2b-256 checksum How to use checksums |
115b138f7e15a29a63c080bf6b254736b392c12556110a88e106ca8c07a12784
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / spatialrna-0.3.0.dev0-py3-none-any.whl
| Download URL | spatialrna-0.3.0.dev0-py3-none-any.whl |
|---|---|
| Size | 44.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9491695632fc80897375edd3e30c43d8f885d2d502d76b30a79efabe374abd3
|
|
BLAKE2b-256 checksum How to use checksums |
2cd6bba5975209d27a9433e0e756b5c71f17da5a201702c7994087a93aab85ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for spatialrna 0.3.0.dev0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.