spatial-annotate
Load when assigning per-spot cell-type labels on a spatial AnnData via marker-gene scoring or scRNA-reference mapping (Tangram / scANVI / CellAssign). Skip when computing spot-level cell-type proportions for multi-cell-per-spot platforms (use spatial-deconv); tissue-domain detection (use spatial-domains).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- spatial-annotate
- tags
- [ "spatial", "annotation", "cell-type", "marker-based", "tangram", "scanvi", "cellassign" ]
- trigger
- cell type annotation, annotate cell types, Tangram, scANVI, CellAssign, marker genes, label transfer, spatial annotation
- description
- Load when assigning per-spot cell-type labels on a spatial AnnData via marker-gene scoring or scRNA-reference mapping (Tangram / scANVI / CellAssign). Skip when computing spot-level cell-type proportions for multi-cell-per-spot platforms (use spatial-deconv); tissue-domain detection (use spatial-domains).
02 资源文件 11
- 脚本_api.py6.1 KB
- 脚本examples/example_step.py419 B
- 参考文档OPERATOR.json360 B
- 其他r_visualization/annotation_publication_template.R1.6 KB
- 参考文档r_visualization/README.md1.4 KB
- 参考文档references/methodology.md10.8 KB
- 参考文档references/output_contract.md1.7 KB
- 参考文档references/parameters.md4.3 KB
- 脚本spatial_annotate.py36.2 KB
- 脚本tests/test_api.py1.4 KB
- 脚本tests/test_spatial_annotate.py5.5 KB
03 SKILL.md 正文
spatial-annotate
When to use
Assign discrete cell labels using marker overlap, Tangram, scANVI or CellAssign. Use spatial-deconv for proportions and spatial-domains for tissue regions.
Use from a step
from skills._sdk.notebook import load_skill, read_input, write_output
library = load_skill("spatial-annotate")
data = read_input("input.h5ad")
data = library.annotate(data, cluster_key="leiden")
write_output(library.cell_type_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 -->
annotate(adata, *, method: str='marker_based', reference=None, species: str='human', marker_genes: dict | None=None, random_state: int=0, **parameters)
Annotate in place and return the same AnnData without file writes.
Marker and Tangram methods read log-normalized X. scANVI/CellAssign require raw counts in the requested layer (normally counts), raw, or explicitly selected X. Reference AnnData is copied before training.
:param adata: Spatial AnnData with normalized X and method-required labels/counts. :param method: CLI default marker_based; tangram, scanvi or cellassign are optional. :param reference: Labelled reference AnnData for Tangram/scANVI; None otherwise. :param species: Human by default or mouse for built-in marker dictionaries. :param marker_genes: Optional CellAssign marker mapping; None uses species markers. :param random_state: Training seed, 0 by default; change to assess sensitivity. :param parameters: Method keyword options in references/parameters.md. Defaults match the CLI, including cluster_key=leiden and n_marker_genes=50. :returns: The same AnnData with cell_type labels and JSON run diagnostics. :raises ValueError: Invalid method, species, missing reference or invalid counts. :raises TypeError: Unknown method parameter. :raises ImportError: Missing backend; use install_skill_deps for the named package.
run_info(adata, *, keep: bool=True) -> dict
Read annotation counts, method parameters and cluster-marker scores.
:param adata: AnnData returned by annotate. :param keep: True retains diagnostics; False removes them before CLI serialization. :returns: Diagnostic dict, or an empty dict before analysis.
cell_type_counts(adata)
Count cell labels and their percentages.
:param adata: AnnData with cell_type labels; expression values are not read. :returns: DataFrame with cell_type, n_cells and proportion (percent). :raises KeyError: Annotation labels are absent.
annotation_figure(adata)
Plot discrete cell labels in spatial coordinates.
:param adata: Annotated spatial AnnData; reads coordinates and cell_type. :returns: A matplotlib Figure without saving it. :raises KeyError: Annotation labels are absent.
<!-- api:end -->
Methods and parameters
Marker/Tangram methods read normalized X. scANVI/CellAssign validate raw integer counts. Reference methods take reference=AnnData; marker_genes applies only to CellAssign. See parameters and methodology.
Gotchas
annotaterequires a reference for Tangram/scANVI.tables/cluster_annotations.csvis marker-method output; probabilities are method-dependent.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-annotate/spatial_annotate.py --input data.h5ad --output results/spatial-annotate
See also
Dependencies
anndata, matplotlib, numpy, pandas, scanpy, scipy, scvi-tools, seaborn, tangram-sc, 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).