Skip to content

Commit

Permalink
Improved AdjScoreHeatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
pcamara committed Feb 6, 2024
1 parent 096e7b8 commit 69eb8fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Imports:
Matrix,
mclust,
methods,
pheatmap,
RANN,
stringr,
tidyr
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import(AdjacencyScore)
import(Matrix)
import(ggplot2)
import(mclust)
import(pheatmap)
importFrom(RANN,nn2)
importFrom(cluster,silhouette)
importFrom(colorspace,rainbow_hcl)
Expand Down
17 changes: 13 additions & 4 deletions R/feature_scores.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @import AdjacencyScore
#' @import pheatmap
#'
NULL

Expand All @@ -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)
}


Expand Down

0 comments on commit 69eb8fa

Please sign in to comment.