getSpatiallyInformedClusters | R Documentation |
Get spatially informed clusters by weighting graph-based clustering with spatial information
getSpatiallyInformedClusters( pcs, W, k, alpha = 1, beta = 1, method = igraph::cluster_louvain, verbose = FALSE, details = FALSE )
pcs |
A matrix of principal components or gene expression to assess transcriptional similarity |
W |
Binary adjacency matrix |
k |
Number of nearest neighbors for clustering |
alpha |
Pseuodocount in edge weight 1/(alpha + as.vector(pweight)) + beta (default: 1) |
beta |
Pseudocount in edge weight 1/(alpha + as.vector(pweight)) + beta (default: 1) |
method |
igraph method for graph-based clustering (default: cluster_louvain) |
verbose |
Verbosity |
details |
Return detailed ouputs |
Factor of cluster annotations
# simulate 3 spatially but 2 transcriptionally distinct groups N <- 300 M <- 30 # Three spatially distinct groups pos1 <- cbind(rnorm(N/3), rnorm(N/3)) pos2 <- cbind(rnorm(N/3, 10), rnorm(N/3)) pos3 <- cbind(rnorm(N/3, 10), rnorm(N/3, 10)) pos <- rbind(rbind(pos1, pos2), pos3) group <- c(rep(1, N/3), rep(2, N/3), rep(3, N/3)) names(group) <- rownames(pos) <- paste0('cell', 1:N) # But two are transcriptionally identical pcs12 <- matrix(rnorm(N*2/3*M), N*2/3, M) pcs3 <- matrix(rnorm(N*1/3*M, 10), N*1/3, M) pcs <- rbind(pcs12, pcs3) pcs <- cbind(pcs, abs(10-pcs)) colnames(pcs) <- paste0('PC:', 1:ncol(pcs)) rownames(pcs) <- rownames(pos) W <- getSpatialNeighbors(pos, filterDist=5) com <- getSpatiallyInformedClusters(pcs, W, k=50, verbose=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.