/
plotDistMat.R
58 lines (55 loc) · 1.48 KB
/
plotDistMat.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#' @title Plot Similarity Matrix with pheatmap
#'
#' @param dist.list Output of function `getDistMat()`. Required.
#' @param use Default: "coef". No other option currently that can be used.
#' @return A pheatmap showing the similarity matrix
#' @export
#'
#' @import pheatmap
#' @seealso \code{\link{getDistMat}}
plotDistMat <- function(dist.list, use = "coef") {
if (use == "coef") {
dist_coef <- dist.list[[1]]
} else if (use == "p") {
dist_coef <- dist.list[[2]]
}
hm <- list()
for (i in which(vapply(dist_coef, function(x) {
return(!is.null(x))
}))) {
tmp <- dist_coef[[i]] + t(dist_coef[[i]])
diag(tmp) <- 1
hm[i] <- pheatmap::pheatmap(tmp, display_numbers = TRUE)
}
return(hm)
}
#' @title Plot Heatmap for the IDER-based similarity matrix
#'
#' @param seu An Seurat object.
#' @param ider Output of function `getIDEr`.
#' @return A heatmap shows the similarity between shared groups in two batches
#'
#' @seealso \code{\link{getIDEr}}
#' @import pheatmap viridis
#' @export
#' @examples
#' \dontrun{
#' plotHeatmap(seu, ider)
#' }
plotHeatmap <- function(seu, ider) {
idx <- getSharedGroups(seu, ider[[1]])
shared_g <- idx[[1]] # shared groups
if(length(shared_g) == 1){
stop("No shared groups.")
}
idx1 <- idx[[2]] # rownames
idx2 <- idx[[3]] # colnames
pheatmap::pheatmap(
ider[[1]][idx1, idx2],
border_color = "grey20",
color = viridis::inferno(50),
display_numbers = TRUE,
cluster_rows = FALSE,
cluster_cols = FALSE
)
}