spatial-velocity
RNA velocity and cellular dynamics analysis for spatial transcriptomics using scVelo stochastic / deterministic / dynamical models or VELOVI, with method-aware preprocessing, graph, training controls,
SKILL.mdSkills/spatial/spatial-velocity/SKILL.md
GitHub🏎️ Spatial Velocity
You are Spatial Velocity, the OmicsClaw skill for RNA velocity, directional state change, and kinetic / variational temporal ordering in spatial transcriptomics.
This skill follows the newer OmicsClaw unified template:
- method-specific core parameters stay explicit
- Python figures are the canonical standard gallery
figure_data/is the stable bridge for downstream styling- optional R plotting is a separate visualization layer, not a second analysis engine
Why This Exists
- RNA velocity is highly sensitive to preprocessing, graph construction, and
backend choice; hiding those settings behind one generic
--methodis not acceptable. - Spatial users need both embedding-centric and tissue-centric views.
- OmicsClaw needs a stable output contract so future velocity backends can be added without breaking downstream interpretation or custom visualization.
Core Capabilities
- scVelo kinetic backends
stochasticdeterministicdynamical
- Variational posterior backend
velovi
- Standard OmicsClaw gallery
- velocity stream on UMAP / spatial
- phase portraits
- spliced / unspliced proportion diagnostics
- heatmap and PAGA summary panels
- feature maps for speed, confidence, pseudotime, and latent time when available
- Figure-ready exports
figures/manifest.jsonfigure_data/*.csvfigure_data/manifest.json
- Stable tabular outputs
- cell-level metrics
- gene-level kinetic summaries
- cluster-level velocity summaries
- top-cell and top-gene exports
Input Convention
| Input slot | Used by | Notes |
|---|---|---|
adata.layers["spliced"] |
all methods | required |
adata.layers["unspliced"] |
all methods | required |
adata.obsm["spatial"] |
spatial gallery panels | strongly recommended |
adata.obsm["X_umap"] |
embedding gallery panels | optional, but OmicsClaw will best-effort compute UMAP when absent |
adata.obs[cluster_key] |
grouped summaries, PAGA, proportions | defaults to leiden; OmicsClaw can auto-compute it |
After the shared preprocessing stage, OmicsClaw also expects or creates:
adata.layers["Ms"] # moment-smoothed spliced counts
adata.layers["Mu"] # moment-smoothed unspliced counts
Method Contract
All methods share the same first stage:
- filter / normalize
log1p- HVG selection when requested
- PCA
- neighbors
- moments
That means the following are part of the scientific contract, not mere wrapper details:
velocity_min_shared_countsvelocity_n_top_genesvelocity_n_pcsvelocity_n_neighborsvelocity_use_highly_variablevelocity_graph_*
Workflow
- Load the h5ad and verify spliced / unspliced layers exist.
- Resolve
cluster_keyfor grouped exports and gallery summaries. - Run shared preprocessing for the requested velocity contract.
- Run the selected backend with method-specific core parameters only.
- Persist velocity results into stable AnnData slots such as:
obs["velocity_speed"]obs["velocity_confidence"]obs["velocity_pseudotime"]obs["latent_time"]when availableobs["root_cells"]/obs["end_points"]when available
- Build gallery context from stable
obs,obsm, and exported summary tables instead of from transient local variables. - Render the standard Python gallery through
PlotSpec/VisualizationRecipe. - Export
figure_data/for downstream styling without recomputing the science.
Visualization Contract
OmicsClaw treats spatial-velocity visualization as a two-layer system:
Python standard gallery
- the canonical analysis output
- generated during the main run
- built primarily from shared
_lib/vizvelocity primitives:streamphaseproportionsheatmappaga
- plus a small number of skill-specific summary plots
Optional R visualization layer
- reads
figure_data/ - focuses on styling, layout, manuscript composition, and publication polish
- must not rerun scVelo or VELOVI internally
- reads
This means:
- Python figures are the default OmicsClaw narrative users should interpret first.
figure_data/*.csvis the stable handoff for downstream beautification.reproducibility/r_visualization.shis an entrypoint for that optional layer.
CLI Reference
# Default stochastic scVelo run
oc run spatial-velocity \
--input <processed.h5ad> --output <dir>
# Deterministic comparison run
oc run spatial-velocity \
--input <processed.h5ad> \
--method deterministic \
--velocity-min-r2 0.02 \
--velocity-min-likelihood 0.005 \
--output <dir>
# Lightweight dynamical smoke test
oc run spatial-velocity \
--input <processed.h5ad> \
--method dynamical \
--dynamical-n-top-genes 500 \
--dynamical-max-iter 5 \
--dynamical-n-jobs 4 \
--output <dir>
# VELOVI
oc run spatial-velocity \
--input <processed.h5ad> \
--method velovi \
--velovi-max-epochs 200 \
--velovi-n-samples 25 \
--output <dir>
# Demo
oc run spatial-velocity --demo --output /tmp/velocity_demo
Output Structure
<output_dir>/
├── report.md
├── result.json
├── processed.h5ad
├── figures/
│ ├── manifest.json
│ ├── velocity_stream_umap.png
│ ├── velocity_stream_spatial.png
│ ├── velocity_phase.png
│ ├── velocity_layer_proportions.png
│ ├── velocity_heatmap.png
│ ├── velocity_paga.png
│ └── ...
├── figure_data/
│ ├── manifest.json
│ ├── velocity_summary.csv
│ ├── velocity_cell_metrics.csv
│ ├── velocity_gene_summary.csv
│ ├── velocity_gene_hits.csv
│ ├── velocity_cluster_summary.csv
│ ├── velocity_top_cells.csv
│ ├── velocity_top_genes.csv
│ ├── velocity_run_summary.csv
│ ├── velocity_spatial_points.csv
│ └── velocity_umap_points.csv
├── tables/
│ ├── cell_velocity_metrics.csv
│ ├── gene_velocity_summary.csv
│ ├── velocity_gene_hits.csv
│ ├── velocity_cluster_summary.csv
│ ├── top_velocity_cells.csv
│ └── top_velocity_genes.csv
└── reproducibility/
├── commands.sh
├── requirements.txt
├── environment.txt
└── r_visualization.sh
Method Notes
stochastic
- Best default first pass.
- Still graph-sensitive and not a full kinetic model.
deterministic
- Simpler steady-state baseline.
- Useful as a comparison against
stochasticordynamicalwhen the user wants to separate graph sensitivity from heavier model complexity.
dynamical
- Adds kinetic fitting and latent-time support.
- Runtime and convergence cost are materially higher.
latent_timeis a fitted ordering, not clock time.
velovi
- Uses a variational posterior model after the shared moment construction step.
- Training settings are scientifically relevant and must be reported.
Safety
- Do not hide preprocessing choices: they materially change velocity, confidence, and pseudotime.
- Do not oversell time:
velocity_pseudotimeandlatent_timeare model-derived orderings. - Do not mix backend semantics: scVelo kinetics and VELOVI posteriors are not interchangeable labels.
- Keep visualization layers separated: R templates read
figure_data/and must not rerun the backend.
Dependencies
- Required:
scanpyanndatascvelo
- Optional by method:
scvi-toolsvelovi
Citations
- Bergen V, et al. Generalizing RNA velocity to transient cell states through dynamical modeling. Nat Biotechnol. 2020.
- Gayoso A, et al. VELOVI: deep generative modeling of RNA velocity. 2024.