This vigettte demonstrates how to run trajectory inference and pseudotime calculations with Monocle 3 on Seurat objects. If you use Monocle 3, please cite:
The single-cell transcriptional landscape of mammalian organogenesis
Junyue Cao, Malte Spielmann, Xiaojie Qiu, Xingfan Huang, Daniel M. Ibrahim, Andrew J. Hill, Fan Zhang, Stefan Mundlos, Lena Christiansen, Frank J. Steemers, Cole Trapnell & Jay Shendure
doi: 10.1038/s41586-019-0969-x
Website: https://cole-trapnell-lab.github.io/monocle3/
knitr::opts_chunk$set( tidy = TRUE, tidy.opts = list(width.cutoff = 95), message = FALSE, warning = FALSE, fig.height = 10, fig.width = 16 )
Prerequisites to install:
if (!requireNamespace("monocle3", quietly = TRUE)) { setRepositories(ind = 1:2) remotes::install_github( repo = "cole-trapnell-lab/monocle3", upgrade = FALSE ) }
library(monocle3) library(Seurat) library(SeuratData) library(SeuratWrappers) library(ggplot2) library(patchwork) library(magrittr)
InstallData("hcabm40k") data("hcabm40k")
hcabm40k <- SplitObject(hcabm40k, split.by = "orig.ident") for (i in seq_along(hcabm40k)) { hcabm40k[[i]] <- NormalizeData(hcabm40k[[i]]) %>% FindVariableFeatures() } features <- SelectIntegrationFeatures(hcabm40k) for (i in seq_along(along.with = hcabm40k)) { hcabm40k[[i]] <- ScaleData(hcabm40k[[i]], features = features) %>% RunPCA(features = features) }
anchors <- FindIntegrationAnchors( hcabm40k, reference = c(1, 2), reduction = "rpca", dims = 1:30 ) integrated <- IntegrateData(anchors, dims = 1:30)
integrated <- ScaleData(integrated) integrated <- RunPCA(integrated) integrated <- RunUMAP(integrated, dims = 1:30, reduction.name = "UMAP") integrated <- FindNeighbors(integrated, dims = 1:30) integrated <- FindClusters(integrated) DimPlot(integrated, group.by = c("orig.ident", "ident"))
con <- url("https://seurat.nygenome.org/monocle3/hcabm40k_integrated.Rds") integrated <- readRDS(file = con) close(con = con) DimPlot(object = integrated, group.by = c("orig.ident", "ident"))
cds <- as.cell_data_set(integrated) cds <- cluster_cells(cds) p1 <- plot_cells(cds, show_trajectory_graph = FALSE) p2 <- plot_cells(cds, color_cells_by = "partition", show_trajectory_graph = FALSE) wrap_plots(p1, p2)
rm(integrated) gc(verbose = FALSE)
integrated.sub <- subset(as.Seurat(cds), monocle3_partitions == 1) cds <- as.cell_data_set(integrated.sub) cds <- learn_graph(cds) plot_cells( cds, label_groups_by_cluster = FALSE, label_leaves = FALSE, label_branch_points = FALSE )
gc(verbose = FALSE)
max.avp <- which.max(unlist(FetchData(integrated.sub, "AVP"))) max.avp <- colnames(integrated.sub)[max.avp] cds <- order_cells(cds, root_cells = max.avp) plot_cells( cds, color_cells_by = "pseudotime", label_cell_groups = FALSE, label_leaves = FALSE, label_branch_points = FALSE ) # Set the assay back as "integrated" integrated.sub <- as.Seurat(cds, assay = "integrated") FeaturePlot(integrated.sub, "monocle3_pseudotime")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.