spatialrna 0.2.0__tar.gz → 0.3.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. spatialrna-0.3.0.dev0/PKG-INFO +102 -0
  2. spatialrna-0.3.0.dev0/README.md +78 -0
  3. spatialrna-0.3.0.dev0/pyproject.toml +40 -0
  4. spatialrna-0.3.0.dev0/src/spatialrna/__init__.py +60 -0
  5. spatialrna-0.3.0.dev0/src/spatialrna/cluster.py +473 -0
  6. spatialrna-0.3.0.dev0/src/spatialrna/datasets.py +51 -0
  7. spatialrna-0.3.0.dev0/src/spatialrna/graph_build.py +350 -0
  8. spatialrna-0.3.0.dev0/src/spatialrna/graph_zarr_io.py +1022 -0
  9. spatialrna-0.3.0.dev0/src/spatialrna/readers.py +313 -0
  10. spatialrna-0.3.0.dev0/src/spatialrna/train_val.py +129 -0
  11. spatialrna-0.3.0.dev0/src/spatialrna/viz.py +326 -0
  12. spatialrna-0.3.0.dev0/src/spatialrna.egg-info/PKG-INFO +102 -0
  13. spatialrna-0.3.0.dev0/src/spatialrna.egg-info/SOURCES.txt +19 -0
  14. spatialrna-0.3.0.dev0/src/spatialrna.egg-info/requires.txt +15 -0
  15. spatialrna-0.3.0.dev0/tests/test_cluster_viz.py +30 -0
  16. spatialrna-0.3.0.dev0/tests/test_readers.py +99 -0
  17. spatialrna-0.3.0.dev0/tests/test_tiling.py +38 -0
  18. spatialrna-0.3.0.dev0/tests/test_zarr_roundtrip.py +133 -0
  19. spatialrna-0.2.0/LICENSE.txt +0 -21
  20. spatialrna-0.2.0/PKG-INFO +0 -66
  21. spatialrna-0.2.0/README.md +0 -43
  22. spatialrna-0.2.0/pyproject.toml +0 -48
  23. spatialrna-0.2.0/spatialrna/__init__.py +0 -1
  24. spatialrna-0.2.0/spatialrna/run_kmeans.py +0 -113
  25. spatialrna-0.2.0/spatialrna/spatialrna.py +0 -352
  26. spatialrna-0.2.0/spatialrna/spatialrna_ondisk.py +0 -74
  27. spatialrna-0.2.0/spatialrna/train_val.py +0 -387
  28. spatialrna-0.2.0/spatialrna/viz.py +0 -188
  29. spatialrna-0.2.0/spatialrna.egg-info/PKG-INFO +0 -66
  30. spatialrna-0.2.0/spatialrna.egg-info/SOURCES.txt +0 -18
  31. spatialrna-0.2.0/spatialrna.egg-info/requires.txt +0 -9
  32. spatialrna-0.2.0/tests/test_data.py +0 -225
  33. spatialrna-0.2.0/tests/test_reload.py +0 -137
  34. spatialrna-0.2.0/tests/test_subgraph.py +0 -98
  35. spatialrna-0.2.0/tests/test_subgraph_mode.py +0 -136
  36. {spatialrna-0.2.0 → spatialrna-0.3.0.dev0}/setup.cfg +0 -0
  37. {spatialrna-0.2.0 → spatialrna-0.3.0.dev0/src}/spatialrna.egg-info/dependency_links.txt +0 -0
  38. {spatialrna-0.2.0 → spatialrna-0.3.0.dev0/src}/spatialrna.egg-info/top_level.txt +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: spatialrna
3
+ Version: 0.3.0.dev0
4
+ Summary: Spatial RNA graph data processing and analysis for single-molecule spatial transcriptomics (Xenium / Atera): graphs, GNN training / embedding, clustering, spatial maps.
5
+ Author-email: Anne Pan <anne.pan@svi.edu.au>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: numpy
12
+ Requires-Dist: pandas
13
+ Requires-Dist: scipy
14
+ Requires-Dist: zarr>=3
15
+ Requires-Dist: numcodecs
16
+ Requires-Dist: tqdm
17
+ Requires-Dist: scikit-learn
18
+ Requires-Dist: matplotlib
19
+ Provides-Extra: gnn
20
+ Requires-Dist: torch; extra == "gnn"
21
+ Requires-Dist: torch_geometric; extra == "gnn"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest; extra == "dev"
24
+
25
+ # spatialrna
26
+
27
+ Spatial RNA graph data processing and analysis for single-molecule spatial
28
+ transcriptomics (10x Xenium and Atera): transcripts → tile graphs and subgraphs →
29
+ any graph neural network (train / validate / embed) → clusters → spatial maps.
30
+
31
+ This continues the lab's `spatialrna` 0.2 (Ruqian Lyu) with the same scope and adds
32
+ reading of raw Xenium / Atera outputs, zarr storage, a fast KD-tree graph builder,
33
+ balanced grid tiling for large sections, and GPU Gaussian mixtures. The ISTIST
34
+ pipeline builds on it with its own model (CrossSampleGAT), transcript-level
35
+ annotation, statistics and an HTML report.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install -e . # readers, graph builders, clustering, maps (no torch)
41
+ pip install -e ".[gnn]" # + SpatialRNA dataset, datasets, train_val
42
+ # (install torch + PyG for your CUDA first)
43
+ ```
44
+
45
+ Python >= 3.10, zarr-python >= 3.
46
+
47
+ ## Modules
48
+
49
+ | module | what it does | 0.2 equivalent | needs torch |
50
+ |---|---|---|---|
51
+ | `readers` | Xenium / Atera `transcripts.zarr.zip` → transcripts (layout auto-detected) | – | no |
52
+ | `graph_build` | KD-tree radius graphs, subgraph sampling, `plan_tiles` (grid tiling) | – | no |
53
+ | `graph_zarr_io` | `SpatialRNA`: tiles (strips or grid) + padding → radius graphs → subgraphs, zarr I/O | `spatialrna.py` | yes |
54
+ | `datasets` | `ZarrGraphDataset` over many tile / subgraph stores | `spatialrna_ondisk.py` | yes |
55
+ | `train_val` | model-agnostic link-prediction training / validation, `embed_tile` | `train_val.py` | yes |
56
+ | `cluster` | `gmm` (GPU or numpy EM), `kmeans` | `run_kmeans.py` | optional |
57
+ | `viz` | `pixel_map`, two-panel overviews, one panel per label | `viz.py` | no |
58
+
59
+ ## Quick start
60
+
61
+ ```python
62
+ import numpy as np, torch
63
+ import spatialrna as sr
64
+
65
+ df = sr.readers.load_transcripts("/path/to/output") # x, y, z, qv, gene
66
+ print(sr.readers.describe("/path/to/output"))
67
+
68
+ # tile graphs (here: 100 near-square tiles with equal transcript counts)
69
+ # SpatialRNA(root="data/S01.zarr", sample_name="S01", cohort_zarr_path="data/cohort.zarr",
70
+ # num_tiles=100, tile_mode="grid", one_hot_encoding=enc, ...)
71
+
72
+ # train any model(x, edge_index) on the tiles / subgraphs
73
+ from spatialrna import train_val as tv
74
+ from spatialrna.datasets import ZarrGraphDataset
75
+ graphs = ZarrGraphDataset.from_sample_store("data/S01.zarr", kind="subgraphs")
76
+ opt = torch.optim.Adam(model.parameters(), lr=1e-3)
77
+ loss, acc = tv.train_link_prediction(model, graphs, opt, device, num_genes)
78
+ emb, tx_id = tv.embed_tile(model, graphs[0], device, num_genes)
79
+
80
+ # clusters and a map
81
+ labels, gmm = sr.cluster.gmm(emb.numpy(), 12)
82
+ fig = sr.viz.pixel_map(x, y, labels)
83
+ ```
84
+
85
+ ## Tiling
86
+
87
+ `SpatialRNA(tile_mode="strips")` (default, as in 0.2) cuts `num_tiles` equal-width
88
+ bands along `tile_by_dim`. `tile_mode="grid"` cuts near-square tiles with equal
89
+ transcript counts: no empty tiles in irregular tissue and little padding with many
90
+ tiles (~5–7 % at 500 tiles, vs ~40 % for 500 strips).
91
+
92
+ ## Tests
93
+
94
+ ```bash
95
+ pip install -e ".[dev]"
96
+ pytest # test_zarr_roundtrip needs the [gnn] extra
97
+ ```
98
+
99
+ ## Note on the name
100
+
101
+ `spatialrna` 0.1–0.2 on PyPI is maintained by Ruqian Lyu; this is 0.3.0.dev0.
102
+ Coordinate with her before uploading to PyPI under the same name.
@@ -0,0 +1,78 @@
1
+ # spatialrna
2
+
3
+ Spatial RNA graph data processing and analysis for single-molecule spatial
4
+ transcriptomics (10x Xenium and Atera): transcripts → tile graphs and subgraphs →
5
+ any graph neural network (train / validate / embed) → clusters → spatial maps.
6
+
7
+ This continues the lab's `spatialrna` 0.2 (Ruqian Lyu) with the same scope and adds
8
+ reading of raw Xenium / Atera outputs, zarr storage, a fast KD-tree graph builder,
9
+ balanced grid tiling for large sections, and GPU Gaussian mixtures. The ISTIST
10
+ pipeline builds on it with its own model (CrossSampleGAT), transcript-level
11
+ annotation, statistics and an HTML report.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install -e . # readers, graph builders, clustering, maps (no torch)
17
+ pip install -e ".[gnn]" # + SpatialRNA dataset, datasets, train_val
18
+ # (install torch + PyG for your CUDA first)
19
+ ```
20
+
21
+ Python >= 3.10, zarr-python >= 3.
22
+
23
+ ## Modules
24
+
25
+ | module | what it does | 0.2 equivalent | needs torch |
26
+ |---|---|---|---|
27
+ | `readers` | Xenium / Atera `transcripts.zarr.zip` → transcripts (layout auto-detected) | – | no |
28
+ | `graph_build` | KD-tree radius graphs, subgraph sampling, `plan_tiles` (grid tiling) | – | no |
29
+ | `graph_zarr_io` | `SpatialRNA`: tiles (strips or grid) + padding → radius graphs → subgraphs, zarr I/O | `spatialrna.py` | yes |
30
+ | `datasets` | `ZarrGraphDataset` over many tile / subgraph stores | `spatialrna_ondisk.py` | yes |
31
+ | `train_val` | model-agnostic link-prediction training / validation, `embed_tile` | `train_val.py` | yes |
32
+ | `cluster` | `gmm` (GPU or numpy EM), `kmeans` | `run_kmeans.py` | optional |
33
+ | `viz` | `pixel_map`, two-panel overviews, one panel per label | `viz.py` | no |
34
+
35
+ ## Quick start
36
+
37
+ ```python
38
+ import numpy as np, torch
39
+ import spatialrna as sr
40
+
41
+ df = sr.readers.load_transcripts("/path/to/output") # x, y, z, qv, gene
42
+ print(sr.readers.describe("/path/to/output"))
43
+
44
+ # tile graphs (here: 100 near-square tiles with equal transcript counts)
45
+ # SpatialRNA(root="data/S01.zarr", sample_name="S01", cohort_zarr_path="data/cohort.zarr",
46
+ # num_tiles=100, tile_mode="grid", one_hot_encoding=enc, ...)
47
+
48
+ # train any model(x, edge_index) on the tiles / subgraphs
49
+ from spatialrna import train_val as tv
50
+ from spatialrna.datasets import ZarrGraphDataset
51
+ graphs = ZarrGraphDataset.from_sample_store("data/S01.zarr", kind="subgraphs")
52
+ opt = torch.optim.Adam(model.parameters(), lr=1e-3)
53
+ loss, acc = tv.train_link_prediction(model, graphs, opt, device, num_genes)
54
+ emb, tx_id = tv.embed_tile(model, graphs[0], device, num_genes)
55
+
56
+ # clusters and a map
57
+ labels, gmm = sr.cluster.gmm(emb.numpy(), 12)
58
+ fig = sr.viz.pixel_map(x, y, labels)
59
+ ```
60
+
61
+ ## Tiling
62
+
63
+ `SpatialRNA(tile_mode="strips")` (default, as in 0.2) cuts `num_tiles` equal-width
64
+ bands along `tile_by_dim`. `tile_mode="grid"` cuts near-square tiles with equal
65
+ transcript counts: no empty tiles in irregular tissue and little padding with many
66
+ tiles (~5–7 % at 500 tiles, vs ~40 % for 500 strips).
67
+
68
+ ## Tests
69
+
70
+ ```bash
71
+ pip install -e ".[dev]"
72
+ pytest # test_zarr_roundtrip needs the [gnn] extra
73
+ ```
74
+
75
+ ## Note on the name
76
+
77
+ `spatialrna` 0.1–0.2 on PyPI is maintained by Ruqian Lyu; this is 0.3.0.dev0.
78
+ Coordinate with her before uploading to PyPI under the same name.
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "spatialrna"
7
+ version = "0.3.0.dev0"
8
+ description = "Spatial RNA graph data processing and analysis for single-molecule spatial transcriptomics (Xenium / Atera): graphs, GNN training / embedding, clustering, spatial maps."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [{ name = "Anne Pan", email = "anne.pan@svi.edu.au" }]
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "Operating System :: OS Independent",
15
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
16
+ ]
17
+ # Core: readers, graph builders, clustering, maps. No torch needed.
18
+ dependencies = [
19
+ "numpy",
20
+ "pandas",
21
+ "scipy",
22
+ "zarr>=3",
23
+ "numcodecs",
24
+ "tqdm",
25
+ "scikit-learn",
26
+ "matplotlib",
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ # SpatialRNA dataset, datasets, train_val. Install torch and the PyG wheels matching
31
+ # your CUDA first -- see README.
32
+ gnn = ["torch", "torch_geometric"]
33
+ dev = ["pytest"]
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+ include = ["spatialrna*"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
@@ -0,0 +1,60 @@
1
+ """spatialrna: spatial RNA graph data processing and analysis for single-molecule
2
+ spatial transcriptomics (Xenium / Atera): transcripts -> tile graphs / subgraphs ->
3
+ any GNN (train / validate / embed) -> clusters -> spatial maps.
4
+
5
+ import spatialrna as sr
6
+ df = sr.readers.load_transcripts("/path/to/xenium_or_atera_output")
7
+ from spatialrna import SpatialRNA # tile graphs / subgraphs; needs torch + PyG
8
+
9
+ The ISTIST pipeline builds on this with its own model (CrossSampleGAT), transcript
10
+ annotation, statistics and report.
11
+
12
+ Submodules (imported on first use, so the light ones need neither torch nor a GPU):
13
+
14
+ readers Xenium / Atera transcripts.zarr.zip -> transcripts
15
+ graph_build radius graphs (KD-tree) and subgraph sampling
16
+ graph_zarr_io SpatialRNA tile dataset (strips or grid tiles) + zarr I/O [torch]
17
+ datasets ZarrGraphDataset over many tile / subgraph stores [torch]
18
+ train_val model-agnostic link-prediction training, validation, tile embedding [torch]
19
+ cluster Gaussian mixture (GPU or numpy) and k-means on embeddings
20
+ viz pixel maps of labels / niches / cell types
21
+
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import importlib
26
+
27
+ __version__ = "0.3.0.dev0"
28
+
29
+ _SUBMODULES = {"readers", "graph_build", "graph_zarr_io", "datasets", "train_val", "cluster", "viz"}
30
+
31
+ # name -> submodule, for `from spatialrna import SpatialRNA` etc. (resolved lazily, so
32
+ # `import spatialrna` works without torch; the graph_zarr_io names need it).
33
+ _EXPORTS = {
34
+ **{n: "graph_zarr_io" for n in (
35
+ "SpatialRNA", "save_data_zarr", "load_data_zarr", "zarr_group_exists", "save_raw_transcripts_zarr",
36
+ "load_raw_transcripts_zarr", "store_exists", "tile_store_path", "sample_store_path",
37
+ "ensure_sample_store", "subgraph_store_path", "read_tile_graph", "write_tile_graph",
38
+ "read_subgraph", "write_subgraph")},
39
+ "load_transcripts": "readers",
40
+ "ZarrGraphDataset": "datasets",
41
+ "plan_tiles": "graph_build",
42
+ }
43
+
44
+ __all__ = sorted(_SUBMODULES | set(_EXPORTS)) + ["__version__"]
45
+
46
+
47
+ def __getattr__(name):
48
+ if name in _SUBMODULES:
49
+ mod = importlib.import_module(f".{name}", __name__)
50
+ globals()[name] = mod
51
+ return mod
52
+ if name in _EXPORTS:
53
+ value = getattr(importlib.import_module(f".{_EXPORTS[name]}", __name__), name)
54
+ globals()[name] = value
55
+ return value
56
+ raise AttributeError(f"module 'spatialrna' has no attribute {name!r}")
57
+
58
+
59
+ def __dir__():
60
+ return __all__