Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Seurat merged object for pseudo time analysis in Monocle 3 #2833

Closed
CaroSegami opened this issue Apr 8, 2020 · 17 comments
Closed

Using Seurat merged object for pseudo time analysis in Monocle 3 #2833

CaroSegami opened this issue Apr 8, 2020 · 17 comments

Comments

@CaroSegami
Copy link

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.

@KinSimon96
Copy link

KinSimon96 commented Apr 9, 2020

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 <- try@active.ident
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!

@CaroSegami
Copy link
Author

Thanks a lot! It worked!

@satijalab
Copy link
Collaborator

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

@mojaveazure
Copy link
Member

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

@CaroSegami
Copy link
Author

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"

@mojaveazure
Copy link
Member

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

@CaroSegami
Copy link
Author

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

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

@CaroSegami
Copy link
Author

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.

@vlcm2019
Copy link

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

@ahoffrichter
Copy link

ahoffrichter commented May 7, 2020

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

@nbahlis
Copy link

nbahlis commented Jun 19, 2020

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"

@chlee-tabin
Copy link
Contributor

@GhobrialMoheb
Copy link

@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

@qoiopipq
Copy link

qoiopipq commented Apr 7, 2021

@Mohebg1234 same issue

Have you figured out how to do it using SeuratWrappers? Or have to do it manually?

@vicscott
Copy link

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 <- try@active.ident
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!

So great, it can even help me at 2022!

@paulatn240
Copy link

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 <- try@active.ident
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!

Thank you very much! It works for me, I just had to change preprocess_aux for reduce_dim_aux :)

@qimiaonnegliguo
Copy link

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 <- try@active.ident
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!

hi thanks for your great work. I have a small question. If im working on an integrated Seurat object, should I use 'integrated' instead of 'RNA' assay? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests