Skip to content

Commit

Permalink
ettore, enrichment heatmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
emosca-cnr committed Dec 13, 2023
1 parent b12d58f commit e92989a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion R/plot_gsea_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @importFrom pals brewer.purples
#' @importFrom grid gpar grid.text

plot_gsea_heatmap <- function(gsea_res=NULL, nes_sign=TRUE, a=0.25, p.stat="FDRq", na_col="khaki", max_gs=50, min.p=0.0001, ...){
plot_gsea_heatmap <- function(gsea_res=NULL, nes_sign=TRUE, a=0.25, p.stat="FDRq", na_col="khaki", max_gs=50, min.p=NA, ...){

if(length(gsea_res)<2){
stop("This function requires at least two GSEAs.\n")
Expand Down Expand Up @@ -76,6 +76,12 @@ plot_gsea_heatmap <- function(gsea_res=NULL, nes_sign=TRUE, a=0.25, p.stat="FDRq
nes_sign <- nes_sign[match(rownames(X_matrix), rownames(nes_sign)), ]
nes_sign[is.na(X_matrix)] <- ""

if(is.na(min.p)){
min.p <- min(10^-(X_matrix), na.rm = T)
}else{
X_matrix[X_matrix > -log10(min.p)] <- -log10(min.p)
}

col_fun <- colorRamp2(seq(min(X_matrix, na.rm = T), min(max(X_matrix, na.rm=T), -log10(min.p)), length.out=5), brewer.purples(5))

plot(Heatmap(X_matrix, col=col_fun, na_col = na_col, name=paste0("-log10(", p.stat, ")"), rect_gp = gpar(col = "black", lwd = 1), cell_fun = function(j, i, x, y, width, height, fill) { grid.text(nes_sign[i, j], x, y, gp = gpar(fontsize = 10, fontface = "bold", col=ifelse(nes_sign[i, j]=="+", "limegreen", "firebrick")))}, ...))
Expand Down
10 changes: 8 additions & 2 deletions R/plot_ora_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @importFrom grid gpar grid.text
#' @importFrom circlize colorRamp2

plot_ora_heatmap <- function(ora_res=NULL, p.stat="p_adj", a=0.25, na_col="khaki", min.p=0.0001, max_gs=50, ...){
plot_ora_heatmap <- function(ora_res=NULL, p.stat="p_adj", a=0.25, na_col="khaki", min.p=NA, max_gs=50, ...){

if(length(ora_res)<2){
stop("This function requires at least two ORAs.\n")
Expand Down Expand Up @@ -51,7 +51,13 @@ plot_ora_heatmap <- function(ora_res=NULL, p.stat="p_adj", a=0.25, na_col="khaki
if(any(is.na(X_matrix))){
cat("The presence of many NA values may cause errors in hclust(). To avoid this error, (i) increase 'a' or (ii) set cluster_columns = F and/or cluster_rows = F.\n")
}
#col_fun <- colorRamp2(seq(0, -log10(min.p), length.out=5), brewer.purples(5))

if(is.na(min.p)){
min.p <- min(10^-(X_matrix), na.rm = T)
}else{
X_matrix[X_matrix > -log10(min.p)] <- -log10(min.p)
}

col_fun <- colorRamp2(seq(min(X_matrix, na.rm = T), min(max(X_matrix, na.rm=T), -log10(min.p)), length.out=5), brewer.purples(5))

plot(Heatmap(X_matrix, col=col_fun, na_col = na_col, name=paste0("-log10(", p.stat, ")"), rect_gp = gpar(col = "black", lwd = 1), ...))
Expand Down

0 comments on commit e92989a

Please sign in to comment.