dynverse / dyno

Inferring, interpreting and visualising trajectories using a streamlined set of packages 🦕
https://dynverse.github.io/dyno
Other
163 stars 32 forks source link

how to import existing umap into dyno #97

Closed wfma closed 3 years ago

wfma commented 3 years ago

Hi there, I want to import the same UMAP embedding from Seurat. Previously I transferred it into Monocle3 using the following line:

cds@int_colData@listData$reducedDims$UMAP <- temp.cds@reductions$umap@cell.embeddings

I tried doing something similar with the dyno obj but I am getting an argument issue.

> model <- model %>% 
+   add_dimred(dyndimred::dimred_mds,
+              dimred = stanford@reductions[["umap"]],
+              expression_source = stanford.dyno$expression)
Error in dimred(expression) : could not find function "dimred"

I was just hoping to have consistent looking UMAPs in my analysis! Please help.

rcannood commented 3 years ago

Hello @wfma!

Could you send me some data so that I can run your code myself?

Do you want to perform this step before or after running trajectory inference?

At the very least, you either can provide a dimred = dyndimred::dimred_mds, expression_source = standford.dyno$expression arguments to let dyno compute a dimred using the probided function. In your example, I think what you want is simply model %>% add_dimred(dimred = stanford@reductions[["umap"]]).

Kind regards, Robrecht

wfma commented 3 years ago

Hi Robrecht, thank you so much for getting back to me! I want to input my UMAP before trajectory inference. I tried exactly what you said and it didnt work.

> model <- model %>% 
+   add_dimred(dimred = stanford@reductions[["umap"]])
Error in get_expression(dataset, expression_source) : 
  No expression found in trajectory, please provide the expression through the expression_source argument. This can be an expression or counts matrix, or a dataset containing the expression.

I also tried to specify the expression source:

> model <- model %>% 
+   add_dimred(dimred = stanford@reductions[["umap"]],
+              expression_source = stanford.dyno$expression)
Error in dimred(expression) : could not find function "dimred"

I am happy to send you the rds and the script I am working on, whats a good email address for you?

Wei

wfma commented 3 years ago

hi there! I am still trying to import the UMAP from seurat, any updates on this front?

Thanks! Wei

mariafiruleva commented 3 years ago

Works for me:

get_data <- function(path, assay_counts='SCT', assay_data='integrated') {
  obj <- get(load(path))
  wrap_data <- wrap_expression(
    counts = t(as.matrix(obj@assays[[assay_counts]]@counts)),
    expression = t(as.matrix(obj@assays[[assay_data]]@data))
  )
  wrap_data <- add_dimred(
    wrap_data,
    dimred = as.matrix(obj@reductions$umap@cell.embeddings)
  )
  wrap_data
}

obj <- get_data('path/to/seurat/RData')
is_wrapper_with_dimred(obj) # returns True
wfma commented 3 years ago

amazing, thanks for getting back! :)

wfma commented 3 years ago

Hi, just an update (sorry for the delay). But I was able to import the seurat UMAP using your code chunk! I made slight modifications, but in case the next person needs it also:

object_counts <- Matrix::t(as(as.matrix(SEURATOBJ@assays$RNA@counts), 'sparseMatrix'))
object_expression <- Matrix::t(as(as.matrix(SEURATOBJ@assays$RNA@data), 'sparseMatrix'))
object_cellinfo <- SEURATOBJ@meta.data[["SingleR.labels"]] #optional, i needed the cell type IDs

dyno_object <- wrap_expression(
  counts = object_counts,
  expression = object_expression)

model <- infer_trajectory(SEURATOBJ, "slingshot")

model <- model %>% 
  add_dimred(dimred = as.matrix(SEURATOBJ@reductions$umap@cell.embeddings),
             expression_source = dyno_object$expression)

plot_dimred(
  model, 
  expression_source = dyno_object$expression, 
  grouping = object_cellinfo 
)