markrobinsonuzh/cytofWorkflow

help implementing Phate

Closed this issue · 3 comments

This is more of a help request than an issue with the package.

I have been asked to implement PHATE (https://github.com/KrishnaswamyLab/PHATE) in my workflow but this DR technique isn't included in the Scater package. The package requires a matrix (rows of cells, columns of parameters) as input so I'd like to extract the same values used to produce the UMAP/Clustering but try as hard as I may, I just can't see where those values are in the sce object. Are you able to point me in the right direction?

Dear @83years

Here is a potentially useful example, to both extract the matrix out and put PHATE values back into the object for plotting ..

library(SingleCellExperiment)
library(CATALYST)

# construct SCE
data(PBMC_fs, PBMC_panel, PBMC_md)
sce <- prepData(PBMC_fs, PBMC_panel, PBMC_md)

# run UMAP on <= 200 cells per sample
sce <- runDR(sce, dr = "UMAP", 
             features = type_markers(sce), cells = 200)

x <- t(assay(sce, "exprs")) # matrix: row=cell; column=marker
# some actual PHATE computation on 'x'?
phate <- matrix(rnorm(ncol(sce)*2), nrow = ncol(sce))

reducedDim(sce, "PHATE") <- phate

plotDR(sce, "UMAP")
plotDR(sce, "PHATE")

Hope that helps, Mark

Hi Mark,

That mostly worked.
I've adapted the code to:

phate_in<- t(assay(sce, "exprs")) # matrix: row=cell; column=marker
phate_out<-phate(phate_in)
reducedDim(sce, "PHATE") <- phate_out$embedding
plotDR(sce, "PHATE")

This leaves me with the error:
Error in FUN(X[[i]], ...) : object 'X1' not found

I've seen this error before from trying to run DiffusionMap, but never been able to get to the core of the problem and gave up.

Looking at the sce object there is a PHATE object at the right location with the right values.
sce@int_colData@listData[["reducedDims"]]@listData[["PHATE"]]

Any thoughts on what may be happening?

It seems to not like the column names .. this seems to work for me:

library(SingleCellExperiment)
library(CATALYST)
library(phateR)


# construct SCE
data(PBMC_fs, PBMC_panel, PBMC_md)
sce <- prepData(PBMC_fs, PBMC_panel, PBMC_md)

# run UMAP on <= 200 cells per sample
sce <- runDR(sce, dr = "UMAP", 
             features = type_markers(sce), cells = 200)

x <- t(assay(sce, "exprs")) # matrix: row=cell; column=marker
ph <- phate(x)

reducedDim(sce, "PHATE") <- unname(ph$embedding)

plotDR(sce, "UMAP")
plotDR(sce, "PHATE")