This vignette demonstrates analysing RNA Velocity quantifications stored in a Seurat object using scVelo. If you use scVelo in your work, please cite:

Generalizing RNA velocity to transient cell states through dynamical modeling

Volker Bergen, Marius Lange, Stefan Peidli, F. Alexander Wolf & Fabian J. Theis

doi: 10.1101/820936

Website: https://scvelo.readthedocs.io/

python3 <- Sys.which(names = c("python3.6", "python3"))
python3 <- unname(obj = Filter(f = nchar, x = python3))[1]
library(reticulate)
reticulate::use_python(python = python3, required = TRUE)
knitr::opts_chunk$set(
  tidy = TRUE,
  tidy.opts = list(width.cutoff = 95),
  message = FALSE,
  warning = FALSE,
  fig.height = 10,
  fig.width = 16
)
if (!requireNamespace("SeuratDisk", quietly = TRUE)) {
  remotes::install_github(repo = "mojaveazure/seurat-disk", upgrade = FALSE)
}
if (!py_module_available(module = "scvelo")) {
  pip3 <- Sys.which(names = "pip3")[1]
  if (!nchar(x = pip3)) {
    stop("Cannot find pip3 or scvelo", call. = FALSE)
  }
  system2(command = pip3, args = c("install", "scvelo"))
}

Prerequisites to install:

library(Seurat)
library(SeuratDisk)
library(SeuratWrappers)
if (file.exists("mouseBM.h5Seurat")) {
  file.remove("mouseBM.h5Seurat")
}
if (file.exists("mouseBM.h5ad")) {
  file.remove("mouseBM.h5ad")
}
dir.create("~/Downloads", showWarnings = FALSE, recursive = TRUE)
curl::curl_download(
  url = "http://pklab.med.harvard.edu/velocyto/mouseBM/SCG71.loom",
  destfile = "~/Downloads/SCG71.loom"
)
# If you don't have velocyto's example mouse bone marrow dataset, download with the CURL command
# curl::curl_download(url = "http://pklab.med.harvard.edu/velocyto/mouseBM/SCG71.loom", destfile = "~/Downloads/SCG71.loom")
ldat <- ReadVelocity(file = "~/Downloads/SCG71.loom")
bm <- as.Seurat(x = ldat)
bm[["RNA"]] <- bm[["spliced"]]
bm <- SCTransform(bm)
bm <- RunPCA(bm)
bm <- RunUMAP(bm, dims = 1:20)
bm <- FindNeighbors(bm, dims = 1:20)
bm <- FindClusters(bm)
DefaultAssay(bm) <- "RNA"
SaveH5Seurat(bm, filename = "mouseBM.h5Seurat")
Convert("mouseBM.h5Seurat", dest = "h5ad")

```{python load_adata, eval=TRUE}

In Python

import scvelo as scv adata = scv.read("mouseBM.h5ad") adata

```{python scvelo, results="hide", eval=TRUE}
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)
scv.tl.velocity(adata)
scv.tl.velocity_graph(adata)
scv.pl.velocity_embedding_stream(adata, basis="umap", color="seurat_clusters")
scv.pl.velocity_embedding(adata, basis="umap", color="seurat_clusters", arrow_length=3, arrow_size=2, dpi=120)

{python latent_time, results="hide", eval=TRUE} scv.tl.recover_dynamics(adata) scv.tl.latent_time(adata) scv.pl.scatter(adata, color="latent_time", color_map="gnuplot") top_genes = adata.var["fit_likelihood"].sort_values(ascending=False).index[:300] scv.pl.heatmap(adata, var_names=top_genes, sortby="latent_time", col_color="seurat_clusters", n_convolve=100)



satijalab/seurat-wrappers documentation built on April 10, 2024, 3:25 p.m.