Skip to contents

scVelo is a scalable toolkit for RNA velocity analysis in single cells. This function runs scVelo workflow on a Seurat object.

Usage

RunSCVELO(
  srt = NULL,
  assay_X = "RNA",
  slot_X = "counts",
  assay_layers = c("spliced", "unspliced"),
  slot_layers = "counts",
  adata = NULL,
  group_by = NULL,
  linear_reduction = NULL,
  nonlinear_reduction = NULL,
  basis = NULL,
  mode = "stochastic",
  fitting_by = "stochastic",
  magic_impute = FALSE,
  knn = 5,
  t = 2,
  min_shared_counts = 30,
  n_pcs = 30,
  n_neighbors = 30,
  stream_smooth = NULL,
  stream_density = 2,
  arrow_length = 5,
  arrow_size = 5,
  arrow_density = 0.5,
  denoise = FALSE,
  denoise_topn = 3,
  kinetics = FALSE,
  kinetics_topn = 100,
  calculate_velocity_genes = FALSE,
  top_n = 6,
  n_jobs = 1,
  palette = "Paired",
  palcolor = NULL,
  show_plot = TRUE,
  save = FALSE,
  dpi = 300,
  dirpath = "./",
  fileprefix = "",
  return_seurat = !is.null(srt)
)

Arguments

srt

A Seurat object.

assay_X

Assay to convert as the main data matrix (X) in the anndata object.

slot_X

Slot name for assay_X in the Seurat object.

assay_layers

Assays to convert as layers in the anndata object.

slot_layers

Slot names for the assay_layers in the Seurat object.

adata

An anndata object.

group_by

Variable to use for grouping cells in the Seurat object.

linear_reduction

Linear reduction method to use, e.g., "PCA".

nonlinear_reduction

Non-linear reduction method to use, e.g., "UMAP".

basis

The basis to use for reduction, e.g., "UMAP".

mode

Velocity estimation model to use, e.g., "stochastic".

fitting_by

Method used to fit gene velocities, e.g., "stochastic".

magic_impute

Flag indicating whether to perform magic imputation.

knn

The number of nearest neighbors for magic.MAGIC.

t

power to which the diffusion operator is powered for magic.MAGIC.

min_shared_counts

Minimum number of counts (both unspliced and spliced) required for a gene.

n_pcs

Number of principal components (PCs) used for velocity estimation.

n_neighbors

Number of nearest neighbors used for velocity estimation.

stream_smooth

Multiplication factor for scale in Gaussian kernel around grid point.

stream_density

Controls the closeness of streamlines. When density = 2 (default), the domain is divided into a 60x60 grid, whereas density linearly scales this grid. Each cell in the grid can have, at most, one traversing streamline.

arrow_length

Length of arrows.

arrow_size

Size of arrows.

arrow_density

Amount of velocities to show.

denoise

Boolean flag indicating whether to denoise.

denoise_topn

Number of genes with highest likelihood selected to infer velocity directions.

kinetics

Boolean flag indicating whether to estimate RNA kinetics.

kinetics_topn

Number of genes with highest likelihood selected to infer velocity directions.

calculate_velocity_genes

Boolean flag indicating whether to calculate velocity genes.

top_n

The number of top features to plot.

n_jobs

The number of parallel jobs to run.

palette

The palette to use for coloring cells.

palcolor

A vector of colors to use as the palette.

show_plot

Whether to show the PAGA plot.

save

Whether to save the PAGA plots.

dpi

The DPI (dots per inch) for saving the PAGA plot.

dirpath

The directory to save the PAGA plots.

fileprefix

The file prefix to use for the PAGA plots.

return_seurat

Whether to return a Seurat object instead of an anndata object. Default is TRUE.

Examples

data("pancreas_sub")
pancreas_sub <- RunSCVELO(srt = pancreas_sub, assay_X = "RNA", group_by = "SubCellType", linear_reduction = "PCA", nonlinear_reduction = "UMAP")
#> 'misc' slot is not converted.
#> 'tools' slot is not converted.
#> Error in slot(object = object, name = "features")[[layer]] <- features: more elements supplied than there are to replace
head(pancreas_sub[[]])
#>                     orig.ident nCount_RNA nFeature_RNA     S_score   G2M_score nCount_spliced nFeature_spliced
#> CAGCCGAAGCGATATA SeuratProject      10653         3295  0.33188155  0.54532743          10653             3295
#> AGTGTCATCGCCGTGA SeuratProject       4596         2053 -0.07156909 -0.08865353           4596             2053
#> GATGAAAAGTTGTAGA SeuratProject      14091         3864  0.08940628  0.77610326          14091             3864
#> CACAGTACATCCGTGG SeuratProject       5484         2510 -0.25927997 -0.25941831           5484             2510
#> CGGAGCTCATTGGGCC SeuratProject       7357         2674 -0.11764368  0.46237856           7357             2674
#> AGAGCTTGTGTGACCC SeuratProject       6498         2516 -0.11406432 -0.17830831           6498             2516
#>                  nCount_unspliced nFeature_unspliced      CellType   SubCellType Phase
#> CAGCCGAAGCGATATA             1587               1063        Ductal        Ductal   G2M
#> AGTGTCATCGCCGTGA             1199                803 Pre-endocrine Pre-endocrine    G1
#> GATGAAAAGTTGTAGA             2166               1379   Ngn3 low EP   Ngn3 low EP   G2M
#> CACAGTACATCCGTGG             1339                859     Endocrine          Beta    G1
#> CGGAGCTCATTGGGCC              976                745        Ductal        Ductal   G2M
#> AGAGCTTGTGTGACCC              822                591        Ductal        Ductal    G1
names(pancreas_sub@assays)
#> [1] "RNA"       "spliced"   "unspliced"

FeatureDimPlot(pancreas_sub, c("stochastic_length", "stochastic_confidence"))
#> Warning: stochastic_length,stochastic_confidence are not in the features of srt.
#> Error in FeatureDimPlot(pancreas_sub, c("stochastic_length", "stochastic_confidence")): There are no valid features present.
FeatureDimPlot(pancreas_sub, "stochastic_pseudotime")
#> Warning: stochastic_pseudotime are not in the features of srt.
#> Error in FeatureDimPlot(pancreas_sub, "stochastic_pseudotime"): There are no valid features present.
VelocityPlot(pancreas_sub, reduction = "UMAP", plot_type = "stream")
#> Error in VelocityPlot(pancreas_sub, reduction = "UMAP", plot_type = "stream"): Cannot find the velocity embedding stochastic_UMAP.
CellDimPlot(pancreas_sub, group.by = "SubCellType", reduction = "UMAP", pt.size = NA, velocity = "stochastic")
#> Error in VelocityPlot(srt, cells = cells, reduction = reduction, dims = dims,     velocity = velocity, plot_type = velocity_plot_type, group_by = group.by,     group_palette = palette, group_palcolor = palcolor, n_neighbors = velocity_n_neighbors,     density = velocity_density, smooth = velocity_smooth, scale = velocity_scale,     min_mass = velocity_min_mass, cutoff_perc = velocity_cutoff_perc,     arrow_color = velocity_arrow_color, arrow_angle = velocity_arrow_angle,     streamline_L = streamline_L, streamline_minL = streamline_minL,     streamline_res = streamline_res, streamline_n = streamline_n,     streamline_width = streamline_width, streamline_alpha = streamline_alpha,     streamline_color = streamline_color, streamline_palette = streamline_palette,     streamline_palcolor = streamline_palcolor, streamline_bg_color = streamline_bg_color,     streamline_bg_stroke = streamline_bg_stroke, aspect.ratio = aspect.ratio,     title = title, subtitle = subtitle, xlab = xlab, ylab = ylab,     legend.position = "bottom", legend.direction = legend.direction,     theme_use = theme_void, theme_args = theme_args, return_layer = TRUE): Cannot find the velocity embedding stochastic_UMAP.

pancreas_sub <- Standard_SCP(pancreas_sub, normalization_method = "SCT", nonlinear_reduction = "tsne")
#> [2023-11-21 07:49:51.319034] Start Standard_SCP
#> [2023-11-21 07:49:51.319229] Checking srtList... ...
#> Perform FindVariableFeatures on the data 1/1 of the srtList...
#> Perform SCTransform on the data 1 of the srtList...
#> Use the separate HVF from srtList...
#> Number of available HVF: 2000
#> [2023-11-21 07:49:58.639701] Finished checking.
#> [2023-11-21 07:49:58.63984] Perform linear dimension reduction (pca) on the data...
#> Warning: The following arguments are not used: force.recalc
#> Warning: The following arguments are not used: force.recalc
#> [2023-11-21 07:49:59.16628] Perform FindClusters (louvain) on the data...
#> [2023-11-21 07:49:59.243687] Reorder clusters...
#> [2023-11-21 07:49:59.313644] Perform nonlinear dimension reduction (tsne) on the data...
#> Non-linear dimensionality reduction(tsne) using Reduction(Standardpca, dims:1-11) as input
#> Non-linear dimensionality reduction(tsne) using Reduction(Standardpca, dims:1-11) as input
#> [2023-11-21 07:50:04.013638] Standard_SCP done
#> Elapsed time: 12.69 secs 
pancreas_sub <- RunSCVELO(srt = pancreas_sub, assay_X = "SCT", group_by = "SubCellType", linear_reduction = "Standardpca", nonlinear_reduction = "StandardTSNE2D")
#> Assay 'RNA' is in the srt object but not converted.
#> 'misc' slot is not converted.
#> 'tools' slot is not converted.
#> Error in slot(object = object, name = "features")[[layer]] <- features: more elements supplied than there are to replace