spatial-statistics
Load when running spatial autocorrelation / hotspot / co-occurrence / neighbourhood-enrichment / Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- spatial-statistics
- tags
- [ "spatial", "statistics", "moran", "geary", "ripley", "co-occurrence", "nhood-enrichment", "getis-ord", "squidpy" ]
- trigger
- spatial statistics, Moran, Geary, Ripley, co-occurrence, Getis-Ord, local Moran, centrality
- description
- Load when running spatial autocorrelation / hotspot / co-occurrence / neighbourhood-enrichment / Ripley K stats on a clustered spatial AnnData via squidpy. Skip when ranking spatially variable genes (use spatial-genes); tissue domain detection (use spatial-domains).
02 资源文件 12
- 脚本_api.py4.6 KB
- 脚本examples/example_step.py566 B
- 参考文档r_visualization/README.md1.4 KB
- 其他r_visualization/stats_publication_template.R3.2 KB
- 参考文档references/methodology.md6.2 KB
- 参考文档references/output_contract.md2.9 KB
- 参考文档references/parameters.md7.5 KB
- 脚本spatial_statistics.py75.1 KB
- 参考文档STRATEGY.json522 B
- 脚本tests/__init__.py—
- 脚本tests/test_api.py2.5 KB
- 脚本tests/test_spatial_statistics.py7.0 KB
03 SKILL.md 正文
spatial-statistics
When to use
Measure spatial enrichment, co-occurrence, autocorrelation or graph structure. Use spatial-genes for SVG ranking and spatial-domains for regions.
Use from a step
from skills._sdk.notebook import load_skill, read_input, write_output
library = load_skill("spatial-statistics")
data = read_input("input.h5ad")
data = library.analyze(data, analysis_type="neighborhood_enrichment", random_state=123)
write_output(library.results_table(data), "tables/results.csv")
Run examples/example_step.py through the step runner.
API
<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->
analyze(adata, *, analysis_type: str='neighborhood_enrichment', random_state: int=123, **parameters)
Run one spatial analysis in place and return the same AnnData.
Gene analyses read X (log-normalized expression); cluster and network analyses read labels, coordinates and spatial_connectivities. Existing spatial graphs are reused unless force_graph_rebuild=True. Bivariate Moran's backend cannot be seeded: results vary between runs.
:param adata: Spatial AnnData; cluster-aware methods require categorical labels. :param analysis_type: CLI default neighborhood_enrichment; also ripley, co_occurrence, moran, geary, local_moran, getis_ord, bivariate_moran, network_properties or spatial_centrality. :param random_state: Permutation/simulation seed, matching CLI default 123. Ignored by bivariate_moran; its run_info records this limitation. :param parameters: Method keyword options from references/parameters.md; omitted values retain backend wrapper defaults. Unknown options raise. :returns: The same AnnData with JSON-encoded diagnostics and result tables. :raises ValueError: Unknown analysis or invalid input. :raises TypeError: An option does not belong to the chosen method. :raises ImportError: Missing backend; use install_skill_deps with squidpy, esda, libpysal or networkx as reported in the error.
run_info(adata, *, keep: bool=True) -> dict
Read the analysis diagnostics, including method-specific DataFrames.
:param adata: AnnData returned by analyze. :param keep: True retains the record; False removes it before CLI serialization. :returns: Diagnostic dict; encoded tables are restored as DataFrames.
results_table(adata, *, name: str='pair_summary_df')
Return a method result table independently of the CLI gallery.
:param adata: AnnData returned by analyze. :param name: Default pair_summary_df for enrichment; results_df for most other methods, or zscore_df/count_df/per_cluster_df when present. :returns: A DataFrame copy. :raises KeyError: The selected analysis has no table with this name.
enrichment_figure(adata)
Plot the neighborhood enrichment z-score matrix.
:param adata: AnnData after neighborhood_enrichment; expression is not read. :returns: A matplotlib Figure without saving it. :raises KeyError: No enrichment matrix is available.
<!-- api:end -->
Methods and parameters
Ten methods remain available through analysis_type; extra keywords use Python wrapper names documented in references/parameters.md. Existing spatial graphs are reused unless force_graph_rebuild=True. See parameters and methodology.
Gotchas
results_tabledefaults to pair_summary_df; other methods often return results_df.spatial_centralityrequires labels and returns cluster-level scores.run_info(keep=False)removes library diagnostics before CLI serialization.
Inputs and outputs
The library returns AnnData, DataFrames or Figures without file writes. The CLI keeps reports, result.json, tables and conditional gallery outputs. See the complete output contract for filenames and conditions.
CLI
python skills/spatial/spatial-statistics/spatial_statistics.py --input data.h5ad --output results/spatial-statistics
See also
Dependencies
anndata, esda, libpysal, matplotlib, networkx, numpy, pandas, scanpy, scipy, seaborn, squidpy
04 同仓库更多 Skills
demo-skill
A fixture skill for the skill environment tests. Use it for nothing else.
fake-domains
Test fixture for the golden deployment in tests/entry. Load never; it has no script.
replace-me-skill
Load when copying this directory to bootstrap a new OmicsClaw skill. Skip when an existing skill already covers the request.
spatial-velocity
Load when estimating RNA velocity on a spatial AnnData with `layers["spliced"]` + `layers["unspliced"]` via scVelo (stochastic / deterministic / dynamical) or veloVI (deep generative). Skip when input lacks the spliced/unspliced layers (must be quantified upstream by velocyto / kb-python / STARsolo); non-spatial scRNA velocity (use sc-velocity).
spatial-trajectory
Load when inferring pseudotime / lineage trajectories on a preprocessed spatial AnnData via DPT (default — diffusion pseudotime), CellRank (terminal-state + fate-probability), or Palantir (waypoint branch probabilities). Skip when the data has spliced/unspliced layers and you want velocity-driven dynamics (use spatial-velocity); non-spatial scRNA pseudotime (use sc-pseudotime).
spatial-register
Load when aligning multiple spatial slices into a common coordinate frame with PASTE or STalign. Skip single-slice data; for expression-space batch correction use spatial-integrate.