From 69eb8fa98d5bde337e8d5f045a4eb566c9d3036e Mon Sep 17 00:00:00 2001 From: pcamara Date: Tue, 6 Feb 2024 12:54:54 -0500 Subject: [PATCH] Improved AdjScoreHeatmap --- DESCRIPTION | 1 + NAMESPACE | 1 + R/feature_scores.R | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 468b462..7c39de6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,7 @@ Imports: Matrix, mclust, methods, + pheatmap, RANN, stringr, tidyr diff --git a/NAMESPACE b/NAMESPACE index ebb78c9..f1afdbb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,6 +59,7 @@ import(AdjacencyScore) import(Matrix) import(ggplot2) import(mclust) +import(pheatmap) importFrom(RANN,nn2) importFrom(cluster,silhouette) importFrom(colorspace,rainbow_hcl) diff --git a/R/feature_scores.R b/R/feature_scores.R index cedaafe..4d0a41d 100644 --- a/R/feature_scores.R +++ b/R/feature_scores.R @@ -1,4 +1,5 @@ #' @import AdjacencyScore +#' @import pheatmap #' NULL @@ -9,18 +10,26 @@ NULL #' @param adj_score_output output of any of the AdjScore functions #' - a matrix where each row contains the features in a pair and their #' Adjacency Score and q values +#' @param scaling scaling factor applied in the visualization of q-values. +#' The q-value are transformed according to -log10(scaling + q-value) +#' @param style plotting style for the heatmap, to choose between "heatmap" +#' (default) and "pheatmap" #' #' @export #' -AdjScoreHeatmap <- function(adj_score_output) { +AdjScoreHeatmap <- function(adj_score_output, scaling = 1e-10, style = "heatmap") { heatmap_matrix <- matrix(rep(0,length(unique(adj_score_output$f))*length(unique(adj_score_output$g))), ncol=length(unique(adj_score_output$g))) row.names(heatmap_matrix) <- unique(adj_score_output$f)[order(unique(adj_score_output$f))] colnames(heatmap_matrix) <- unique(adj_score_output$g)[order(unique(adj_score_output$g))] for (i in 1:nrow(adj_score_output)) { - heatmap_matrix[adj_score_output[i,"f"],adj_score_output[i,"g"]] <- log10(adj_score_output[i,"q"]+1e-15) - heatmap_matrix[adj_score_output[i,"g"],adj_score_output[i,"f"]] <- log10(adj_score_output[i,"q"]+1e-15) + heatmap_matrix[adj_score_output[i,"f"],adj_score_output[i,"g"]] <- -log10(adj_score_output[i,"q"]+scaling) + heatmap_matrix[adj_score_output[i,"g"],adj_score_output[i,"f"]] <- -log10(adj_score_output[i,"q"]+scaling) + } + if (style=="heatmap") { + heatmap(heatmap_matrix, margins=c(10,10), symm=T) + } else if (style=="pheatmap") { + pheatmap(heatmap_matrix, main=paste0("-log10(",as.character(scaling)," + q-value)")) } - heatmap(heatmap_matrix, margins=c(10,10), symm=T) }