From d4a6af250d296bcce6ba973777384201e52011cb Mon Sep 17 00:00:00 2001 From: Witold Wolski Date: Tue, 7 May 2024 16:41:01 +0200 Subject: [PATCH] include also statistic column when converting to wide (CONTRASTS) --- R/Contrasts.R | 2 +- R/ContrastsModerated.R | 2 +- R/ContrastsSimpleImpute.R | 2 +- R/ContrastsTable.R | 2 +- R/tidyMS_plotting.R | 89 +++++++++++++++++++-------------------- man/Contrasts.Rd | 2 +- man/ContrastsMissing.Rd | 2 +- man/ContrastsModerated.Rd | 2 +- man/ContrastsTable.Rd | 2 +- 9 files changed, 52 insertions(+), 53 deletions(-) diff --git a/R/Contrasts.R b/R/Contrasts.R index eee6186df..fe36b6cd8 100644 --- a/R/Contrasts.R +++ b/R/Contrasts.R @@ -197,7 +197,7 @@ Contrasts <- R6::R6Class( #' convert to wide format #' @param columns value column default p.value #' @return data.frame - to_wide = function(columns = c("p.value", "FDR")){ + to_wide = function(columns = c("p.value", "FDR", "statistic")){ contrast_minimal <- self$get_contrasts() contrasts_wide <- pivot_model_contrasts_2_Wide(contrast_minimal, subject_Id = self$subject_Id, diff --git a/R/ContrastsModerated.R b/R/ContrastsModerated.R index 36b83a593..164b281fe 100644 --- a/R/ContrastsModerated.R +++ b/R/ContrastsModerated.R @@ -158,7 +158,7 @@ ContrastsModerated <- R6::R6Class( #' convert to wide format #' @param columns value column default moderated.p.value #' @return data.frame - to_wide = function(columns = c("p.value", "FDR")){ + to_wide = function(columns = c("p.value", "FDR", "statistic")){ contrast_minimal <- self$get_contrasts() contrasts_wide <- pivot_model_contrasts_2_Wide(contrast_minimal, subject_Id = self$subject_Id, diff --git a/R/ContrastsSimpleImpute.R b/R/ContrastsSimpleImpute.R index b48f8e664..8040a92c7 100644 --- a/R/ContrastsSimpleImpute.R +++ b/R/ContrastsSimpleImpute.R @@ -153,7 +153,7 @@ ContrastsMissing <- R6::R6Class( #' convert contrast results to wide format #' @param columns value column default p.value #' @return data.frame - to_wide = function(columns = c("p.value", "FDR")){ + to_wide = function(columns = c("p.value", "FDR","statistic")){ contrast_minimal <- self$get_contrasts() contrasts_wide <- pivot_model_contrasts_2_Wide(contrast_minimal, subject_Id = self$subject_Id, diff --git a/R/ContrastsTable.R b/R/ContrastsTable.R index f66088aa0..ea2a830dd 100644 --- a/R/ContrastsTable.R +++ b/R/ContrastsTable.R @@ -91,7 +91,7 @@ ContrastsTable <- R6::R6Class( #' @description convert to wide format #' @param columns value column default beta.based.significance #' @return data.frame - to_wide = function(columns = c("p.value", "FDR")){ + to_wide = function(columns = c("p.value", "FDR","statistic")){ contrast_minimal <- self$get_contrasts() contrasts_wide <- pivot_model_contrasts_2_Wide(contrast_minimal, subject_Id = self$subject_Id, diff --git a/R/tidyMS_plotting.R b/R/tidyMS_plotting.R index 76a1b228f..4348705e8 100644 --- a/R/tidyMS_plotting.R +++ b/R/tidyMS_plotting.R @@ -85,22 +85,22 @@ plot_sample_correlation <- function(pdata, config){ M <- cor(matrix, use = "pairwise.complete.obs") if (nrow(M) > 12) { res <- corrplot::corrplot.mixed(M,upper = "ellipse", - lower = "pie", - diag = "u", - tl.cex = .6, - tl.pos = "lt", - tl.col = "black", - mar = c(2,5,5,2)) + lower = "pie", + diag = "u", + tl.cex = .6, + tl.pos = "lt", + tl.col = "black", + mar = c(2,5,5,2)) } else{ res <- corrplot::corrplot.mixed(M,upper = "ellipse", - lower = "number", - lower.col = "black", - tl.cex = .6, - number.cex = .7, - diag = "u", - tl.pos = "lt", - tl.col = "black", - mar = c(2,5,5,2)) + lower = "number", + lower.col = "black", + tl.cex = .6, + number.cex = .7, + diag = "u", + tl.pos = "lt", + tl.col = "black", + mar = c(2,5,5,2)) } invisible(res) @@ -323,32 +323,31 @@ plot_heatmap <- function(data, if (nrow(resdataf) >= 3) { gg <- stats::hclust( stats::dist( resdataf )) - res <- pheatmap::pheatmap(resdataf[gg$order,], - cluster_rows = FALSE, - scale = "row", - annotation_col = factors, - show_rownames = show_rownames, - border_color = NA, - silent = TRUE, - ... = ...) - - + res <- pheatmap::pheatmap( + resdataf[gg$order,], + cluster_rows = FALSE, + scale = "row", + annotation_col = factors, + show_rownames = show_rownames, + border_color = NA, + silent = TRUE, + ... = ...) } else { - - res <- tryCatch(pheatmap::pheatmap(resdata, - cluster_rows = FALSE, - scale = "row", - annotation_col = factors, - show_rownames = show_rownames, - border_color = NA, - silent = TRUE, - ... = ...), error = .ehandler) - - + res <- tryCatch( + pheatmap::pheatmap( + resdata, + cluster_rows = FALSE, + scale = "row", + annotation_col = factors, + show_rownames = show_rownames, + border_color = NA, + silent = TRUE, + ... = ...), error = .ehandler) } invisible(res) } + #' plot heatmap without any clustering (use to show NA's) #' @param data dataframe #' @param config dataframe configuration @@ -521,7 +520,7 @@ plot_pca <- function(data , config, PC = c(1,2), add_txt = FALSE, plotly = FALSE if (max(PC) > ncol(xx)) { warning("nr of PCs: ", ncol(xx), "\n") return(NULL) - } + } variance_explained <- pca_result$sdev^2 / sum(pca_result$sdev^2) * 100 xx <- inner_join(wide$annotation, xx) @@ -537,15 +536,15 @@ plot_pca <- function(data , config, PC = c(1,2), add_txt = FALSE, plotly = FALSE nudge_x = 0.25, nudge_y = 0.25 ) - PCx <- paste0("PC", PC[1]) - PCy <- paste0("PC", PC[2]) - x <- ggplot(xx, aes(x = !!sym(PCx), y = !!sym(PCy), - color = !!sym(config$table$factor_keys()[1]), - text = !!sym(config$table$sampleName))) + - labs(x = paste0(PCx," (", round(variance_explained[PC[1]]), "% variance)"), - y = paste0(PCy," (", round(variance_explained[PC[2]]), "% variance)")) + - point + - if (add_txt) {text} + PCx <- paste0("PC", PC[1]) + PCy <- paste0("PC", PC[2]) + x <- ggplot(xx, aes(x = !!sym(PCx), y = !!sym(PCy), + color = !!sym(config$table$factor_keys()[1]), + text = !!sym(config$table$sampleName))) + + labs(x = paste0(PCx," (", round(variance_explained[PC[1]]), "% variance)"), + y = paste0(PCy," (", round(variance_explained[PC[2]]), "% variance)")) + + point + + if (add_txt) {text} if (!is.na(sh)) { x <- x + ggplot2::scale_shape_manual(values = seq_along(unique(xx[[sh]]))) } diff --git a/man/Contrasts.Rd b/man/Contrasts.Rd index 50a38bfb5..4b6d30b81 100644 --- a/man/Contrasts.Rd +++ b/man/Contrasts.Rd @@ -231,7 +231,7 @@ creates Contrast_Plotter \subsection{Method \code{to_wide()}}{ convert to wide format \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Contrasts$to_wide(columns = c("p.value", "FDR"))}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{Contrasts$to_wide(columns = c("p.value", "FDR", "statistic"))}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/ContrastsMissing.Rd b/man/ContrastsMissing.Rd index 4016eacc6..772df2024 100644 --- a/man/ContrastsMissing.Rd +++ b/man/ContrastsMissing.Rd @@ -227,7 +227,7 @@ Contrast_Plotter \subsection{Method \code{to_wide()}}{ convert contrast results to wide format \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ContrastsMissing$to_wide(columns = c("p.value", "FDR"))}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ContrastsMissing$to_wide(columns = c("p.value", "FDR", "statistic"))}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/ContrastsModerated.Rd b/man/ContrastsModerated.Rd index b17b7dd19..7e972e180 100644 --- a/man/ContrastsModerated.Rd +++ b/man/ContrastsModerated.Rd @@ -228,7 +228,7 @@ get \code{\link{ContrastsPlotter}} \subsection{Method \code{to_wide()}}{ convert to wide format \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ContrastsModerated$to_wide(columns = c("p.value", "FDR"))}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ContrastsModerated$to_wide(columns = c("p.value", "FDR", "statistic"))}\if{html}{\out{
}} } \subsection{Arguments}{ diff --git a/man/ContrastsTable.Rd b/man/ContrastsTable.Rd index 31ac25d66..09aabf3a3 100644 --- a/man/ContrastsTable.Rd +++ b/man/ContrastsTable.Rd @@ -202,7 +202,7 @@ get \code{\link{ContrastsPlotter}} \subsection{Method \code{to_wide()}}{ convert to wide format \subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ContrastsTable$to_wide(columns = c("p.value", "FDR"))}\if{html}{\out{
}} +\if{html}{\out{
}}\preformatted{ContrastsTable$to_wide(columns = c("p.value", "FDR", "statistic"))}\if{html}{\out{
}} } \subsection{Arguments}{