1
---
2
name: scvelo
3
description: Performs RNA velocity analysis with scVelo from spliced and unspliced single-cell RNA counts. Fits deterministic or dynamical models, examines gene phase portraits, builds velocity graphs, estimates relative latent time, and ranks velocity-associated genes. Use for directional trajectory hypotheses and kinetic-model diagnostics alongside Scanpy; velocity alone does not establish cell fate or causal drivers.
4
license: BSD-3-Clause
5
compatibility: Requires Python 3.13 for the tested stack with scvelo 0.3.4, scanpy 1.12.4, anndata 0.13.4, numpy 2.5.3 and pandas 2.3.3. Loom import requires loompy. Local H5AD analysis needs no network or credentials. The default stochastic solver is incompatible with NumPy 2.
6
metadata:
7
version: "2.0"
8
skill-author: Kuan-lin Huang
9
last-reviewed: "2026-10-01"
10
---
11
12
# scVelo RNA Velocity
13
14
## When to use
15
16
Use for kinetic analysis of aligned spliced/unspliced RNA counts, directional
17
trajectory hypotheses, gene-level phase portraits, and dynamical latent time.
18
Use the [model reference](references/velocity_models.md) for assumptions,
19
transition probabilities, and an optional CellRank handoff.
20
21
RNA velocity estimates an expression derivative under a model. Smooth arrows
22
are not observed cell movement, lineage tracing, causal drivers, or proof of
23
future fate. The dynamical estimator is not automatically more accurate than
24
a steady-state estimator on every dataset.
25
26
## Tested environment and compatibility
27
28
The maintained workflow targets scVelo **0.3.4**, Scanpy **1.12.4**, AnnData
29
**0.13.4**, NumPy **2.5.3**, pandas **2.3.3**, SciPy **1.18.1**, Matplotlib
30
**3.11.2**, and loompy **3.0.8** on Python 3.13. Use an isolated environment:
31
32
```bash
33
uv venv --python 3.13 .venv-velocity
34
uv pip install --python .venv-velocity/bin/python \
35
scvelo==0.3.4 scanpy==1.12.4 anndata==0.13.4 numpy==2.5.3 \
36
pandas==2.3.3 scipy==1.18.1 matplotlib==3.11.2 loompy==3.0.8
37
```
38
39
The packages above were resolved from cache and tested in an isolated `uv`
40
environment; shell paths above use POSIX syntax. Installation requires network
41
access unless packages are cached. No API key is required.
42
43
- **Deterministic and dynamical models:** native synthetic fitting, graphs,
44
relative times, plots and H5AD round trips are tested on this stack.
45
- **Stochastic model:** scVelo 0.3.4's default GLS scalar assignment fails with
46
NumPy 2. Scanpy 1.12 requires NumPy 2, so installing `numpy<2` beside current
47
Scanpy is not a solution. A separately validated legacy Scanpy/NumPy environment
48
is required; that legacy stack was not executed in this review. The helper
49
rejects this combination before modifying data, without changing the model.
50
- **pandas 3:** scVelo 0.3.4 dynamical fitting and some plots use operations no
51
longer supported by pandas 3. Keep the explicit pandas pin.
52
- The upstream stable tutorial still contains removed `scv.read` and older
53
preprocessing calls. Check the [0.3.4 source](https://github.com/theislab/scvelo/tree/v0.3.4)
54
when a tutorial disagrees with the installed API.
55
56
## Input contract
57
58
1. Obtain spliced and unspliced counts from a velocity-aware quantifier. Keep
59
quantifier/version, reference annotation, counting mode, sample IDs and cell
60
barcode mapping. Upstream quantification is outside the bundled script.
61
2. Supply **cells by genes** matrices in `adata.layers['spliced']` and
62
`adata.layers['unspliced']`, with identical cell/gene ordering and unique IDs.
63
Counts must be finite and nonnegative; fractional count estimates are allowed.
64
Never use logged, scaled, residualized, or batch-corrected values as counts.
65
Numerical inspection alone cannot establish that data are raw.
66
3. Inspect per-library/cluster coverage, doublets, ambient RNA, zero-count cells,
67
and annotation compatibility before fitting. Preserve the original full-gene
68
count file. Retained-gene backups do not preserve filtered-out genes.
69
4. Resolve barcode prefixes and gene identifiers explicitly when combining
70
files. Do not silently strip library IDs, intersect away most cells, or make
71
duplicated biological IDs unique without understanding why they repeat.
72
73
Read H5AD through AnnData. scVelo 0.3.4 has no `scv.read` or `scv.DataFrame`:
74
75
```python
76
import anndata as ad
77
adata = ad.read_h5ad("velocity_counts.h5ad")
78
```
79
80
For legacy loom input use `ad.io.read_loom('counts.loom', X_name='spliced',
81
sparse=True)`. AnnData 0.13 deprecates loom; convert to H5AD for further work.
82
Its `layers[None]` aliases `X`: do not delete it or iterate all layers as if every
83
key were a string. The helper accesses only named velocity layers. Native loom
84
reading and exact, reordered metadata alignment are covered by the tests;
85
AnnData 0.13 `write_loom` is not used.
86
87
## Run the maintained workflow
88
89
The [bundled script](scripts/rna_velocity_workflow.py) accepts local files and
90
never downloads a demonstration dataset on startup:
91
92
```bash
93
MPLBACKEND=Agg .venv-velocity/bin/python scripts/rna_velocity_workflow.py \
94
velocity_counts.h5ad --mode dynamical --groupby clusters \
95
--n-top-genes 2000 --n-neighbors 30 --n-jobs 1 --output-dir velocity_results
96
97
# Import a loom and align its raw counts to an existing annotation file:
98
MPLBACKEND=Agg .venv-velocity/bin/python scripts/rna_velocity_workflow.py \
99
counts.loom --processed-h5ad annotated.h5ad --groupby clusters \
100
--mode deterministic --output-dir velocity_check
101
```
102
103
Run these from the skill directory. Input filenames and biological annotations
104
are illustrative; the same CLI and functions are tested on small generated
105
kinetic fixtures. Omit `--groupby` when annotations are unavailable. Use
106
`--no-plots` for analysis without computing UMAP.
107
108
The helper performs these steps:
109
110
1. Validate layers, IDs, model compatibility and grouping; refuse previously
111
generated moments/velocity so preprocessing cannot silently run twice.
112
2. Back up retained raw layers as `spliced_counts` and `unspliced_counts` and
113
rebuild `X` from raw spliced counts. Filter genes and normalize `X` and the
114
two count layers on a linear scale.
115
3. Apply `sc.pp.log1p` **only to X**, select highly variable genes with Scanpy,
116
and rebuild PCA and neighbors after subsetting. Reusing stale PCA/neighbors
117
from an unrelated feature set can silently change the velocity model.
118
4. Compute `Ms` and `Mu` with `scv.pp.moments(adata, n_neighbors=None)` from the
119
explicit Scanpy graph. Moments are dense: budget memory for multiple
120
cells-by-genes arrays, not only the sparse input.
121
5. For dynamical mode, call `recover_dynamics(var_names='all')` on the selected
122
genes before `velocity(mode='dynamical')`; otherwise fit the selected model.
123
Require usable genes and a nonempty velocity graph.
124
6. Compute velocity coherence and velocity pseudotime; add latent time only for
125
dynamical fits. Rank velocity-associated genes only with at least two groups
126
and at least two cells per group. Record/warn about nonfinite or constant
127
time/coherence outputs in `uns['velocity_workflow']['diagnostics']`; a
128
constant pseudotime does not support a trajectory ordering. Ranking is exploratory.
129
7. For plots, recompute UMAP from the rebuilt graph, project velocities, save
130
PNGs directly to the requested directory, then save H5AD with package versions
131
and selected parameters. Existing labels remain annotations, not validated
132
cell identities.
133
134
The Python function mutates its argument in place; pass `adata.copy()` to keep
135
the original object. The CLI writes to `output_dir/adata_velocity.h5ad`.
136
Version 2 changes the former helper's behavior deliberately: raw layer geometry
137
is rebuilt, missing requested labels are errors, and plots/parallelism can be
138
controlled explicitly. Runtime depends on cells, genes and fit difficulty;
139
there is no universal 10–30 minute expectation.
140
141
## Inspect the evidence before interpretation
142
143
After a dynamical run (dataset-specific gene selection is illustrative):
144
145
```python
146
import pandas as pd
147
import scvelo as scv
148
149
# Candidate kinetic genes, not experimentally established drivers.
150
candidates = adata.var['fit_likelihood'].dropna().nlargest(6).index.tolist()
151
scv.pl.velocity(adata, var_names=candidates, basis='umap', show=False)
152
153
# This ranks group-associated velocities, not causal influence or condition DE.
154
scv.tl.rank_velocity_genes(adata, groupby='clusters', min_corr=0.3)
155
ranked = pd.DataFrame(adata.uns['rank_velocity_genes']['names'])
156
157
scv.tl.velocity_confidence(adata)
158
scv.pl.scatter(adata, color=['velocity_length', 'velocity_confidence'], show=False)
159
```
160
161
Inspect spliced-versus-unspliced phase portraits, coverage across induction and
162
repression, fitted parameters, failed/NaN fits, and branch-specific kinetics.
163
Check sensitivity to gene set, neighbors, subsampling and model assumptions.
164
Use time-course labels, perturbations, lineage tracing or labeling experiments
165
as independent directional evidence where available. A plausible UMAP alone
166
cannot validate a fit, and tuning until arrows match a desired story is not a
167
validation strategy.
168
169
There is no general minimum of 2,000 cells, universal unspliced fraction, or
170
rule that root cells must have the highest unspliced/spliced ratio. Coverage of
171
relevant kinetic states and measurement quality matter. Negative velocity can
172
represent repression or model misspecification; it is not by itself evidence
173
that layers were swapped.
174
175
## Output interpretation
176
177
| Field | Interpretation |
178
| --- | --- |
179
| `layers['velocity']` | Model-estimated derivative in processed gene-expression space |
180
| `var['velocity_genes']` | Genes selected for the velocity graph; distinct from all HVGs |
181
| `layers['Ms']`, `layers['Mu']` | Neighbor-averaged linear-scale spliced/unspliced expression |
182
| `layers['fit_t']` | Gene-specific fitted time coordinates, dynamical model only |
183
| `var['fit_alpha/beta/gamma']` | Fitted rates on the model's inferred scale; not calibrated physical rates |
184
| `var['fit_likelihood']` | Relative model-fit diagnostic; not a posterior probability of biological truth |
185
| `uns['velocity_graph']` | Sparse positive cosine correlations for candidate transitions; not row-stochastic |
186
| `obsm['velocity_umap']` | Projected vectors, only after embedding computation/plotting |
187
| `obs['velocity_pseudotime']` | Graph-based relative ordering |
188
| `obs['latent_time']` | Coupled dynamical ordering; normally scaled 0–1, not elapsed hours |
189
| `obs['velocity_length']` | Processed-space vector magnitude; not physical cell speed |
190
| `obs['velocity_confidence']` | Neighbor velocity coherence, not calibrated uncertainty |
191
192
For fate probabilities use an explicitly normalized transition kernel and a
193
validated terminal-state definition; see the optional CellRank example in the
194
reference. PAGA requires optional igraph and compatible Scanpy internals; it is
195
not part of the tested core workflow or a substitute for fate inference.
196
197
## Troubleshooting
198
199
| Problem | Action |
200
| --- | --- |
201
| Missing or mismatched layers | Revisit quantification and explicit ID alignment; X cannot substitute for unspliced counts |
202
| Very few velocity genes | Inspect depth, state coverage and phase portraits before altering thresholds |
203
| Smooth but implausible arrows | Check model assumptions, batch geometry and individual genes; compare independent evidence |
204
| Nonfinite fit or empty graph | Stop interpretation and investigate degenerate features/coverage |
205
| Excessive memory or fitting time | Use a justified gene set and `n_jobs=1`; account for dense moments and fit arrays |
206
| Stochastic failure on NumPy 2 | Use a separately validated compatible legacy stack or explicitly reconsider the model |
207
| pandas `unique` error in fit/plot | Use the tested pandas 2.3.3 pin |
208
209
## Sources and verification scope
210
211
Reviewed 2026-10-01 against the [released source](https://github.com/theislab/scvelo/tree/v0.3.4),
212
[API](https://scvelo.readthedocs.io/en/latest/api.html),
213
[kinetic-model caveats](https://scvelo.readthedocs.io/en/latest/perspectives/Perspectives.html),
214
and [AnnData loom reader](https://anndata.readthedocs.io/en/stable/generated/anndata.io.read_loom.html).
215
The main paper is [Bergen et al., 2020](https://doi.org/10.1038/s41587-020-0591-3).
216
Synthetic execution tests verify software contracts and file/figure production;
217
they do not establish biological accuracy, identifiability or dataset-specific
218
parameter recovery. Optional CellRank/PAGA analyses remain source-reviewed,
219
illustrative extensions. No authenticated remote service is used.
220