Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/satijalab/seurat-wrappers/llms.txt

Use this file to discover all available pages before exploring further.

This page demonstrates how to compute RNA velocity quantifications stored in a Seurat object using SeuratWrappers and velocyto.R.
RNA velocity of single cells Gioele La Manno, Ruslan Soldatov, Amit Zeisel, Emelie Braun, Hannah Hochgerner, Viktor Petukhov, Katja Lidschreiber, Maria E. Kastriti, Peter Lönnerberg, Alessandro Furlan, Jean Fan, Lars E. Borm, Zehua Liu, David van Bruggen, Jimin Guo, Xiaoling He, Roger Barker, Erik Sundström, Gonçalo Castelo-Branco, Patrick Cramer, Igor Adameyko, Sten Linnarsson & Peter V. Kharchenko Nature, 2018. doi: 10.1038/s41586-018-0414-6
For the scVelo (Python) extension, see:
Generalizing RNA velocity to transient cell states through dynamical modeling Volker Bergen, Marius Lange, Stefan Peidli, F. Alexander Wolf & Fabian J. Theis bioRxiv, 2019. doi: 10.1101/820936

Installation

The following packages are required before proceeding:
remotes::install_github('velocyto-team/velocyto.R')
library(Seurat)
library(velocyto.R)
library(SeuratWrappers)

Workflow

1

Generate a loom file with velocyto

Before using ReadVelocity(), you must run the velocyto command-line tool on your aligned BAM files to produce a .loom file containing spliced, unspliced, and ambiguous count matrices.See the velocyto documentation for instructions on generating loom files from your alignment output.
2

Load velocity data

Use ReadVelocity() to load the loom file into R. This is a wrapper around velocyto.R::read.loom.matrices() that redirects progress output to stderr rather than stdout.
# Download example mouse bone marrow dataset (if needed)
# curl::curl_download(
#   url = 'http://pklab.med.harvard.edu/velocyto/mouseBM/SCG71.loom',
#   destfile = '~/Downloads/SCG71.loom'
# )
ldat <- ReadVelocity(file = "~/Downloads/SCG71.loom")
The result is a named list of sparse matrices: typically spliced, unspliced, and ambiguous.
3

Create a Seurat object from velocity matrices

Pass the list of matrices to as.Seurat(). Each matrix becomes a separate assay. The default assay is the first in the list (or the one specified by default.assay).
bm <- as.Seurat(x = ldat)
4

Preprocess and cluster

Run standard Seurat preprocessing on the spliced assay before computing velocity.
bm <- SCTransform(object = bm, assay = "spliced")
bm <- RunPCA(object = bm, verbose = FALSE)
bm <- FindNeighbors(object = bm, dims = 1:20)
bm <- FindClusters(object = bm)
bm <- RunUMAP(object = bm, dims = 1:20)
5

Compute RNA velocity

RunVelocity() filters genes by minimum cluster-level expression, computes a cell-to-cell distance matrix from the PCA embedding, and calls velocyto.R::gene.relative.velocity.estimates(). Results are stored in the Seurat object via Tool(object) <- cd.
bm <- RunVelocity(
  object = bm,
  deltaT = 1,
  kCells = 25,
  fit.quantile = 0.02
)
6

Visualize velocity

Retrieve the velocity estimates with Tool() and visualize arrows on a low-dimensional embedding using velocyto.R::show.velocity.on.embedding.cor().
ident.colors <- (scales::hue_pal())(n = length(x = levels(x = bm)))
names(x = ident.colors) <- levels(x = bm)
cell.colors <- ident.colors[Idents(object = bm)]
names(x = cell.colors) <- colnames(x = bm)

show.velocity.on.embedding.cor(
  emb = Embeddings(object = bm, reduction = "umap"),
  vel = Tool(object = bm, slot = "RunVelocity"),
  n = 200,
  scale = "sqrt",
  cell.colors = ac(x = cell.colors, alpha = 0.5),
  cex = 0.8,
  arrow.scale = 3,
  show.grid.flow = TRUE,
  min.grid.cell.mass = 0.5,
  grid.n = 40,
  arrow.lwd = 1,
  do.par = FALSE,
  cell.border.alpha = 0.1
)

Functions

ReadVelocity()

Loads a velocyto-generated .loom file and returns a named list of count matrices (spliced, unspliced, ambiguous). This wraps velocyto.R::read.loom.matrices() and redirects its progress messages to stderr so they do not pollute standard output.
file
string
required
Path to the .loom file produced by the velocyto command-line tool.
engine
string
default:"hdf5r"
Backend to use when reading the HDF5-based loom file. Choose from "hdf5r" or "h5".
verbose
boolean
default:"TRUE"
Whether to display progress messages from velocyto.R::read.loom.matrices().

RunVelocity()

Computes RNA velocity on a Seurat object that contains both spliced and unspliced assays. Gene filtering, cell-to-cell distance calculation, and velocity estimation are all performed inside this function. The resulting velocity object is stored using Tool(object) <- cd and can be retrieved with Tool(object, slot = "RunVelocity").
object
Seurat
required
A Seurat object containing at minimum a spliced and unspliced assay.
spliced
string
default:"spliced"
Name of the assay containing spliced RNA counts.
unspliced
string
default:"unspliced"
Name of the assay containing unspliced (nascent) RNA counts.
ambiguous
string
Optional name of the assay containing ambiguously spliced counts. Pass NULL to omit.
spliced.average
number
default:"0.2"
Minimum required average expression count across clusters in the spliced matrix. Genes below this threshold are excluded before velocity estimation.
unspliced.average
number
default:"0.05"
Minimum required average expression count across clusters in the unspliced matrix.
reduction
string
default:"pca"
Name of the dimensional reduction whose embeddings are used to compute the cell-to-cell distance matrix.
group.by
string
default:"ident"
Name of the cell-level metadata variable (or "ident" for active identities) used to define clusters for gene filtering.
cells
character vector
Subset of cells to use as steady-state cells (passed to gene.relative.velocity.estimates as steady.state.cells). Defaults to all cells.
graph
string
Optional name of a nearest-neighbor graph in the Seurat object to pass as cellKNN to the velocity estimator.
ncores
number
default:"1"
Number of cores to use for parallel computation.
verbose
boolean
default:"TRUE"
Whether to display progress messages during gene filtering and distance matrix computation.

as.Seurat() for lists

Converts a named list of matrices (as returned by ReadVelocity()) into a Seurat object where each matrix becomes a separate assay.
x
list
required
A named list of dense (matrix) or sparse (dgCMatrix) matrices. Unnamed entries are assigned names Assay1, Assay2, etc.
default.assay
string or number
default:"1"
Name or index of the matrix to set as the default assay.
slot
string
default:"counts"
Slot in which to store each matrix. Must be "counts" or "data". Vectorized: different values can be specified per matrix.
min.cells
number
default:"0"
Minimum number of cells a feature must be detected in (applied only to matrices stored in counts). Vectorized.
min.features
number
default:"0"
Minimum number of features detected per cell (applied only to matrices stored in counts). Vectorized.
verbose
boolean
default:"TRUE"
Whether to show a progress bar while constructing the Seurat object.

Build docs developers (and LLMs) love