Spatial Communication
Researchspatial-communicationSpatial Communication is an Agent Skill for research published in the TianGzlab/OmicsClaw repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Load when computing ligand-receptor cell-cell communication on a preprocessed spatial AnnData with `obs[cell_type_key]` (default `leiden`) via LIANA (default), CellPhoneDB, FastCCC, or CellChat (R). Skip when running scRNA-only L-R inference (use `sc-cell-communication`) or when no cell-type labels exist (run `spatial-annotate` or `spatial-domains` first).
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/TianGzlab/OmicsClaw/blob/HEAD/skills/spatial/spatial-communication/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/spatial-communication, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
spatial-communication
When to use
The user has a preprocessed spatial AnnData with cell-type labels
(obs[cell_type_key], default leiden) and wants ligand-receptor
cell-cell communication scored. Four backends:
liana(default) — LIANA consensus across multiple L-R methods. Tunables--liana-expr-prop,--liana-min-cells,--liana-n-perms.cellphonedb— Permutation test with mean expression statistic. Tunables--cellphonedb-iterations,--cellphonedb-threshold.fastccc— Fast permutation-free percentile-based score. Tunables--fastccc-min-percentile.cellchat_r— CellChat (R) viarpy2interop. Tunables--cellchat-min-cells,--cellchat-prob-type.
Species: --species human (default) or mouse. For non-spatial
L-R use sc-cell-communication; for pathway scoring use
spatial-enrichment.
Inputs & Outputs
| Input | Format | Required |
|---|---|---|
| Preprocessed spatial AnnData | .h5ad with obsm["spatial"], obs[cell_type_key] (default leiden) | yes (unless --demo) |
| Output | Path | Notes |
|---|---|---|
| Annotated AnnData | processed.h5ad | uns["ccc_results"] (canonical L-R DataFrame); per-method copy at uns["liana_results"] / uns["cellphonedb_results"] / uns["fastccc_results"] / uns["cellchat_results"]; uns["communication_summary"] (pathway-level); uns["communication_signaling_roles"] (sender/receiver scores); uns["spatial_communication"] (run metadata) |
| L-R interactions | tables/lr_interactions.csv | full L-R list |
| Top interactions | tables/top_interactions.csv | top-N filtered |
| Pathway summary | tables/communication_summary.csv | aggregate per pathway |
| Signaling roles | tables/signaling_roles.csv | sender/receiver per cell type |
| Source-target | tables/source_target_summary.csv | per source-target pair counts |
| Run summary | tables/communication_run_summary.csv | params used |
| Report | report.md + result.json | always |
Flow
- Load AnnData, validate
obs[cell_type_key]exists with ≥ 2 categories (_lib/communication.py:764-765). - Sync
obsm["spatial"]↔obsm["X_spatial"](spatial_communication.py:79-81); cast cell-type column to Categorical. - Dispatch to chosen backend (LIANA / CellPhoneDB / FastCCC / CellChat-R).
- Write canonical L-R results to
uns["ccc_results"]+ per-methoduns[METHOD_RESULT_KEYS[method]](_lib/communication.py:735-739). - Compute pathway-level summary, signaling roles, source-target summary.
- Save tables +
processed.h5ad+ report.
Gotchas
obs[cell_type_key]is REQUIRED — no auto-fallback._lib/communication.py:764-765raisesValueErrorwhen the column is missing. Runspatial-annotateorspatial-domainsfirst.- Default cell-type column is
leiden, notcell_type.spatial_communication.py:1065defaults--cell-type-keyto"leiden". If your AnnData usescell_type, pass--cell-type-key cell_typeexplicitly. - CellChat backend needs an R install with CellChat.
--method cellchat_rinvokes R viarpy2. Install CellChat in your R environment first; missing R / rpy2 / CellChat surfaces as a runtime error inside the dispatch step (not atparser.error), so the failure happens after argument parsing succeeds. - FastCCC
--fastccc-min-percentilemust be in [0, 1].spatial_communication.py:985rejects values outside that range withparser.error. - Output
unskeys are unconditionally written, even with 0 interactions._lib/communication.py:735-739writes emptyuns["ccc_results"]/uns["communication_summary"]if no L-R pairs pass thresholds — distinguish "no signal" from "method failed" by inspectingtables/communication_run_summary.csv. - Per-method copy uses
METHOD_RESULT_KEYSmapping._lib/communication.py:68-73mapsliana → uns["liana_results"],cellphonedb → uns["cellphonedb_results"],fastccc → uns["fastccc_results"],cellchat_r → uns["cellchat_results"]. Downstream readers should preferuns["ccc_results"]for portability.
Key CLI
# Demo
python omicsclaw.py run spatial-communication --demo --output /tmp/comm_demo
# LIANA consensus (default)
python omicsclaw.py run spatial-communication \
--input preprocessed.h5ad --output results/ \
--method liana --species human --cell-type-key cell_type \
--liana-expr-prop 0.1 --liana-min-cells 5 --liana-n-perms 1000
# CellPhoneDB permutation test
python omicsclaw.py run spatial-communication \
--input preprocessed.h5ad --output results/ \
--method cellphonedb --cellphonedb-iterations 1000 --cellphonedb-threshold 0.1
# CellChat (R via rpy2)
python omicsclaw.py run spatial-communication \
--input preprocessed.h5ad --output results/ \
--method cellchat_r --species mouse \
--cellchat-min-cells 10 --cellchat-prob-type triMean
See also
references/parameters.md— every CLI flag, per-method tunablesreferences/methodology.md— when each backend winsreferences/output_contract.md—uns["ccc_results"]schema + per-method copies- Adjacent skills:
spatial-annotate(upstream — providesobs[cell_type_key]),spatial-domains(upstream alternative — Leiden domains),sc-cell-communication(parallel — non-spatial L-R),spatial-condition(parallel — DE between conditions),spatial-enrichment(parallel — pathway scoring)