spatial-domains
Load when detecting tissue domains / niches on a preprocessed spatial AnnData via Leiden / Louvain (spatial-weighted) or graph-neural backends (SpaGCN / STAGATE / GraphST / BANKSY / CellCharter). Skip when ranking spatially variable genes (use spatial-genes); spot-level cell-type annotation (use spatial-annotate).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- spatial-domains
- tags
- [ "spatial", "domains", "niches", "spagcn", "stagate", "graphst", "banksy", "cellcharter", "leiden", "louvain" ]
- trigger
- spatial domain, tissue region, niche, spatial niche, niche identification, niche detection, SpaGCN, STAGATE, CellCharter
- description
- Load when detecting tissue domains / niches on a preprocessed spatial AnnData via Leiden / Louvain (spatial-weighted) or graph-neural backends (SpaGCN / STAGATE / GraphST / BANKSY / CellCharter). Skip when ranking spatially variable genes (use spatial-genes); spot-level cell-type annotation (use spatial-annotate).
02 资源文件 11
- 脚本_api.py6.0 KB
- 脚本examples/example_step.py713 B
- 其他r_visualization/domains_publication_template.R1.5 KB
- 参考文档r_visualization/README.md1.4 KB
- 参考文档references/methodology.md16.2 KB
- 参考文档references/output_contract.md1.7 KB
- 参考文档references/parameters.md4.3 KB
- 脚本spatial_domains.py42.5 KB
- 脚本tests/__init__.py—
- 脚本tests/test_api.py5.8 KB
- 脚本tests/test_spatial_domains.py12.5 KB
03 SKILL.md 正文
spatial-domains
When to use
Find tissue domains from expression and coordinates. Use spatial-annotate for named cell labels and spatial-genes for variable genes.
Use from a step
from skills._sdk.notebook import load_skill, read_input, write_output
library = load_skill("spatial-domains")
data = read_input("input.h5ad")
data = library.identify(data, method="leiden", spatial_weight=0.3)
write_output(library.domain_counts(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 -->
identify(adata, *, method: str='leiden', resolution: float=1.0, spatial_weight: float=0.3, refine: bool=False, random_state: int | None=None, **parameters)
Identify domains in place and return the same AnnData.
Reads log-normalized X, X_pca and spatial coordinates; graph methods reuse existing expression neighbors. SpaGCN, STAGATE and BANKSY results vary between runs because their training wrappers do not expose every RNG.
:param adata: Preprocessed spatial AnnData; expression values are retained. :param method: CLI default leiden, or louvain/spagcn/stagate/graphst/banksy/cellcharter. :param resolution: Graph-clustering resolution, CLI default 1.0. :param spatial_weight: Spatial graph weight for Leiden/Louvain, CLI default 0.3. :param refine: False by default; True smooths labels using spatial KNN. :param random_state: None preserves CLI defaults: backend seed 42 for STAGATE, GraphST and CellCharter, otherwise 0; PCA uses 0. An explicit integer overrides both PCA and supported backend seeds. Existing PCA is reused. :param parameters: Backend options listed in references/parameters.md; fixed-K methods use n_domains=7 unless supplied. :returns: The same AnnData with spatial_domain and JSON run diagnostics. :raises ValueError: Unsupported method or invalid graph parameters. :raises ImportError: A backend is missing; use install_skill_deps with the named package.
run_info(adata, *, keep: bool=True) -> dict
Read the method, domain sizes, refinement status and effective seeds.
pca_random_state is None when identify reused existing PCA coordinates.
:param adata: AnnData returned by identify. :param keep: True retains diagnostics; False removes them before CLI serialization. :returns: Diagnostic dict, or an empty dict before analysis.
domain_counts(adata)
Count observations and percentages per domain.
:param adata: AnnData with spatial_domain labels; X is not read. :returns: DataFrame with domain, n_cells and proportion (percent). :raises KeyError: Domain labels are absent.
domain_figure(adata)
Plot domain labels in spatial coordinates.
:param adata: AnnData with spatial_domain and spatial coordinates; X is not read. :returns: A matplotlib Figure without writing files. :raises KeyError: Domain labels are absent.
<!-- api:end -->
Methods and parameters
Leiden/Louvain combine expression and spatial graphs. SpaGCN, STAGATE, GraphST, BANKSY and CellCharter remain optional. Fixed-K methods default to seven domains. See parameters and methodology.
Gotchas
identifyreuses expression neighbors. SpaGCN, STAGATE and BANKSY results vary between runs.spatial_weight=0uses expression-only graph clustering.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-domains/spatial_domains.py --input data.h5ad --output results/spatial-domains
See also
Dependencies
anndata, cellcharter, GraphST, igraph, louvain, matplotlib, numpy, pandas, pybanksy, scanpy, scikit-learn, scipy, seaborn, SpaGCN, squidpy, STAGATE-pyG, torch
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-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).