drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
258 stars 98 forks source link

How to create a Giotto object with a pre-computed dimensionality reduction? #85

Open msto opened 3 years ago

msto commented 3 years ago

Hi,

I'm trying to create a Giotto object with a pre-computed PCA. When I try to pass a list with the PC matrix, i.e. dimension_reduction=list("pca"=as.matrix(PCs)), I receive the following error.

Error in createGiottoObject(raw_exprs = counts(sce), norm_expr = as.matrix(logcounts), : 
  each dimension reduction list must contain all required slots, see details.

Unfortunately, the details of createGiottoObject() do not include any description of the slots required for the dimension reduction list. What is the expected input format for a pre-computed dimensionality reduction?

Thanks,

Matt

msto commented 3 years ago

I found by reading the source code that the following works:

PCA_list <- list(
    'type'="cells",
    'name'="pca",
    'reduction_method'="pca",
    'coordinates'=as.matrix(PCs),
    'misc'=NULL
)

gobj <- createGiottoObject(
    dimension_reduction=list("pca"=PCA_list),
    ...
)

However, plotPCA() no longer works as the eigenvalues aren't included. Could you please document the expected input in the docs for createGiottoObject(), and possibly update plotPCA() so it can accommodate previously computed PCs that aren't generated with Giotto functions?

Thanks!

RubD commented 3 years ago

Hi Matt,

I've updated the code so that it now only uses the eigenvalues to calculate the percentage explained for each PC when it's available in the dimension reduction object. This should fix your problem. I've also expanded the docs for ceateGiottoObject() using your example, but I hope to add some more structured and comprehensive information on our website for all the different slots in the near future. And then I'll just provide a link in the documentation.

The changes have been made to the cless branch. It's the same as the master branch, except that we have stepped away from using our C++ code for the moment.

Thanks for the feedback, Ruben