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
Requested feature: handle inputs from Seurat #262
Comments
hi @TomKellyGenetics - I've been able to extract a monocle3 CDS from a seurat v3 object - would be happy to share the function here or as part of a pull request, I'm not sure which is best. Granted, it's for moving a SCT & harmony-integrated dataset from Seurat to monocle3 so it may not work with all input Seurat objects |
@d93espinoza That would be great. I've managed to extract the relevant fields of a Seurat object but haven't made it into a function (thinking about the best way to do this). If you've already done it, that would be great, I hope to see it as a PR. |
@d93espinoza Hello! I am hoping to perform pseudotime analysis on an integrated Seurat (v3) object in Monocle. It sounds like you have performed similar analyses - I would greatly appreciate your help and any code you may be willing to share. Thank you so much! |
@summerrfair Based on the documentation here, this is a working example on a Suerat object. Note that monocle takes the raw counts (merged or integrated objects are okay) and requires the gene names and barcodes to match the metadata.
You can also ensure that the clusters and dimension reductions match those computed in Suerat like this:
It wouldn't be too difficult to wrap either of these into a function but not sure on the best way to do this. |
Many thanks for sharing this. Very helpful! I will try to implement and will let you know how it goes. |
Here's my try (so far) at the function, sorry for the delay and thanks @TomKellyGenetics for sharing your code! ToMonocle3 <- function(seurat_object,
scale_all = FALSE,
assay = "SCT",
reduction_for_projection = "PCA",
UMAP_cluster_slot = NULL){
if(scale_all){
message("Getting residuals for all Seurat genes in chosen assay slot and placing in scale.data")
seurat_genes <- rownames(seurat_object[[assay]])
remaining_genes <- setdiff(seurat_genes, rownames(seurat_object[[assay]]@scale.data))
if(assay == "SCT"){
seurat_object <- Seurat::GetResidual(seurat_object, features = remaining_genes, assay = assay, umi.assay = "RNA")
} else {
seurat_object <- Seurat::ScaleData(seurat_object, features = rownames(seurat_object[[assay]]))
}
}
#We prep the seurat object by creating gene loadings for ALL genes in the Seurat scale.data slot. This is done to allow downstream monocle3 functions on gene_modules to work appropriately.
message("Projecting gene loadings for all Seurat genes in scale.data slot")
seurat_object <- Seurat::ProjectDim(seurat_object, reduction = reduction_for_projection, assay = assay)
##################
message("Initializing CDS object")
#Extract Seurat's log-transformed values
expression_matrix <- Seurat::GetAssayData(seurat_object, assay = assay, slot = "counts")
#Extract Seurat meta_data
meta_data <- seurat_object@meta.data
#Extract gene names from Seurat object SCT slot to make CDS
seurat_genes <- data.frame(gene_short_name = rownames(seurat_object[[assay]]),
row.names = rownames(seurat_object[[assay]]))
new_cds <- monocle3::new_cell_data_set(expression_data = expression_matrix, cell_metadata = meta_data, gene_metadata = seurat_genes)
##################
message("Making an SCE object from the Seurat object to facilitate transfer of information from SCE to CDS")
sce <- as.SingleCellExperiment(seurat_object, assay = assay)
message("Loading in all Seurat reductions (PCA, HARMONY, UMAP, etc.) into CDS")
SingleCellExperiment::reducedDims(new_cds) <- SingleCellExperiment::reducedDims(sce)
message("Loading in specified Seurat assay into CDS")
SummarizedExperiment::assays(new_cds) <- SummarizedExperiment::assays(sce)
message("Loading in Seurat gene names into CDS")
SummarizedExperiment::rowData(new_cds) <- SummarizedExperiment::rowData(sce)
SummarizedExperiment::rowData(new_cds)$gene_short_name <- row.names(new_cds)
message("Loading in Seurat gene loadings into CDS")
new_cds@preprocess_aux$gene_loadings <- seurat_object@reductions[[reduction_for_projection]]@feature.loadings.projected
##################
message("Get user specified selected clusters (or active idents) from Seurat and load into CDS")
if(is.null(UMAP_cluster_slot)){
list_cluster <- Idents(seurat_object)
} else {
Idents(seurat_object) <- UMAP_cluster_slot
list_cluster <- Idents(seurat_object)
}
new_cds@clusters[["UMAP"]]$clusters <- list_cluster
#The next two commands are run in order to allow "order_cells" to be run in monocle3
rownames(new_cds@principal_graph_aux[['UMAP']]$dp_mst) <- NULL
colnames(SingleCellExperiment::reducedDims(new_cds)[["UMAP"]]) <- NULL
##################
message("Setting all cells as belonging to one partition (multiple partitions not supported yet)")
recreate_partition <- c(rep(1, length(new_cds@colData@rownames)))
names(recreate_partition) <- new_cds@colData@rownames
recreate_partition <- as.factor(recreate_partition)
new_cds@clusters[["UMAP"]]$partitions <- recreate_partition
##################
message("Done")
new_cds
} |
@TomKellyGenetics |
@Vidya-Acadgild Have you run |
@TomKellyGenetics |
@Vidya-Acadgild Sorry it's unclear what issue you are having here. I suggest that you follow the steps in the vignette in order. Please note that this code is not supported by Seurat or monocle3 developers and is a workaround. If you are still having trouble, I suggest you open a new issue on more details on what you've tried already and give a minimal reproducible example. You can do this in R with |
@TomKellyGenetics |
@TomKellyGenetics |
@TomKellyGenetics Hi, Tom, thank you for your codes, it is helpful. They didn't work. It's really puzzled me. Thanks. |
Yes you can do that as follows.
Note: you need to have run umap with monocle3 |
Thank you for your help. Is it because the version of SingleCellExperiment? Mine is 1.8.0 God help me== |
Here's a minimal reproducible example.
R version 3.6.2, Seurat_3.0.0, monocle3_0.2.0 |
I can confirm what @Wincky111 is seeing, there's no "reducedDims" slot in the cds object after preprocessing / reducing dimensions / and clustering. This is what I see: |
@rohanshad @Wincky111 You need to run
This example works with |
Happened to meet the same error: "no slot of name "reducedDims"" It works for me! |
Yep, above answer works! |
Hi, Paul Hoffman at the Satija Lab is working on tools for inter-converting Seurat and Monocle3 objects. This is a work-in-progress so it may not be feature-complete or stable but Paul encourages people to test it. The URL is https://github.com/satijalab/seurat-wrappers/tree/feat/monocle3. |
@williamhsy @TomKellyGenetics any luck getting the learn_graph command to work on new embeddings processed this way? use_partition = TRUE / FALSE doesn't help and 'order_cells' errors out. Hmmm... Edit: |
As announced by Rahul Satija this is now supported by SeuratWrappers. See here for details on the code and usage.
Apply it to a Seurat objects as follows:
|
Hello! I have followed the SeuratWrappers tutorial for converting an integrated seurat v3 object to monocle3. However, when I try to plot single gene expression in pseudotime using plot_genes_in_pseudotime(), I get the error "Error: When label_by_short_name = TRUE, rowData must have a column of gene names called gene_short_name."
I wonder whether the as.cell_data_set() function to convert my integrated seurat object into a cds does not carry over gene names as a column. Edit: I was able to get around this by adding the gene_short_name column to my rowData(cds) from a previous monocle dataframe I already had. |
…_data_set" See issue in cole-trapnell-lab/monocle3#262.
Hi, I have the same problem! can you specify how you did this? thanks a lot! |
@laijen000 "Error: When label_by_short_name = TRUE, rowData must have a column of gene names called gene_short_name." or can someone else provide an example to set up the gene_short_name column after converting from a Seurat object? |
This worked for me previously! library(monocle3) |
Proposal to implement to extract a cell_data_set from a Seurat object. Can submit a PR if needed.
The text was updated successfully, but these errors were encountered: