spatial_graph_algorithms
Python package for analysing proximity graphs from sequencing-based spatial microscopy (Slide-tags, Pixelgen, and similar).
Takes a raw edge list → simulate, denoise, reconstruct coordinates, and score quality in one coherent package.
Documentation · Quickstart · Example notebook
pip install spatial-graph-algorithms
pip install "spatial-graph-algorithms[all]" # Node2Vec, PyMDE, PaCMAP
Quick start
from spatial_graph_algorithms.simulate import generate
from spatial_graph_algorithms.reconstruct import reconstruct
from spatial_graph_algorithms.metrics import evaluate
from spatial_graph_algorithms.plot.network import plot_network, plot_comparison
# simulate a 500-node circular tissue graph with 5 % spurious edges
sn = generate(n=500, shape="circle", mode="knn", k=8,
false_edges_fraction=0.05, seed=42)
# reconstruct coordinates from topology alone
sn = reconstruct(sn, method="mds", dim=2, seed=42)
# score the reconstruction
m = evaluate(sn)
# m["cpd"] ≈ 0.98, m["knn_preservation"] ≈ 0.77
Gallery
| Simulated graph (false edges in red) | Reconstruction vs ground truth |
|---|---|
Nine graph construction modes ship out of the box:
Modules
| Module | Status |
|---|---|
simulate — point clouds + 9 graph modes + false-edge injection |
stable |
reconstruct — MDS, STRND; UMAP/Isomap/Node2Vec/PaCMAP/PyMDE optional |
stable |
metrics — CPD, kNN preservation, distortion, graph summary |
stable |
plot — network, 3-D, edge-length histogram, reconstruction comparison |
stable |
denoise — Leiden, Jaccard, betweenness, bipartite filters |
in progress |
coherence — spatial constant, dimension prediction, promiscuity |
in progress |
All modules consume and return a SpatialGraph — a thin dataclass holding the adjacency matrix, ground-truth positions, reconstructed positions, and node/edge metadata.
Architecture
See ARCHITECTURE.md for the full design doc. Summary:
src/spatial_graph_algorithms/
├── network.py # SpatialGraph dataclass — shared by every module
├── simulate/ # point cloud generation + 9 graph construction modes
├── reconstruct/ # coordinate recovery (MDS, STRND, …)
├── metrics/ # quality scoring and graph structure summaries
├── plot/ # matplotlib figures
├── verify/ # end-to-end pipeline runner (writes CSV + PNG artefacts)
├── denoise/ # (in progress) edge noise removal
└── coherence/ # (in progress) spatial coherence analysis
Every function takes and returns a SpatialGraph — nothing hides state. Modules only import
from modules earlier in the pipeline; simulate never touches reconstruct, metrics never
touches plot.
| Module | Owns | Does not own |
|---|---|---|
network |
SpatialGraph schema and validation |
Creating or analysing graphs |
simulate |
Synthetic graph generation | Real-data I/O |
reconstruct |
Coordinate recovery algorithms | Graph creation or quality scoring |
metrics |
Quality metrics and structure summaries | Plotting or file I/O |
plot |
Figures | Saving results or running algorithms |
verify |
Pipeline orchestration and artefact writing | Any algorithm logic |
Contributing
See CONTRIBUTING.md and the full docs. Run pip install -e ".[all]" && pytest to get started — 50 tests, all should pass.
MIT license · David Fernandez Bonet
Metadata
Release files for spatial-graph-algorithms 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spatial_graph_algorithms-0.1.1.tar.gz | 33.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spatial_graph_algorithms-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.5 kB
Release files / spatial_graph_algorithms-0.1.1.tar.gz
| Download URL | spatial_graph_algorithms-0.1.1.tar.gz |
|---|---|
| Size | 33.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ead7e92a4fcdf83e7300ded3603b1d9342a4dec5d620e1a7f55f1586f4416e2
|
|
BLAKE2b-256 checksum How to use checksums |
c07dafd33cff26f58488d9dd017f432cef35fe373610baa4a19cc2c4d27bece4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / spatial_graph_algorithms-0.1.1-py3-none-any.whl
| Download URL | spatial_graph_algorithms-0.1.1-py3-none-any.whl |
|---|---|
| Size | 34.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d57582a022333f9d8748abaaf7c6efd065adcf310b16d3a40bf63a16691903cb
|
|
BLAKE2b-256 checksum How to use checksums |
f2418cf340731230cedfb2168e795cba41d37035e1c573ccb58e9acb6bf029b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|