Skip to main content

Biological Graph Signal Processing for Spatial Data Analysis

Project description

PyBioGSP

Biological Graph Signal Processing for Spatial Data Analysis

A Python implementation of Graph Signal Processing (GSP) methods including Spectral Graph Wavelet Transform (SGWT) for analyzing spatial patterns in biological data. Uses PyTorch for accelerated matrix decomposition.

Based on Hammond, Vandergheynst, and Gribonval (2011) "Wavelets on Graphs via Spectral Graph Theory" and biological application in Stephanie, Yao, Yuzhou (2024).

Features

  • Multi-scale analysis of spatial signals using Spectral Graph Wavelet Transform
  • PyTorch acceleration for fast eigendecomposition and matrix operations
  • Multiple kernel families: Mexican Hat, Meyer, and Heat kernels
  • Graph Fourier Transform (GFT) and Inverse GFT
  • Similarity analysis using energy-normalized weighted similarity in Fourier domain
  • Simulation tools for generating test patterns (circles, stripes, checkerboards)
  • Visualization functions for SGWT decomposition, kernels, and patterns

Installation

From PyPI (recommended)

pip install pybiogsp

From source (development)

git clone https://github.com/BMEngineeR/PyBioGSP.git
cd PyBioGSP
pip install -e ".[viz]"  # includes matplotlib & seaborn

Quick Start

from pybiogsp import SGWT

# 1. Initialize with a DataFrame containing X, Y coordinates and signal columns
sg = SGWT(data=df, x_col="X", y_col="Y",
          signals=["signal_1", "signal_2"],
          J=3, scaling_factor=5, kernel_type="heat")

# 2. Build graph (k-NN -> Laplacian)
sg.build_graph(k=12, laplacian_type="normalized", verbose=False)

# 3. Forward & inverse SGWT (method controls spectral preparation)
sg.run_sgwt(method="eigen", use_batch=True, verbose=False,
            use_torch=True, length_eigenvalue=900)

# 4a. Compare two signals in wavelet domain
result = sg.run_sgcc("signal_1", "signal_2", return_parts=True)
print(f"Overall similarity:  {result['S']:.4f}")
print(f"Low-freq similarity: {result['c_low']:.4f}")
print(f"High-freq similarity:{result['c_nonlow']:.4f}")

# 4b. Or compute all-pairs SGCC matrix at once (matrix multiplication, no loop)
sgcc_df = sg.run_sgcc_matrix()
print(sgcc_df)

# 5. Energy analysis
energy_df = sg.energy_analysis("signal_1")
print(energy_df)

Workflow

SGWT(data) -> build_graph() -> run_sgwt(method=...) -> run_sgcc() / energy_analysis()
Step Method What it does
1 SGWT(data, ...) Initialize with DataFrame, coordinates, signals, kernel parameters
2 build_graph(k, laplacian_type) Build k-NN graph -> Laplacian (method-agnostic)
3 run_sgwt(method=..., use_batch=...) Spectral prep + forward SGWT + inverse reconstruction
4a run_sgcc(signal1, signal2, ...) Energy-weighted cosine similarity -> c_low, c_nonlow, S
4a' run_sgcc_matrix() All-pairs SGCC matrix via matrix multiplication (no loop needed)
4b energy_analysis(signal_name) Per-scale energy distribution

API Overview

SGWT Class — Main Entry Point

from pybiogsp import SGWT

sg = SGWT(
    data,                    # DataFrame with coordinates and signals
    x_col="x", y_col="y",   # Coordinate column names
    signals=["sig1"],        # Signal columns (None = auto-detect)
    J=5,                     # Number of wavelet scales
    scaling_factor=2.0,      # Ratio between consecutive scales
    kernel_type="heat",      # "heat" | "mexican_hat" | "meyer"
)

sg.build_graph(k=25, laplacian_type="normalized")
sg.run_sgwt(method="eigen", use_batch=True, use_torch=True)
result = sg.run_sgcc("sig1", "sig2", return_parts=True)   # -> {c_low, c_nonlow, S, ...}
sgcc_df = sg.run_sgcc_matrix()                              # -> p×p DataFrame of all-pairs S
energy = sg.energy_analysis("sig1")                        # -> DataFrame

PyBioGSP

Biological Graph Signal Processing for Spatial Data Analysis

Documentation PyPI

A Python implementation of Graph Signal Processing (GSP) methods ...

Copilot Agent Skill

This repo includes a VS Code Copilot agent skill at .github/skills/pybiogsp-analysis/ that provides Copilot with full PyBioGSP workflow knowledge — parameter meanings, result interpretation, troubleshooting, and batch analysis patterns. When using Copilot in this workspace, it can guide you through the SGWT pipeline end-to-end.

References

  1. Hammond, D. K., Vandergheynst, P., & Gribonval, R. (2011). Wavelets on graphs via spectral graph theory. Applied and Computational Harmonic Analysis, 30(2), 129-150.
  2. Stephanie, Yao, Yuzhou (2024). [Biological Application]. bioRxiv. doi:10.1101/2024.12.20.629650

License

GPL-3.0

Author

Yuzhou Chang (yuzhou.chang@osumc.edu)

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

pybiogsp-2.0.0.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

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

pybiogsp-2.0.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file pybiogsp-2.0.0.tar.gz.

File metadata

  • Download URL: pybiogsp-2.0.0.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pybiogsp-2.0.0.tar.gz
Algorithm Hash digest
SHA256 4453d2cb2d9d080c8c2ca86ff8130657b8b6b691fd8dcec897cf21a5f850950a
MD5 2cf8856418afbd495ad498cbf7f26a21
BLAKE2b-256 9345cc114eac23106236e1360e89de0e97063629521240aa68ef3a9935971922

See more details on using hashes here.

File details

Details for the file pybiogsp-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pybiogsp-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pybiogsp-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75d1237d9c299d936f8b91bea4628b5d354da4102fcc7dbb87595f741bbc52dd
MD5 c8a36d5dbb9f3f7459686a9fcc1d9818
BLAKE2b-256 35486d83b5b57523430af3b9f42bf2fc96e8d2292e4d6e5dd0374e24b87539a5

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