Goal
Run reusable RNA velocity analysis on a velocity-ready AnnData: map spliced/unspliced layers if needed, fit moments and dynamics, estimate velocity, build the velocity graph, compute UMAP/Leiden, and render the stream plot. Use this same skill for method-comparison notebooks that branch across scvelo, dynamo, latentvelo, and graphvelo. If you still need FASTQ -> h5ad generation, hand off to the kb alignment skill first.
Quick Workflow
- Start from a velocity-ready
AnnData. - Map source-specific layers such as
mature/nascenttospliced/unsplicedwhen needed. - Pick the branch trio up front:
recipe,backend, andmethod. - Instantiate
ov.single.Velo(adata)and runfilter_genes,preprocess,moments,dynamics, andcal_velocity. - Build the velocity graph, neighbors, UMAP, Leiden, and velocity embedding.
- If the notebook includes a GraphVelo refinement stage, run it after an initial velocity layer exists.
- Plot the embedding and stream plot.
- Validate the stored keys before treating the result as finished.
Interface Summary
ov.single.Velo(adata)creates the velocity workflow wrapper.Velo.filter_genes(min_shared_counts=20)keeps velocity-usable genes.Velo.preprocess(recipe='monocle', n_neighbors=30, n_pcs=30, **kwargs)uses Dynamo preprocessing and then builds a PCA-based neighbor graph.Velo.moments(backend='dynamo'|'scvelo', ...)andVelo.dynamics(backend='dynamo'|'scvelo', ...)branch on the requested backend.Velo.cal_velocity(method='dynamo'|'scvelo'|'latentvelo'|'graphvelo', ...)selects the velocity estimator and controls the output key family.Velo.graphvelo(xkey='Ms', vkey='velocity_S', n_jobs=1, basis_keys=['X_umap', 'X_pca'], gene_subset=...)refines an existing velocity layer and projects it to UMAP/PCA.Velo.velocity_graph(vkey='velocity_S', ...)andVelo.velocity_embedding(basis='umap', vkey='velocity_S', ...)project and store velocity outputs.ov.pp.neighbors(..., method='umap'|'gauss'|'rapids', transformer=...)builds the graph.ov.pp.umap(adata, method='umap'|'rapids'|'torchdr'|'mde'|'pumap', **kwargs)switches embedding backends.ov.pp.leiden(...)usesov.settings.modeto choose CPU, mixed, or RAPIDS execution.ov.pl.embedding(...)andov.pl.add_streamplot(...)render the final plot.
Boundary
- Keep this skill on the analysis side of the notebook.
- Do not absorb FASTQ download, reference building, or kb counting here.
- If you need raw quantification, hand off to the kb alignment skill first.
- If the notebook only changes velocity
method,backend,recipe, ormode, keep it in this skill instead of creating a duplicate skill. - If the notebook introduces a truly different analysis family or input contract, split it.
GraphVelo Refinement
- Use this branch after an initial velocity layer already exists in
adata. - Pick the matching input layer as
vkeyand use the corresponding..._genesmask when the notebook provides one. - Call
Velo.graphvelo(..., basis_keys=['X_umap', 'X_pca'])to project GraphVelo refinement back onto the existing manifold. - Then call
Velo.velocity_graph(vkey='velocity_gv', xkey='Ms', n_jobs=8)andVelo.velocity_embedding(basis='umap', vkey='velocity_gv'). - Expect GraphVelo to add
velocity_gv,velocity_gv_genes,gv_X_umap, andgv_X_pca; the downstream graph and embedding calls addvelocity_gv_graphandvelocity_gv_umap.
Branch Selection
- Use
recipe='monocle'for the notebook path; the live DynamoPreprocessoralso exposesseurat,sctransform,pearson_residuals, andmonocle_pearson_residuals. - Use
backend='scvelo'formomentsanddynamicswhen the input already has spliced/unspliced counts. - Use
backend='dynamo'when you want the Dynamo kinetics branch. - Use
method='scvelo'forcal_velocityon the portable notebook path. - Use
method='dynamo'when you want the Dynamo velocity branch. - Use
method='latentvelo'only when you have the required model inputs and a representative GPU or import-only smoke path. - Use
method='graphvelo'when you want the graph-based velocity branch; keepn_jobssmall in smoke tests. - Use
method='umap'inov.pp.neighborsunless you intentionally want thegaussorrapidsgraph branch. - Set
ov.settings.modeexplicitly beforeov.pp.umapandov.pp.leidenif you need reproducible CPU, mixed, or GPU behavior. - Use
ov.settings.cpu_init()for the portable path; usecpu_gpu_mixed_init()orgpu_init()only when the hardware and dependencies actually support those modes. - For notebook comparisons, keep the same input object and vary only the branch parameters you are studying.
Input Contract
- Begin with an
AnnDatathat already contains raw velocity counts or velocity-ready layers. - If the source layers are named
matureandnascent, rename or copy them tosplicedandunspliced. preprocessshould createX_pca;neighborsshould then consumeX_pca.velocity_embeddingand the stream plot needX_umap.- Keep the dataset large enough for stream plotting; tiny synthetic sets can fail because the grid helper derives its own neighbor count from cell number.
Minimal Execution Patterns
import omicverse as ov
import scanpy as sc
adata = sc.read_h5ad("velocity-ready.h5ad")
if "spliced" not in adata.layers and "mature" in adata.layers:
adata.layers["spliced"] = adata.layers["mature"]
if "unspliced" not in adata.layers and "nascent" in adata.layers:
adata.layers["unspliced"] = adata.layers["nascent"]
ov.settings.cpu_init()
velo = ov.single.Velo(adata)
velo.filter_genes(min_shared_counts=20)
velo.preprocess(recipe="monocle", n_neighbors=30, n_pcs=30)
velo.moments(backend="scvelo", n_neighbors=30, n_pcs=30)
velo.dynamics(backend="scvelo", n_jobs=1)
velo.cal_velocity(method="scvelo")
velo.velocity_graph(vkey="velocity_S", xkey="Ms", n_jobs=1)
ov.pp.neighbors(adata, n_neighbors=15, use_rep="X_pca")
ov.pp.umap(adata)
ov.pp.leiden(adata, resolution=0.2)
velo.velocity_embedding(basis="umap", vkey="velocity_S")
# Method-comparison branch sketch
velo.moments(backend="dynamo")
velo.dynamics(backend="dynamo")
velo.cal_velocity(method="dynamo")
velo.cal_velocity(method="graphvelo", n_jobs=1)
velo.cal_velocity(
method="latentvelo",
batch_key="batch",
celltype_key="celltype",
velocity_key="velo_latentvelo",
)
Validation
- Confirm
X_pca,X_umap, andleidenare present after preprocessing and clustering. - Confirm
Ms,Mu, the chosenvelocity_key, and the derived graph/embedding keys are present after the velocity steps. - When you keep the default
velocity_key='velocity_S', confirmvelocity_S_graphandvelocity_S_umap. - Confirm
ov.pl.add_streamplot(...)returns an axes object and does not raise. - If you switch
ov.settings.mode, confirm the backend-specific messages match the selected mode. - Validate
latentveloand any GPU-heavy path with a representative smoke or import-only interface check if a full run is not practical. - For GraphVelo smoke on synthetic data, use a broad gene subset so the internal PCA has enough features.
Resource Map
- Read
references/branch-selection.mdwhen choosing the recipe, backend, method, or mode branch. - Read
references/source-notebook-map.mdwhen you need to see how the notebook splits into comparison branches and where the skill boundary sits. - Read
references/source-grounding.mdfor inspected signatures and source behavior. - Read
references/compatibility.mdfor smoke-path caveats and runtime notes.