Skip to main content

spatial_graph_algorithms

Tests Docs PyPI Python 3.9+ License: MIT

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatial_graph_algorithms-0.1.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spatial_graph_algorithms-0.1.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file spatial_graph_algorithms-0.1.1.tar.gz.

File metadata

  • Download URL: spatial_graph_algorithms-0.1.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for spatial_graph_algorithms-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3ead7e92a4fcdf83e7300ded3603b1d9342a4dec5d620e1a7f55f1586f4416e2
MD5 48be849ae31fca6c3918e89155bae7a3
BLAKE2b-256 c07dafd33cff26f58488d9dd017f432cef35fe373610baa4a19cc2c4d27bece4

See more details on using hashes here.

File details

Details for the file spatial_graph_algorithms-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spatial_graph_algorithms-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d57582a022333f9d8748abaaf7c6efd065adcf310b16d3a40bf63a16691903cb
MD5 a9a3d6d411b05c4e30eb250351dce061
BLAKE2b-256 f2418cf340731230cedfb2168e795cba41d37035e1c573ccb58e9acb6bf029b5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page