Seurat: Using Seurat merged object for pseudo time analysis in Monocle 3

Created on 8 Apr 2020  路  13Comments  路  Source: satijalab/seurat

I have an SCTtransformed merged Seurat object and I would like to follow up with a pseudo time analysis. I've seen that last year Seurat didn't support conversion of Seurat objects to Monocle 3 cds because it was still beta. Is this still the case? Which pseudo time analysis that could be compatible with Seurat object would you recommend? I expect my data to be linear rather than branched. Thank you.

Most helpful comment

Hello,
Here is how I convert the object of class Seurat into a cds object (Monocle3) for pseudotime analysis. Eveything will be unchanged. I don't know if it will work with SCTransformed, but you should be able to do your own modifications with the code below. My Seurat object here is try

gene_annotation <- as.data.frame(rownames(try@reductions[["pca"]]@feature.loadings),
                                 row.names = rownames(try@reductions[["pca"]]@feature.loadings))
colnames(gene_annotation) <- "gene_short_name"


cell_metadata <- as.data.frame(try@assays[["RNA"]]@counts@Dimnames[[2]],
                               row.names = try@assays[["RNA"]]@counts@Dimnames[[2]])
colnames(cell_metadata) <- "barcode"


New_matrix <- try@assays[["RNA"]]@counts
New_matrix <- New_matrix[rownames(try@reductions[["pca"]]@feature.loadings), ]
expression_matrix <- New_matrix

library(monocle3)

cds_from_seurat <- new_cell_data_set(expression_matrix,
                                     cell_metadata = cell_metadata,
                                     gene_metadata = gene_annotation)


recreate.partition <- c(rep(1, length(cds_from_seurat@colData@rownames)))
names(recreate.partition) <- cds_from_seurat@colData@rownames
recreate.partition <- as.factor(recreate.partition)

cds_from_seurat@clusters@listData[["UMAP"]][["partitions"]] <- recreate.partition



list_cluster <- [email protected]
names(list_cluster) <- try@assays[["RNA"]]@data@Dimnames[[2]]

cds_from_seurat@clusters@listData[["UMAP"]][["clusters"]] <- list_cluster



cds_from_seurat@clusters@listData[["UMAP"]][["louvain_res"]] <- "NA"


cds_from_seurat@int_colData@listData$reducedDims@listData[["UMAP"]] <-try@reductions[["umap"]]@cell.embeddings


cds_from_seurat@preprocess_aux$gene_loadings <- try@reductions[["pca"]]@feature.loadings

Then perform pseudotime analysis:

cds_from_seurat <- learn_graph(cds_from_seurat, use_partition = F)

plot_cells(cds_from_seurat, 
                   color_cells_by = 'cluster',
                   label_groups_by_cluster=TRUE,
                   label_leaves=FALSE,
                   label_branch_points=TRUE,
           graph_label_size=4)

Hope it will help. Good luck!

All 13 comments

Hello,
Here is how I convert the object of class Seurat into a cds object (Monocle3) for pseudotime analysis. Eveything will be unchanged. I don't know if it will work with SCTransformed, but you should be able to do your own modifications with the code below. My Seurat object here is try

gene_annotation <- as.data.frame(rownames(try@reductions[["pca"]]@feature.loadings),
                                 row.names = rownames(try@reductions[["pca"]]@feature.loadings))
colnames(gene_annotation) <- "gene_short_name"


cell_metadata <- as.data.frame(try@assays[["RNA"]]@counts@Dimnames[[2]],
                               row.names = try@assays[["RNA"]]@counts@Dimnames[[2]])
colnames(cell_metadata) <- "barcode"


New_matrix <- try@assays[["RNA"]]@counts
New_matrix <- New_matrix[rownames(try@reductions[["pca"]]@feature.loadings), ]
expression_matrix <- New_matrix

library(monocle3)

cds_from_seurat <- new_cell_data_set(expression_matrix,
                                     cell_metadata = cell_metadata,
                                     gene_metadata = gene_annotation)


recreate.partition <- c(rep(1, length(cds_from_seurat@colData@rownames)))
names(recreate.partition) <- cds_from_seurat@colData@rownames
recreate.partition <- as.factor(recreate.partition)

cds_from_seurat@clusters@listData[["UMAP"]][["partitions"]] <- recreate.partition



list_cluster <- [email protected]
names(list_cluster) <- try@assays[["RNA"]]@data@Dimnames[[2]]

cds_from_seurat@clusters@listData[["UMAP"]][["clusters"]] <- list_cluster



cds_from_seurat@clusters@listData[["UMAP"]][["louvain_res"]] <- "NA"


cds_from_seurat@int_colData@listData$reducedDims@listData[["UMAP"]] <-try@reductions[["umap"]]@cell.embeddings


cds_from_seurat@preprocess_aux$gene_loadings <- try@reductions[["pca"]]@feature.loadings

Then perform pseudotime analysis:

cds_from_seurat <- learn_graph(cds_from_seurat, use_partition = F)

plot_cells(cds_from_seurat, 
                   color_cells_by = 'cluster',
                   label_groups_by_cluster=TRUE,
                   label_leaves=FALSE,
                   label_branch_points=TRUE,
           graph_label_size=4)

Hope it will help. Good luck!

Thanks a lot! It worked!

This is very helpful - thanks! We're preparing to release some updates as well to make this a bit easier, stay tuned!

Beta Monocle 3 support us available on SeuratWrappers on the feat/monocle3 branch. Conversion to and from Seurat objects is available with as.cell_data_set and as.Seurat

Hi @mojaveazure, I couldn't make the as.cell_data_set command work after installing SeuratWrappers:

library(SeuratWrappers)
cds<-as.cell_data_set(my_seurat_object)

It gives me:

Error in as.cell_data_set(my_seurat_object) :
could not find function "as.cell_data_set"

You need to use the feat/monocle3 branch of SeuratWrappers, not the master or develop branches.

How do I do that?
Is the installation different?
I used this:

devtools::install_github('satijalab/seurat-wrappers')

Nevermind! I managed, but when I try to run "learn_graph" from Monocle3 it gives me this error:

No dimensionality reduction for UMAP calculated. Please run reduce_dimensions with reduction_method = UMAP and cluster_cells before running learn_graph.

Does this mean that it didn't save all the characteristics of the previous merged Seurat object? I could directly run the learn_graph with the cds object resulting from the code above.

Thank you KinSimon96 for sharing your code. It worked for pseudotime analysis.

I had to change

cds_from_seurat@int_colData@listData$reducedDims@listData[["UMAP"]] <-try@reductions[["umap"]]@cell.embeddings

to

cds_from_seurat@reducedDims@listData[["UMAP"]] <-try@reductions[["umap"]]@cell.embeddings

in @KinSimon96 's solution to make it work for me.
Thanks for the workaround!

Edit: Unfortunately, I get stuck at the order_cells command with this. The shiny window opens, but I get an error message:

object 'V1' not found

With the original solution though, I got an Error at:

cds_from_seurat@int_colData@listData$reducedDims@listData[["UMAP"]] <-try@reductions[["umap"]]@cell.embeddings

Error in [...] trying to get slot "listData" from an object of a basic class ("NULL") with no slots

I downloaded the develop version of monocle 3 but I still get this error below, any help is greatly appreciated

cds <- as.cell_data_set(integrated)
Error in as.cell_data_set(integrated) :
could not find function "as.cell_data_set"

install SeuratWrappers and follow https://htmlpreview.github.io/?https://github.com/satijalab/seurat-wrappers/blob/master/docs/monocle3.html

@mojaveazure , thanks for the update in seuratwrappers, I have a question regarding plotting in tSNE, rather than UMAP?
It seems that I can only plot UMAP, rather than tSNE in the cell dataset object converted from Seurat

Was this page helpful?
0 / 5 - 0 ratings

Related issues

camilliano picture camilliano  路  3Comments

igordot picture igordot  路  3Comments

mvalenzuelav picture mvalenzuelav  路  3Comments

GHAStVHenry picture GHAStVHenry  路  3Comments

sarahwajid picture sarahwajid  路  3Comments