#' guided_MST
#'
#' Minimum spanning tree to guide pseudotime construction
#'
#' This function should be used when users have already performed PCA or other dimension reductions, and cell clustering. This function will plot a minimum-spanning-tree that helps users to determine which cell clusters should be linked in what order. The result can be fed into guided_tscan function to get the actual pseudotime.
#'
#' @param dr A numeric matrix of reduced dimensions. Can be from PCA, t-sne, UMAP, diffusion map, and many others. Each row is a cell and each column is a reduced dimension. Row names should be the cell names.
#' @param clu A named vector of cell clustering. Names are the cell names. Need to correspond to dr.
#' @return A minimum-spanning-tree plot generated by igraph package
#' @import igraph
#' @export
#' @author Zhicheng Ji <zhicheng.ji@@duke.edu>
#' @examples
#' # see vignette
guided_MST <- function(dr,clu) {
n <- names(clu)
clu <- as.character(clu)
names(clu) <- n
cm <- sapply(unique(clu),function(i) colMeans(dr[clu==i,]))
dp <- as.matrix(dist(t(cm)))
gp <- graph.adjacency(dp, mode = "undirected", weighted = TRUE)
dp_mst <- minimum.spanning.tree(gp)
plot(dp_mst)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.