Skip to main content

Unified toolkit for sequencing-based spatial microscopy graph analysis

Project description

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

Project details


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.0.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.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spatial_graph_algorithms-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 84da29384fa3baba0af83a37338a372482f6b5098bac9ff777fd62e42e793dc0
MD5 9cb50eaa97c93fe9b345c15c2853fc91
BLAKE2b-256 7110e594383379fff6c4c4583e455195b0be032a238c10e2d02714fd0f7ddb32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatial_graph_algorithms-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 808c12174ed7def245489a2ab4b4a0ff99c409e1587616dcab12850b4dcec417
MD5 cedda6a71ebb8e31ca1189be35f3732b
BLAKE2b-256 b92948fb97393dc27df056a7774c4cf26fca614e2644a7b2f5edbb7b9be4e737

See more details on using hashes here.

Supported by

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