satijalab / seurat-wrappers

Community-provided extensions to Seurat
GNU General Public License v3.0
307 stars 131 forks source link

[monocle3] Error in converting cell_data_set to Seurat object with function "as.Seurat()" #207

Open jcshuy opened 15 hours ago

jcshuy commented 15 hours ago

Hi everyone. Apologies if this has been answered already but I haven't been able to find a working solution yet. I am trying to run a pseudotime analysis with a v3 Seurat object which was integrated using harmony. The analysis runs fine until I try to convert the cell_data_set object back into a Seurat object using the "as.Seurat()" function. Upon running this code code:

library(SeuratWrappers)
library(monocle3)
options(Seurat.object.assay.version = "v3")
cds <- as.cell_data_set(seuratObject)
gc(full = T)
cds <- cluster_cells(cds)
p1 <- plot_cells(cds, color_cells_by = "cluster", show_trajectory_graph = FALSE)
p2 <- plot_cells(cds, color_cells_by = "seurat_clusters", show_trajectory_graph = FALSE, label_groups_by_cluster = TRUE)
wrap_plots(p1, p2)
cds <- learn_graph(cds)
cds <- order_cells(cds, root_cells = colnames(cds[,clusters(cds) == c("10")]))
plot_cells(cds,
           color_cells_by = "pseudotime",
           group_cells_by = "seurat_clusters",
           label_cell_groups = FALSE,
           label_groups_by_cluster=FALSE,
           label_leaves=TRUE,
           label_branch_points=FALSE,
           label_roots = FALSE,
           cell_size = 0.6,
           trajectory_graph_color = "BLACK")
pseudotime <- as.Seurat(cds, assay = NULL)

I get the result: Error in validObject(object = value) : invalid class "DimReduc" object: colnames for 'feature.loadings' must start with reduction key (PC_)

I confirmed that the Seurat object has colnames starting with "PC_", but when looking at the feature loadings from the cell_data_set object the colnames are all from the harmony reduction ("harmony_1", "harmony_2", ..., "harmony_50")

Trying to convert to a Seurat object manually ends up with no reductions at all (including the monocle3_pseudotime reduction). The results don't change upon updating the Seurat Object to v5 either.

Has anyone else been able to work around this?