satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.24k stars 902 forks source link

Using Monocle 3 with Seurat 3 integrated object #1658

Closed dwucsf closed 5 years ago

dwucsf commented 5 years ago

Has anyone performed pseudotemporal ordering analysis with Monocle 3 using an object made from Seurat 3's integration function?

I'm wondering if designating only 2000 features for the integration parameter will become problematic for doing downstream analyses with Monocle 3. Thanks in advance for your help.

dwucsf commented 5 years ago

Additional follow-up question: should I be using the batch-corrected, integrated gene values in the "integrated" assay or the non-integrated gene values in the "RNA" assay for downstream Monocle analyses?

Sophia409 commented 5 years ago

@dwucsf I have the same question as you.And from one user's post,the code showed integrated assay.But i also want to know if it's OK,because satijalab said that Seurat does not return batch-corrected expression values. Instead, Seurat can be used to generate a corrected cell/cell distance matrix. If you have any progress, please let me know.Thank you!

dwucsf commented 5 years ago

I'm able to run Monocle 3 with Seurat 3's integrated cells/counts, but I'm trying to construct my CDS in such a way that it contains original RNA count and integrated count data. I haven't figured this out. Have you?

mojaveazure commented 5 years ago

Hi @dwucsf,

Seurat has support for the Monocle v2 object. However, we don't have support for Monocle v3 as it's still under development. Once Monocle v3 has been finalized and the object is no longer in development, we will work on adding support for the v3 CellDataSet object.

Monocle v2 support is present in the development version of Seurat. To install the development version of Seurat, please see the instructions here.

Sophia409 commented 5 years ago

@mojaveazure Hi, Monocle v2 has been deprecated and v3 has been finalized.Now we can only import one assay(integrated or RNA) to monocle and do further pseudotime trajectory.So we are really expecting your added support for the v3 CellDataSet object. For example,I have integrated data from mouse cells from different times,including E11,15,18,p5,p10,p30.And I want to do further linage tracing and pseudotime trajectory.My data was batch corrected,so it's not right for me to just use one assay to do analysis.Because if I import the integrated assay to monocle for clustering,monocle will automatically find markers for these cluster referring to integrated data matrix.And in fact, for data integration these values should not be interpreted, and may well contain negative values as seurat are subtracting values from datasets to remove technical differences. But if import the RNA assay to monocle for clustering,the data matrix was not batch corrected,it still not right to use it for do clustering and pseuodotime analysis. I'm really confused and waiting for your reply.Thank you! 图片

dwucsf commented 5 years ago

Just to echo what @Sophia409 has stated: If it's simple to make a Monocle v3 CellDataSet contain two assays (i.e. be able to hold both integrated counts and original RNA counts) instead of being single-assay, that would be extremely helpful! Thank you!!

dwucsf commented 5 years ago

Or, if you have other suggestions on how to approach this problem, I am more than happy to hear your suggestions!

mojaveazure commented 5 years ago

@Sophia409 and @dwucsf,

Monocle v3 is in beta and under active development. We are working on adding support for Monocle v3, but are unable to provide more details at this time. Moreover, in order for us to be able to release new versions of Seurat on CRAN, we can only depend on packages on CRAN, Bioconductor, or another CRAN-like repository. Monocle v3 is not yet on a repository, only GitHub, and as we have other improvements to Seurat in the pipeline, we want the flexibility to release on our schedule.

Rest assured, once Monocle v3 is fully released, we will build support for the v3 CellDataSet object. If Monocle v3 is multi-assay, we will add full support for those multi-assay features. We cannot offer much more until then.

AnaHowellsFerreira commented 5 years ago

following this thread! Thank you for the clarification

zihengxuwu commented 5 years ago

Final_Seurat_to_Monocle3_2D_and_3D_190719 2.txt Here is a script I wrote for the project I was involved with that concerns converting a Seurat object into a cds, if it provides any directions or guidance to anyone.

vitamindlab commented 5 years ago

@zihengxuwu ,

This script is great! Thank you for posting. The one step that gave me issues was the "Assign cluster info" step. Any advice for me if I get the warning "object 'list_cluster' not found" and "object 'cluster.res' not found"?

Sophia409 commented 5 years ago

@zihengxuwu Hello,your script imported the RNA counts not the integrated data.But I have to use the batch integrated data of Seurat.In addition, monocle3 is not the final edition,and its result trajectory is really not available for me.So I still use monocle 2 to do it.

Sophia409 commented 5 years ago

@mojaveazure Hello,I have a question.You said that Monocle v2 support is present in the development version of Seurat.So it means that we can convert seurat v3 object to monocle 2 celldataSet object through the development version?Is there any tutorial about how to make this conversion in this version?I couldn't find it. Since monocle 3 is not finished, I imported the Seurat3 integrated data to monocle2 to do analysis.Could you add monocle V2 support to Seurat 3 CRAN version?I think it does good to users.

Dragonmasterx87 commented 4 years ago

@Sophia409 @dwucsf did any of you guys figure out how to create a pseudotime plot with integrated seurat object calculations yet plot expression data on them using expression values from either the SCT DATA or RNA DATA slots?

I am also having the same problem, and feel like there has to be a way where we can plot and order based on integrated data and look at expression using data slots from either the RNA or SCT assay.....

parveendabas commented 4 years ago

Did anyone find the link to tutorial to convert seurat v3 object to monocle 2?

Dragonmasterx87 commented 4 years ago

@parveendabas try this:

seuratX <- analysis.file

#Extract data, phenotype data, and feature data from the SeuratObject
data <- as(as.matrix(seuratX@assays$RNA@data), 'sparseMatrix')

pd <- new('AnnotatedDataFrame', data = seuratX@meta.data)

fData <- data.frame(gene_short_name = row.names(data), row.names = row.names(data))
fd <- new('AnnotatedDataFrame', data = fData)

#Construct monocle cds
HSMM <- newCellDataSet(data,
                              phenoData = pd,
                              featureData = fd,
                              #lowerDetectionLimit = 0.5,
                              expressionFamily = uninormal())# since I have already normalized, thresholded and scalled in Suerat v3.0.0.9150

#View data
pData(HSMM)
fData(HSMM)

#Run ordering algorithm
var_genes <- seuratX[["RNA"]]@var.features
ordering_genes <- var_genes

HSMM <- setOrderingFilter(HSMM, ordering_genes)
print(dim(exprs(HSMM)))

## reduce dimension - do not normalize or include pseudo count. Use monocle scaling
HSMM <- reduceDimension(HSMM,norm_method="none", 
                        reduction_method="DDRTree",
                        max_components=4,
                        scaling=TRUE,
                        verbose=TRUE,
                        pseudo_expr=0)

# First decide what you want to color your cells by
print(head(pData(HSMM)))

## order cells change colors and theta to match your plot
HSMM <- orderCells(HSMM)
plot_cell_trajectory(HSMM, 
                     color_by = "seurat_clusters",
                     theta = -15,
                     show_branch_points = FALSE,
                     show_tree = TRUE,
                     cell_size = 4) + scale_color_manual(breaks = c("X", "Y", "Z"), 
                                                         values=c("red",
                                                                        "green",
                                                                        "blue")) + theme(legend.position = "right")

# now onwards to pseudotemporal plots
genex <- c("geneX", "geneY")

sig_gene_names <- (genex)
head(sig_gene_names)
pseudotemporalplot <- plot_pseudotime_heatmap(HSMM[sig_gene_names],
                        num_clusters = 9, 
                        cores = 4,
                        hmcols = NULL,
                        show_rownames = T)

pseudotemporalplot 
akshatkarambe commented 4 years ago

Final_Seurat_to_Monocle3_2D_and_3D_190719 2.txt Here is a script I wrote for the project I was involved with that concerns converting a Seurat object into a cds, if it provides any directions or guidance to anyone.

Hello,

I have been using this script and I am stuck at one place. cds_from_seurat@reducedDims@listData[["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings

This throws an error:

Error in cds_from_seurat@reducedDims@listData[["UMAP"]] <- seurat@reductions[["umap"]]@cell.embeddings : no slot of name "reducedDims" for this object of class "cell_data_set"

Is there anything I am missing here?

Thank you for your help.

zihengxuwu commented 4 years ago

Hi, I was recently informed that they have rewritten the package and some of the objects might have changed. I encourage you to take a look at the construct of the object and can maybe change the objects you input in accordingly. Hope this helps!

akshatkarambe commented 4 years ago

Thank you for getting back at me this quick. Likewise, I changed it to cds_from_seurat@reduce_dim_aux@listData[["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings

reduceDims = reduce_dim_aux

but still not going through and giving me the same error.

I am trying to figure out a way but it would be great if you could check it once and let me know.

Thanks

ondina-draia commented 4 years ago

Reinstall monocle3 by doing this: _remotes::installgithub("cole-trapnell-lab/monocle3", force = TRUE)

Worked for me,correcting the no slot of name "reducedDims" for this object of class "cell_data_set" error

Don't forget to relaunch R and reload monocle3

hmumme commented 4 years ago

@akshatkarambe

Try this instead: cds_from_seurat@int_colData@listData[["reducedDims"]][["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings

I was getting the same error as you but this worked for me.

rwo012 commented 4 years ago

Hi everyone, I've just done the import and pseudotime from seurat v3 to monocle v3 using a seurat integrated object. I used the integrated assay because I wanted monocle to map a trajectory onto the merged samples and onto essentially the same UMAP as the seurat object had. I think if I'd used the RNA assay, monocle wouldn't be able to batch-correct and the samples wouldn't even be in the same clusters. Here's what I did. Please let me know if you think I did something wrong lol! ` seurat.object <- readRDS("Integrated.rds") data <- as(as.matrix(GetAssayData(seurat.object, assay = "integrated", slot = "scale.data")), 'sparseMatrix')

pd <- data.frame(seurat.object@meta.data)

keep only the columns that are relevant

pData <- pd %>% select(orig.ident, nCount_RNA, nFeature_RNA) fData <- data.frame(gene_short_name = row.names(data), row.names = row.names(data))

Construct monocle cds

monocle.object <- new_cell_data_set(expression_data = data, cell_metadata = pData, gene_metadata = fData)

preprocess

monocle.object = preprocess_cds(monocle.object, num_dim = 100, norm_method = "size_only", pseudo_count = 0) monocle.object = reduce_dimension(monocle.object)

map pseudotime

monocle.object = order_cells(monocle.object, reduction_method = "UMAP") monocle.object = learn_graph(monocle.object) plot_cells(monocle.object, color_cells_by = "pseudotime")

`

liuyigh commented 4 years ago

@akshatkarambe

Try this instead: cds_from_seurat@int_colData@listData[["reducedDims"]][["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings

I was getting the same error as you but this worked for me.

I had same problem. No luck with force reinstall as ondina-draia or monocle3 issue #246 suggested.

I tried a revision similar to @akshatkarambe 's:

cds_from_seurat@int_colData@listData$reducedDims@listData[["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings then it worked.

liuyigh commented 4 years ago

Would someone please provide a template on the format of celltype.predictions.July2019.xls? Thanks!

Update: I solved this after reading official doc: https://cole-trapnell-lab.github.io/monocle3/docs/clustering/

My code:

colData(cds_from_seurat)$celltype <- as.character(clusters(cds_from_seurat))
colData(cds_from_seurat)$celltype = dplyr::recode(colData(cds_from_seurat)$celltype,
                                                "1"="HSPC1",
                                                "2"="HSPC2",
                                                "3"="DC",
                                                "4"="Neutrophils",
                                                "5"="Tcell",
                                                "0"="Bcell")
iiiir commented 4 years ago

Final_Seurat_to_Monocle3_2D_and_3D_190719 2.txt Here is a script I wrote for the project I was involved with that concerns converting a Seurat object into a cds, if it provides any directions or guidance to anyone.

Hi, however this step give me error: cds_from_seurat@reducedDims@listData[["UMAP"]] <-seurat@reductions[["umap"]]@cell.embeddings

Error in cds_from_seurat@reducedDims@listData[["UMAP"]] <- seurat@reductions[["umap"]]@cell.embeddings : no slot of name "reducedDims" for this object of class "cell_data_set"

any idea? I also tried reduceDimension function but it is not available for the monocle3 i had -- and monocle 2 has it but give compatibility issue... Thanks,

seigfried commented 4 years ago

@rwo012 I was using Harmony for integrating multiple samples and then i wanted to run Monocle on these integrated samples

epi <- epi %>% RunUMAP(reduction = "harmony", dims = 1:11) %>% FindNeighbors(reduction = "harmony", dims = 1:11) %>% FindClusters(resolution = 0.5) %>% identity()

Here I already have the UMAP i want along with the louvain clusters and I wish to use these with Monocle. I see that I have just one assay "RNA" . How do I use this particular clustering information instead of remaking clusters? The error msg I get is given below:

monocle.object = order_cells(monocle.object, reduction_method = "UMAP") Error: No cell clusters for UMAP calculated. Please run cluster_cells with reduction_method = UMAP and run learn_graph before running order_cells.

rahulnutron commented 4 years ago

I temporarily use this solution for better intercompatibility

library(DropletUtils) write10xCounts(x = Seurat.dataset@assays$RNA@counts, path = 'C:/Users/rahul/plant/outs/filtered_feature_bc_matrix',version = "3")

plant_cds <- load_cellranger_data('C:/Users/rahul/plant/')

chiblyaa commented 3 years ago

Hi all, I see that trying to use batch-corrected/integrated data from SEURAT is a common issue. Has anyone been able to export a "batch-corrected" expression matrix or similar? @Sophia409 @dwucsf what was the resolution?

I stopped trying to use monocle because it's too much of a pain to try and manually recreate a cds with appropriate data, so I'm using dynverse which honestly makes things 300% easier. Still, it needs the batch-corrected data because otherwise the trajectory looks a bit non-sensical.

danrei999 commented 3 years ago

@seigfried Do you have an update on your harmony integrated object using in Monocle3? Any success? Thanks and best, Dan