Skip to content

Commit

Permalink
include also statistic column when converting to wide (CONTRASTS)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed May 7, 2024
1 parent 312b0d8 commit d4a6af2
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion R/Contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/ContrastsModerated.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/ContrastsSimpleImpute.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/ContrastsTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
89 changes: 44 additions & 45 deletions R/tidyMS_plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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]])))
}
Expand Down
2 changes: 1 addition & 1 deletion man/Contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ContrastsMissing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ContrastsModerated.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ContrastsTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4a6af2

Please sign in to comment.