Spatial structure analysis and Search-and-Find plot generation for spatial omics data.
Project description
sfplot
sfplot is a Python package for spatial structure analysis in spatial omics data. It implements the Search-and-Find Plot (SFplot) / Cell-GPS workflow used in our manuscript to quantify multiscale tissue architecture, compute cophenetic distance-based structure maps, and analyze cell-cell or transcript-cell spatial relationships.
This repository is being maintained as the code companion for manuscript review and future reuse.
What the package does
- Computes searcher-findee distance matrices from spatial coordinates and cell labels.
- Builds cophenetic distance matrices and StructureMap heatmaps from
AnnDataobjects or plainpandastables. - Loads 10x Xenium outputs and prepares them for downstream spatial analysis.
- Provides a table-bundle Xenium loader that assembles
cells.parquet, official*_cell_groups.csv, andcell_feature_matrix.h5without requiring thespatialdata_iodependency chain. - Supports transcript-by-cell analysis for locating transcripts relative to cell types.
- Includes memory-optimized workflows for large datasets.
- Provides plotting utilities such as clustered heatmaps, circular dendrograms, and related summary figures.
Repository layout
src/sfplot/: core implementation.tests/: package tests and smoke checks.docs/: Sphinx documentation.sfplot-manuscript/: manuscript-specific notebooks, figures, and derived outputs.benchmarking/: benchmarking-related material.segmentation_methods/: supporting segmentation workflows.
Installation
Install directly from GitHub:
pip install git+https://github.com/hutaobo/sfplot.git
For local development or reviewer inspection:
git clone https://github.com/hutaobo/sfplot.git
cd sfplot
pip install -e .
The package requires Python 3.9 or later.
Quick start from a coordinate table
The minimal input is a table with spatial coordinates and a cell-type column.
import pandas as pd
from sfplot import compute_cophenetic_distances_from_df, plot_cophenetic_heatmap
df = pd.DataFrame(
{
"x": [0, 1, 5, 6],
"y": [0, 1, 5, 6],
"celltype": ["A", "A", "B", "B"],
}
)
row_coph, col_coph = compute_cophenetic_distances_from_df(
df=df,
x_col="x",
y_col="y",
celltype_col="celltype",
)
plot_cophenetic_heatmap(
row_coph,
matrix_name="row_coph",
output_dir="output",
output_filename="StructureMap_example.pdf",
sample="Example",
)
Quick start from Xenium output
from sfplot import load_xenium_data, load_xenium_table_bundle, compute_cophenetic_distances_from_adata
# Legacy `spatialdata_io` route
adata = load_xenium_data("/path/to/xenium/run", normalize=False)
# Stable table-bundle route used for the Atera Xenium benchmark
adata = load_xenium_table_bundle("/path/to/xenium/run", normalize=False)
row_coph, col_coph = compute_cophenetic_distances_from_adata(
adata,
cluster_col="Cluster",
output_dir="output",
)
Useful public entry points
load_xenium_data: load and preprocess Xenium data.load_xenium_table_bundle: load Xenium data fromcells.parquet+*_cell_groups.csv+cell_feature_matrix.h5whenspatialdata_iois unavailable or unstable.compute_cophenetic_distances_from_df: compute structure matrices from a coordinate table.compute_weighted_searcher_findee_distance_matrix_from_df: weighted searcher-findee kernel for entity, pathway, or LR analysis.compute_weighted_cophenetic_distances_from_df: weighted StructureMap wrapper over the weighted kernel.compute_cophenetic_distances_from_adata: compute structure matrices fromAnnData.compute_entity_to_cell_topology: generalizet_and_cfrom transcripts to arbitrary weighted entities.compute_entity_structuremap: build StructureMap-style topology among arbitrary weighted entities.plot_cophenetic_heatmap: generate StructureMap and related clustered heatmaps.transcript_by_cell_analysis: analyze transcript-to-cell spatial structure at scale.ligand_receptor_topology_analysis: score sender→receiver ligand-receptor candidates using topology, structure compatibility, and local contact.ligand_receptor_target_consistency: add a NicheNet-style downstream target-consistency layer.compute_pathway_activity_matrix: compute rank-based or weighted pathway activities per cell.pathway_topology_analysis: analyze pathway-to-cell and pathway-to-pathway spatial topology.compute_cophenetic_distances_from_df_memory_opt: memory-aware alternative for large tables.plot_circular_dendrogram_pycirclize: circular dendrogram visualization.
Notes for reviewers
- The package code used for the manuscript is in
src/sfplot/. - Manuscript-facing notebooks and generated figure assets are kept in
sfplot-manuscript/. - Raw experimental datasets are not bundled in this repository because of size and distribution constraints. The code expects standard spatial omics outputs such as Xenium folders or tabular coordinate inputs.
- When an
sfplot_tbc_formal_wta/results-style directory is already available, the LR and pathway topology extensions are designed to reuse itst_and_c_result_*.csvandStructureMap_table_*.csvoutputs as the preferred gene-level topology anchors before falling back to recomputation. load_xenium_datadepends on a compatiblespatialdata_io/spatialdata/ome_zarr/zarrstack. For reviewer reproduction on environments where that stack is mismatched, preferload_xenium_table_bundle.- A short repository walkthrough is available in REVIEWER_GUIDE.md.
Documentation
Sphinx documentation sources are available in docs/.
Citation
If you use this repository in connection with manuscript review, please cite the associated manuscript:
Cophenetic Spatial Topology Embedding reveals multiscale tissue architecture in spatial omics
License
This project is released under the MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cell_gps-0.0.3.tar.gz.
File metadata
- Download URL: cell_gps-0.0.3.tar.gz
- Upload date:
- Size: 72.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c690034206e30f5c9e6f1d6ab96f336660d5e6ff9339ab313fe23eea3f6945b
|
|
| MD5 |
58b6370d123e81bfc9ac811d169276ad
|
|
| BLAKE2b-256 |
e41ffdbde6541998e6bcfd69a4853a56d183e8d3e08e807a5a9962b3d1e96e2a
|
Provenance
The following attestation bundles were made for cell_gps-0.0.3.tar.gz:
Publisher:
python-publish.yml on hutaobo/sfplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cell_gps-0.0.3.tar.gz -
Subject digest:
4c690034206e30f5c9e6f1d6ab96f336660d5e6ff9339ab313fe23eea3f6945b - Sigstore transparency entry: 1573503300
- Sigstore integration time:
-
Permalink:
hutaobo/sfplot@2093ff91943ec3f670a2ccad6d37a430728d8604 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/hutaobo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2093ff91943ec3f670a2ccad6d37a430728d8604 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cell_gps-0.0.3-py3-none-any.whl.
File metadata
- Download URL: cell_gps-0.0.3-py3-none-any.whl
- Upload date:
- Size: 74.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c85d1ebcb31fcd8810bfd0ffbd33a7dc9ab6f245b17b221594aac49ebbaa518f
|
|
| MD5 |
8d6697e41b2f24401ad310f8f8e1ecf0
|
|
| BLAKE2b-256 |
af5051b7ebfdc49fc1132308060939598e916ab18b595e01745fc90c74281341
|
Provenance
The following attestation bundles were made for cell_gps-0.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on hutaobo/sfplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cell_gps-0.0.3-py3-none-any.whl -
Subject digest:
c85d1ebcb31fcd8810bfd0ffbd33a7dc9ab6f245b17b221594aac49ebbaa518f - Sigstore transparency entry: 1573503319
- Sigstore integration time:
-
Permalink:
hutaobo/sfplot@2093ff91943ec3f670a2ccad6d37a430728d8604 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/hutaobo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2093ff91943ec3f670a2ccad6d37a430728d8604 -
Trigger Event:
release
-
Statement type: