Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zktuong committed Feb 17, 2024
1 parent 0a09f0c commit e755059
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions R/plot_cpdb_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@
#' @include utils.R
#' @export

plot_cpdb_heatmap <- function(
pvals, cell_types = NULL, degs_analysis = FALSE, log1p_transform = FALSE,
show_rownames = TRUE, show_colnames = TRUE, scale = "none", cluster_cols = TRUE,
cluster_rows = TRUE, border_color = "white", fontsize_row = 11, fontsize_col = 11,
family = "Arial", main = "", treeheight_col = 0, treeheight_row = 0, low_col = "dodgerblue4",
mid_col = "peachpuff", high_col = "deeppink4", alpha = 0.05, return_tables = FALSE,
symmetrical = TRUE, ...) {
plot_cpdb_heatmap <- function(pvals, cell_types = NULL, degs_analysis = FALSE, log1p_transform = FALSE,
show_rownames = TRUE, show_colnames = TRUE, scale = "none", cluster_cols = TRUE,
cluster_rows = TRUE, border_color = "white", fontsize_row = 11, fontsize_col = 11,
family = "Arial", main = "", treeheight_col = 0, treeheight_row = 0, low_col = "dodgerblue4",
mid_col = "peachpuff", high_col = "deeppink4", alpha = 0.05, return_tables = FALSE,
symmetrical = TRUE, ...) {
requireNamespace("reshape2")
requireNamespace("grDevices")
all_intr <- pvals
col_start <- ifelse(colnames(all_intr)[DEFAULT_CLASS_COL] == "classification",
DEFAULT_V5_COL_START, DEFAULT_COL_START
)
DEFAULT_V5_COL_START, DEFAULT_COL_START)
intr_pairs <- all_intr$interacting_pair
all_intr <- t(all_intr[, -c(1:col_start - 1)])
colnames(all_intr) <- intr_pairs
if (is.null(cell_types)) {
cell_types <- sort(unique(unlist(strsplit(all_intr.columns[col_start:], DEFAULT_CPDB_SEP))))
cell_types <- sort(unique(unlist(strsplit(colnames(all_intr)[col_start:ncol(all_intr)],
paste0("\\", DEFAULT_CPDB_SEP)))))
}
cell_types_comb <- apply(expand.grid(cell_types, cell_types), 1, function(z) paste(z, collapse = "|"))
cell_types_comb <- apply(expand.grid(cell_types, cell_types), 1, function(z) paste(z,
collapse = "|"))
cell_types_keep <- row.names(all_intr)[row.names(all_intr) %in% cell_types_comb]
empty_celltypes <- setdiff(cell_types_comb, cell_types_keep)
all_intr <- all_intr[row.names(all_intr) %in% cell_types_keep, ]
Expand Down Expand Up @@ -95,20 +95,18 @@ plot_cpdb_heatmap <- function(
count_mat <- log1p(count_mat)
}

p <- pheatmap(count_mat,
show_rownames = show_rownames, show_colnames = show_colnames,
p <- pheatmap(count_mat, show_rownames = show_rownames, show_colnames = show_colnames,
scale = scale, cluster_cols = cluster_cols, border_color = border_color,
cluster_rows = cluster_rows, fontsize_row = fontsize_row, fontsize_col = fontsize_col,
main = main, treeheight_row = treeheight_row, family = family, color = col.heatmap,
treeheight_col = treeheight_col, ...
)
treeheight_col = treeheight_col, ...)
if (return_tables) {
if (symmetrical) {
all_sum <- rowSums(count_mat)
all_sum <- data.frame(all_sum)
return(list(count_network = count_mat, interaction_count = all_sum))
} else {
count_mat <- t(count_mat) # so that the table output is the same layout as the plot
count_mat <- t(count_mat) # so that the table output is the same layout as the plot
row_sum <- rowSums(count_mat)
col_sum <- colSums(count_mat)
all_sum <- data.frame(row_sum, col_sum)
Expand All @@ -120,4 +118,4 @@ plot_cpdb_heatmap <- function(
} else {
stop("There are no significant results using p-value of: ", alpha, call. = FALSE)
}
}
}

0 comments on commit e755059

Please sign in to comment.