harmony icon indicating copy to clipboard operation
harmony copied to clipboard

> Dear @yuGithuuub,

Open Emma-China opened this issue 5 years ago • 1 comments

Dear @yuGithuuub,

I currently do not have plans to integrate Harmony into the full Monocle framework. In my own analyses, I found that the trajectory inference algorithm used by Monocle, DDRTree, works just as well on a cell-by-gene matrix as a cell-by-PCs matrix. So I use DDRTree directly on my Harmonized PCA matrix to return the trajectory embedding.

library(DDRTree)
get_ddr <- function(harmony_Z, ndim=2) {
    ncells <- nrow(harmony_Z)
    ncenter <- round(2 * 100 * log(ncells) / (log(ncells) + log(100)))
    ddr_args <- c(list(
        X = harmony_Z, 
        dimensions = ndim, ## LOW DIMENSIONALITY
        ncenter = ncenter, 
        verbose = FALSE))
    ddrtree_res <- do.call(DDRTree, ddr_args)
    ddrtree_res$Z <- t(ddrtree_res$Z)
    row.names(ddrtree_res$Z) <- row.names(harmony_Z)
    colnames(ddrtree_res$Z) <- colnames(harmony_Z)
    return(ddrtree_res$Z)
}

In the code above, harmony_Z is a cell-by-PC matrix of Harmonized cell embeddings and ndim is the number of dimensions you want to get from the DDRTree inference. This is not a full trajectory analysis but it can help you to visualize your cells in a "trajectory space."

Best, Ilya

Hello,I have encountered a problem when i run the function of get_ddr,and would like to ask. Here are my code and error:

harmony_embedding <- Seurat::Embeddings(seuratObject, 'harmony') harmony_embedding[seq_len(5), seq_len(5)] harmony_1 harmony_2 harmony_3 harmony_4 harmony_5 Q9D5_AAACCCAAGCACTAAA-1 1.819167 -7.420685 -6.262630 0.3244117 0.9872209 Q9D5_AAACCCAAGCGATCGA-1 -9.997331 13.725940 4.829441 -13.7063330 3.9843493 Q9D5_AAACCCACAGTAACAA-1 -4.230632 -9.308852 -3.642947 0.1326170 -1.7054477 Q9D5_AAACGAAAGGATTCAA-1 -8.199931 -10.121518 -3.336982 1.8577525 -1.6456189 Q9D5_AAACGAAAGTCATAGA-1 -5.126308 -10.118114 -4.421629 0.4208384 -1.4270345 get_ddr <- function(harmony_Z, ndim=2) { ncells <- nrow(harmony_Z) ncenter <- round(2 * 100 * log(ncells) / (log(ncells) + log(100))) ddr_args <- c(list( X = harmony_Z, dimensions = ndim, ## LOW DIMENSIONALITY ncenter = ncenter, verbose = FALSE)) ddrtree_res <- do.call(DDRTree, ddr_args) ddrtree_res$Z <- t(ddrtree_res$Z) row.names(ddrtree_res$Z) <- row.names(harmony_Z) colnames(ddrtree_res$Z) <- colnames(harmony_Z) return(ddrtree_res$Z) } get_ddr(harmony_embedding) Error in (function (X, dimensions = 2, initial_method = NULL, maxIter = 20, : Error: ncenters must be greater than or equal to ncol(X)

How can I solve such a problem? Thanks for your answer !

Originally posted by @Emma-1991 in https://github.com/immunogenomics/harmony/issues/74#issuecomment-725076069

Emma-China avatar Nov 11 '20 01:11 Emma-China

Dear @Emma-1991,

From the error message, it sounds like there may be an issue with the dimension of the matrix passed to DDRTree. Have you tried to transpose it first?

Best, Ilya

ilyakorsunsky avatar Jun 17 '21 17:06 ilyakorsunsky