spatial-de
Load when ranking spatial cluster markers or comparing two spatial groups. Skip when the data is single-cell (use sc-de), bulk (use bulkrna-de), or for spatially variable expression (use spatial-genes).
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 161
- Forks
- 27
01 前言 Front Matter
- name
- spatial-de
- tags
- [ "spatial", "differential-expression", "markers", "wilcoxon", "t-test", "pydeseq2", "pseudobulk" ]
- trigger
- differential expression, marker gene, pseudobulk, Wilcoxon, t-test, PyDESeq2, spatial DE
- description
- Load when ranking spatial cluster markers or comparing two spatial groups. Skip when the data is single-cell (use sc-de), bulk (use bulkrna-de), or for spatially variable expression (use spatial-genes).
02 资源文件 14
- 脚本_api.py5.3 KB
- 脚本examples/example_step.py861 B
- 参考文档OPERATOR.json379 B
- 其他r_visualization/de_publication_template.R7.2 KB
- 参考文档r_visualization/README.md1.6 KB
- 参考文档references/methodology.md7.6 KB
- 参考文档references/output_contract.md1.9 KB
- 参考文档references/parameters.md4.8 KB
- 参考文档references/r_visualization.md808 B
- 脚本spatial_de.py65.9 KB
- 脚本tests/__init__.py—
- 脚本tests/test_api.py2.2 KB
- 脚本tests/test_examples_replay.py1.8 KB
- 脚本tests/test_spatial_de.py7.2 KB
03 SKILL.md 正文
spatial-de
When to use
Rank spatial group markers with Wilcoxon or t-test, or compare conditions with sample-aware PyDESeq2 pseudobulk. Biological sample labels are required; spatial spots do not supply independent replicates.
Use from a step
from skills._sdk.notebook import load_skill, read_input, write_output
library = load_skill("spatial-de")
adata = read_input("processed.h5ad")
library.differential_expression(adata, groupby="leiden")
write_output(library.results(adata), "tables/de_full.csv")
The executable example checks known markers in simulated spatial domains.
API
<!-- api:begin generated from _api.py; regenerate with run.py api <skill dir> --write -->
differential_expression(adata, *, method='wilcoxon', groupby='leiden', group1=None, group2=None, n_top_genes=10, fdr_threshold=0.05, log2fc_threshold=1.0, **parameters)
Test groups and return the same AnnData, with results in its diagnostics.
Scanpy uses raw when present, otherwise log-normalized X. PyDESeq2 uses counts, then raw, then X; provide integer counts and biological samples.
:param adata: Expression and group labels; modified in place. :param method: CLI default wilcoxon; t-test or pydeseq2 for other tests. :param groupby: CLI default leiden; obs column defining comparisons. :param group1: Tested group, or None for each group versus rest. :param group2: Reference group; supply together with group1. :param n_top_genes: CLI default 10 marker genes per group. :param fdr_threshold: CLI default 0.05 adjusted-p-value threshold. :param log2fc_threshold: CLI default 1.0 effect-size threshold. :param parameters: Method-specific CLI parameters from references/parameters.md. :returns: The same AnnData; results returns the full result table. :raises ValueError: Groups, method or sample replication are invalid. :raises ImportError: PyDESeq2 is unavailable; use install_skill_deps.
results(adata, *, markers_only=False)
Return the full or selected marker table without changing expression.
:param adata: AnnData returned by differential_expression. :param markers_only: Default False; True selects the reported top markers. :returns: A new DataFrame with method-native effect and significance columns. :raises ValueError: No differential expression run is recorded.
run_info(adata, *, keep=True)
Read diagnostics and the result tables from the most recent run.
:param adata: AnnData returned by differential_expression. :param keep: Default True; False removes diagnostics before CLI serialization. :returns: Diagnostic dictionary including full_df and markers_df. :raises ValueError: No differential expression run is recorded.
volcano_figure(adata, *, group=None)
Plot effect size against adjusted significance for one comparison.
:param adata: AnnData returned by differential_expression. :param group: Tested group; None chooses the first reported group. :returns: A matplotlib Figure; no files are written. :raises ValueError: No results exist for the selected group.
<!-- api:end -->
Methods and parameters
Scanpy ranks every gene, then optionally filters markers. PyDESeq2 requires both group labels and two retained pseudobulk profiles per condition. It uses a paired design when two biological samples contribute to both groups. See parameters for keyword arguments and methodology for matrix and design details.
Gotchas
differential_expressionuses Scanpy's raw preference when raw exists; otherwise provide log-normalized X. Count methods preferlayers['counts'].run_info()['design_formula']records the PyDESeq2 paired/unpaired design.tables/skipped_sample_groups.csvrecords bins below the cell threshold.results(markers_only=True)may contain nonsignificant top genes when no genes pass all filters; inspect the significance columns.
Inputs and outputs
Functions modify AnnData in place and return DataFrames/Figures without
writing files. The CLI writes processed.h5ad, tables/de_full.csv,
marker/diagnostic tables, report and result JSON.
The output contract lists conditional figures.
CLI
python skills/spatial/spatial-de/spatial_de.py --input processed.h5ad --output results/de
python skills/spatial/spatial-de/spatial_de.py --demo --output /tmp/spatial-de_demo
See also
Use spatial-preprocess before analysis, spatial-genes for autocorrelation, and sc-de or bulkrna-de for their respective modalities.
Dependencies
anndata, matplotlib, numpy, pandas, pydeseq2, scanpy, scipy, seaborn
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).