domains / science / rna-velocity-analysis / scvelo

scvelo

Skill card

combined

The two skills describe the same high-level task (RNA velocity with scVelo) but diverge significantly on implementation details, version compatibility, and workflow steps. The K-Dense-AI skill is a highly specific, version-pinned (scVelo 0.3.4, Python 3.13) workflow that explicitly warns against using the stochastic model due to NumPy 2 incompatibility and provides a bundled script. The FreedomIntelligence skill is a general, version-agnostic tutorial that recommends the stochastic model for exploratory analysis and uses older API calls (like `scv.read` and `scv.DataFrame`) that the K-Dense-AI skill notes are removed or deprecated in newer versions. Because they disagree on the recommended model (stochastic vs. dynamical) and the valid API surface, crowning one would hide a real alternative approach or lead to errors if the user's environment matches the other skill's assumptions.

Repositories

RepositoryPath
K-Dense-AI/scientific-agent-skillsskills/scvelo/SKILL.md
FreedomIntelligence/OpenClaw-Medical-Skillsskills/scvelo/SKILL.md

Other copies

RoleRepositoryPath
peerK-Dense-AI/scientific-agent-skillsskills/scvelo/SKILL.md
peerFreedomIntelligence/OpenClaw-Medical-Skillsskills/scvelo/SKILL.md

Combined skill

# scVelo RNA Velocity Analysis

## Overview
Perform RNA velocity analysis to infer cell state transitions, trajectory directions, and driver genes from spliced and unspliced single-cell RNA counts.

## Prerequisites
- **Data**: AnnData object with `layers['spliced']` and `layers['unspliced']` containing raw, non-negative counts.
- **Environment**: 
  - **Modern Stack (scVelo 0.3.4+)**: Python 3.13, NumPy 2.x. **Note**: Stochastic model is incompatible with NumPy 2. Use Dynamical model only.
  - **Legacy Stack**: Python 3.10/3.11, NumPy <2. Required if you wish to use the Stochastic model.

## Workflow

### 1. Data Loading
- **Modern (scVelo 0.3.4+)**: Use `anndata.read_h5ad()` or `anndata.io.read_loom()`. Do not use `scv.read`.
- **Legacy**: `scv.read()` may be available. Check your version.

### 2. Preprocessing
```python
import scvelo as scv
import scanpy as sc

# Filter and normalize
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)

# Compute moments (requires neighbors)
sc.pp.neighbors(adata, n_neighbors=30, n_pcs=30)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)
```

### 3. Velocity Estimation
**Choose based on environment:**

**Option A: Dynamical Model (Recommended for Modern Stack)**
```python
scv.tl.recover_dynamics(adata, n_jobs=4)
scv.tl.velocity(adata, mode='dynamical')
scv.tl.velocity_graph(adata)
```

**Option B: Stochastic Model (Legacy Stack Only)**
```python
# WARNING: Fails with NumPy 2.x
scv.tl.velocity(adata, mode='stochastic')
scv.tl.velocity_graph(adata)
```

### 4. Latent Time & Driver Genes
```python
# Latent time (Dynamical model only)
scv.tl.latent_time(adata)

# Rank velocity genes
scv.tl.rank_velocity_genes(adata, groupby='leiden', min_corr=0.3)
# Note: Access results via adata.uns['rank_velocity_genes'] directly if scv.DataFrame is unavailable
```

### 5. Visualization
```python
# Stream plot
scv.pl.velocity_embedding_stream(adata, basis='umap', color='leiden')

# Phase portraits
scv.pl.velocity(adata, ['Gene1', 'Gene2'], ncols=2)
```

## Conflicts & Notes
- **API Differences**: `scv.read` and `scv.DataFrame` are removed in scVelo 0.3.4. Use `anndata` and direct `adata.uns` access respectively.
- **Model Compatibility**: The stochastic model relies on GLS scalar assignment which fails with NumPy 2. If using a modern environment, strictly use the dynamical model.