From ed2d631c649543b11e0fe6fe42a28c924b46b29f Mon Sep 17 00:00:00 2001 From: DanielGarbozo Date: Mon, 4 Aug 2025 10:17:44 -0400 Subject: [PATCH 1/3] feat: add plot_GSEA.R and remove old barplot_GSEA.R --- R/barplot_GSEA.R | 57 ------------------------------------------------ 1 file changed, 57 deletions(-) delete mode 100644 R/barplot_GSEA.R diff --git a/R/barplot_GSEA.R b/R/barplot_GSEA.R deleted file mode 100644 index 8339beb..0000000 --- a/R/barplot_GSEA.R +++ /dev/null @@ -1,57 +0,0 @@ -######################### -# Function barplot_GSEA # -######################### - -#' Create and save a customized barplot for GSEA results -#' -#' This function generates a customized barplot with: -#' * Grouped bars. -#' * Adjusted aesthetics. -#' * Personalized axis labels. -#' * Optionally save the result in SVG format. -#' -#' @param data A data frame containing GSEA results with columns such as `datatype`, `NES`, `-Log10FDR`, and `New_name`. -#' @param output_path The file path where the barplot will be saved (SVG format). -#' @param custom_labels A named vector of custom expressions for x-axis labels. -#' @param axis_y Name of the column to use for the y-axis aesthetic, as a string. Default: "NES". -#' @import ggplot2 -#' @importFrom rlang .data -#' @export - -barplot_GSEA <- function(data, output_path, custom_labels, axis_y = "NES") - -{ - # Generate the barplot - barplot <- ggplot(data, aes(x = .data$datatype, y = .data[[axis_y]], fill = .data[["-Log10FDR"]])) + - geom_bar(stat = "identity", color = "black", size = 0.5, width = 0.6) + - scale_fill_gradient( - low = "white", high = "red", na.value = "white", - limits = c(0, 5.5), # Fixed legend limits - oob = scales::squish, # Squish out-of-bounds values - guide = guide_colorbar(barwidth = 3, barheight = 18) - ) + - labs(x = "Comparisons", y = axis_y) + - theme_bw() + - theme( - axis.line.x = element_blank(), - axis.line = element_line(color = "black", size = 0.5), - axis.title.x = element_text(size = 45, face = "bold", margin = margin(t = 25)), - axis.title.y = element_text(size = 45, face = "bold"), - axis.text.x = element_text(angle = 0, hjust = 0.5, vjust = 0.5, size = 30), - axis.text.y.left = element_text(size = 50), - legend.title = element_text(size = 50), - legend.text = element_text(size = 50), - panel.spacing = grid::unit(0.6, "lines"), - panel.border = element_blank(), - strip.background = element_rect(fill = "white", color = "white"), - strip.text.y.left = element_text(size = 50, angle = 0, hjust = 0.5), - strip.placement = "outside" - ) + - geom_hline(yintercept = 0, color = "black", size = 2) + - expand_limits(y = 0) + - ylim(-3.4, 3.2) + - facet_wrap(~ .data$New_name, ncol = 2, strip.position = "left", scales = "free_y") + - scale_x_discrete(labels = custom_labels) - - return(barplot) -} From a174cb992e3188d02b9bb185ea63f170f19bfd70 Mon Sep 17 00:00:00 2001 From: DanielGarbozo Date: Mon, 4 Aug 2025 12:07:31 -0400 Subject: [PATCH 2/3] chore: fix globalVariables and Roxygen block for GSEA functions --- DESCRIPTION | 4 +- NAMESPACE | 3 +- R/heatmap_GSEA.R | 5 + R/merge_GSEA.R | 11 +- R/plot_GSEA.R | 272 ++++++++++++++++++++++++++------------------ man/barplot_GSEA.Rd | 26 ----- man/plot_GSEA.Rd | 76 ++++++++++--- 7 files changed, 243 insertions(+), 154 deletions(-) delete mode 100644 man/barplot_GSEA.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 1dfc1a5..7c18bce 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,10 +29,10 @@ Imports: scales, grid, utils, - patchwork + patchwork, + cowplot Suggests: biomaRt, - cowplot, dbscan, ggnewscale, ggrepel, diff --git a/NAMESPACE b/NAMESPACE index c7c52e6..d7c9dc4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand export(add_annotations) -export(barplot_GSEA) export(detect_filter) export(get_annotations) export(get_stars) @@ -19,6 +18,8 @@ export(save_results) export(split_cases) export(tpm) import(ggplot2) +importFrom(cowplot,get_legend) importFrom(magrittr,"%>%") importFrom(patchwork,plot_layout) importFrom(rlang,.data) +importFrom(utils,modifyList) diff --git a/R/heatmap_GSEA.R b/R/heatmap_GSEA.R index 40ca338..ff39ff6 100644 --- a/R/heatmap_GSEA.R +++ b/R/heatmap_GSEA.R @@ -23,6 +23,11 @@ heatmap_GSEA <- function(main_dir = NULL, expression_file, metadata_file, gmt_fi ranked_genes_file, gsea_file, output_dir = "leading_edge_heatmaps", sample_col = "Sample", group_col = "group", save_dataframe = FALSE) { + # Avoid check NOTES for global variables across multiple functions + utils::globalVariables(c( + "NAME", "GENES", "SIZE", "tags", "L.EDGE_size" + )) + # Ensure required packages are installed if (!requireNamespace("readr", quietly = TRUE)) stop("Package \"readr\" must be installed to use this function.", call. = FALSE) if (!requireNamespace("grDevices", quietly = TRUE)) stop("Package \"grDevices\" must be installed to use this function.", call. = FALSE) diff --git a/R/merge_GSEA.R b/R/merge_GSEA.R index 990d6b7..64e10fb 100644 --- a/R/merge_GSEA.R +++ b/R/merge_GSEA.R @@ -10,10 +10,15 @@ #' @param output_file The output file to save the merged data. If not provided, the file will be saved in the input directory. #' @importFrom magrittr %>% #' @export - - merge_GSEA <- function(input_directory, output_file = "collections_merged_gsea_data.tsv") { - + + # Avoid check NOTES for global variables across multiple functions + utils::globalVariables(c( + "...12", "numeric_cols", "LEADING EDGE", "tags", "signal", + "FDR q-val", "Log10FDR", "FWER p-val", "Comparison" + )) + + # Ensure required packages are installed if (!requireNamespace("dplyr", quietly = TRUE)) stop("Package \"dplyr\" must be installed to use this function.", call. = FALSE) if (!requireNamespace("readr", quietly = TRUE)) stop("Package \"readr\" must be installed to use this function.", call. = FALSE) if (!requireNamespace("tidyr", quietly = TRUE)) stop("Package \"tidyr\" must be installed to use this function.", call. = FALSE) diff --git a/R/plot_GSEA.R b/R/plot_GSEA.R index 3be4b21..cf31eae 100644 --- a/R/plot_GSEA.R +++ b/R/plot_GSEA.R @@ -1,117 +1,171 @@ -###################### -# Function plot_GSEA # -###################### +utils::globalVariables(c( + "NAME","GENES","SIZE","tags","L.EDGE_size", + "...12","numeric_cols","LEADING EDGE","signal", + "FDR q-val","Log10FDR","FWER p-val","Comparison" +)) -#' Plot global GSEA results +#' Unified GSEA plotting function with theme configuration #' -#' Generates a composite plot displaying NES values, pathway labels, -#' and a \emph{logFDR} legend, organized by MSigDB collections. +#' Creates either a global GSEA plot or a faceted barplot depending on the number of unique +#' comparisons in the `Comparison` column. Allows customizing all previously hard-coded theme +#' parameters via a single `theme_params` list. #' -#' @param data Data frame containing the GSEA results. -#' @param geneset_col Name of the column containing the genesets. -#' @param collection_col Name of the column containing the collections. -#' @param nes_col Name of the column containing the NES values. -#' @param logfdr_col Name of the column containing \eqn{-\log_{10}(FDR)} values. -#' @param text_size_genesets Text size for the geneset labels. -#' @param text_size_collection Text size for the collection labels. +#' @param data A data frame containing GSEA results. +#' @param Comparison Name of the column defining different comparisons. Default: "Comparison". +#' @param custom_labels Named vector of labels for the x-axis discrete scale (barplot mode only). Default: NULL. +#' @param axis_y Name of the column to use for the y-axis aesthetic. Default: "NES". +#' @param fdr_col Name of the column containing FDR values. Default: "FDR". +#' @param logFDR Logical; if TRUE, compute -log10(FDR) from `fdr_col`, otherwise use `fdr_col` directly. Default: TRUE. +#' @param geneset_col Name of the column containing the geneset labels (single comparison mode). +#' @param collection_col Name of the column containing the MSigDB collections (single comparison mode). +#' @param nes_col Name of the column containing NES values (single comparison mode). +#' @param logfdr_col Name of the column containing -log10(FDR) or similar (single comparison mode). +#' @param order One of "desc" or "asc"; order of `axis_y` values. Default: c("desc","asc"). +#' @param ncol_wrap Number of columns for `facet_wrap` in barplot mode. Default: 2. +#' @param free_y Logical; if TRUE, allow free y scales in facets. Default: TRUE. +#' @param fill_limits Numeric vector of length 2 to set fill gradient limits (barplot mode). Default: NULL. +#' @param fill_palette Character vector of two colors for fill gradient. Default: c("white","red"). +#' @param theme_params Named list to override default theme parameters (see details). +#' @details theme_params may include: +#' \describe{ +#' \item{side_label_size}{Size for side panel labels (default 35)} +#' \item{geneset_text_size}{Text size for geneset labels (default 5)} +#' \item{collection_text_size}{Text size for collection labels (default 5)} +#' \item{panel_widths}{Patchwork widths vector (default c(4,25,15,3,10,3))} +#' \item{bar_col}{Bar/col border color (default "black")} +#' \item{bar_size}{Border size for bars (default 0.5)} +#' \item{bar_width}{Width for bars (default 0.6)} +#' \item{col_size}{Border size for geom_col (default 1)} +#' \item{hline_size}{Size for horizontal line at y=0 (default 2)} +#' \item{axis_title_size}{Font size for axis titles (default 45)} +#' \item{axis_text_size_x}{Font size for x-axis text (default 30)} +#' \item{axis_text_size_y}{Font size for y-axis text (default 50)} +#' \item{tick_size}{Size for axis ticks (default 1.5)} +#' \item{tick_length}{Length for axis ticks in cm (default 0.3)} +#' \item{strip_text_size}{Font size for strip text (default 50)} +#' \item{panel_spacing_single}{Facet spacing single mode (default 4)} +#' \item{panel_spacing_multi}{Facet spacing multi mode (default 0.6)} +#' } +#' @return A ggplot or patchwork object for the GSEA plot. #' @import ggplot2 +#' @importFrom rlang .data #' @importFrom patchwork plot_layout -#' @return GSEA barplots arranged in a grid. +#' @importFrom cowplot get_legend +#' @importFrom utils modifyList #' @export - -plot_GSEA <- function(data, geneset_col, collection_col, nes_col, logfdr_col, - text_size_genesets = 5, text_size_collection = 5) -{ - - if (!requireNamespace("patchwork", quietly = TRUE)) stop("Package \"patchwork\" must be installed to use this function.", call. = FALSE) - if (!requireNamespace("cowplot", quietly = TRUE)) stop("Package \"cowplot\" must be installed to use this function.", call. = FALSE) - - # Rename columns dynamically - data <- data[, c(geneset_col, collection_col, nes_col, logfdr_col)] - colnames(data) <- c("Geneset", "Collection", "NES", "logFDR") - - # Order data by NES value (descending) - data <- data[order(data$NES, decreasing = TRUE), ] - - # Ensure Geneset and Collection are factors with ordered levels - data$Geneset <- factor(data$Geneset, levels = rev(unique(data$Geneset))) - data$Collection <- factor(data$Collection, levels = unique(data$Collection)) - - # Right-side label: "MSigDB" vertically centered, in bold and italic - plot_text_msigdb <- ggplot() + - annotate("text", label = "MSigDB", fontface = "bold.italic", angle = 90, size = 35, x = 0, y = 0.5)+ - theme_void() - - # Lef-side label: "Pathways" vertically centered, in bold and italic - plot_text_pathways <- ggplot() + - annotate("text", label = "Pathways", fontface = "bold.italic", angle = 90, size = 35, x = 0, y = 0.5)+ - theme_void() - - # Right panel: Collection labels (without repetition) - plot_right <- ggplot(data, aes(y = Geneset, x = 1.5, label = Collection)) + - geom_text(aes(label = ifelse(duplicated(Collection), "", Collection)), - hjust = 0.5, size = 0, fontface = "bold") + - facet_grid(Collection ~ ., scales = "free_y", space = "free", switch = "y") + - theme_void() + - theme(strip.text.y = element_text(angle = 0, hjust = 1, size = text_size_collection), - panel.spacing = grid::unit(1, "lines")) - - # Center panel: NES bar plot - plot_center <- ggplot(data, aes(x = NES, y = Geneset, fill = logFDR)) + - geom_col(color = "black", size = 1) + - scale_fill_gradient(low = "white", high = "red", - limits = c(0,3), breaks = seq(0,3,1)) + - scale_y_discrete(position = "right") + - facet_grid(Collection ~ ., scales = "free_y", space = "free_y") + - theme_bw() + - labs(x = "NES", y = "") + - theme(axis.text.y = element_blank(), - strip.background = element_rect(fill = "white", color = "black",linewidth = 1 ), - axis.ticks.y = element_line(color = "black", size = 1.5), - axis.ticks.length = grid::unit(0.3, "cm"), - strip.text.y = element_text(size = 1, margin = margin(0, 0, 0, 0)),# element_blank(), - legend.position = "none", - axis.title.x = element_text(size = 49), - axis.text.x = element_text(size = 45), - panel.spacing = grid::unit(4, "lines") - ) - - # Left panel: Pathays labels - plot_left <- ggplot(data, aes(y = Geneset, x = 0, label = Geneset)) + - geom_text(hjust = 1, size = text_size_genesets) + - theme_void() + - theme(axis.text.y = element_blank(), - plot.margin = margin(0, 0, 0, -50)) - - # Legend panel - plot_legend <- ggplot(data, aes(x = NES, y = Geneset, fill = logFDR)) + - geom_tile() + - scale_fill_gradient(low = "white", high = "red", - name = expression(-log[10] ~ FDR), # log10FDR with subscrip, - limits = c(0,3), breaks = seq(0,3,1), - guide = guide_colorbar(ticks.colour = "black", # Make ticks black - ticks.linewidth = 1.5, # Make ticks thicker - draw.ulim = TRUE, # Draw upper limit tick - draw.llim = TRUE)) + # Draw lower limit tick - theme_bw() + - theme(legend.position = "right", - legend.box = "vertical", - legend.title = element_text(size = 44, hjust = 0.5, face = "bold"), # Bigger title - legend.text = element_text(size = 30), # Bigger legend text - legend.key.size = grid::unit(1.5, "cm"), # Bigger color key size - legend.key.height = grid::unit(2, "cm"), # Increase the height of the legend box - legend.spacing = grid::unit(3.5, "cm"), # More space between title and legend - legend.box.margin = margin(10, 20, 10, 10)) # 5, 5, 10, 5)) # Adjust internal spacing - - plot_legend <- plot_legend + theme(legend.box = "vertical") - plot_right_legend <- cowplot::get_legend(plot_legend) - - # Extract legend - #plot_right_legend <- get_legend(plot_legend) - - # Combine all plots - final_plot <- plot_text_pathways + plot_left + plot_center + plot_right + plot_text_msigdb + plot_right_legend + - patchwork::plot_layout(ncol = 6, widths = c(4, 25, 15, 3, 10, 3)) - +plot_GSEA <- function( + data, + Comparison = "Comparison", + custom_labels = NULL, + axis_y = "NES", + fdr_col = "FDR", + logFDR = TRUE, + geneset_col, + collection_col, + nes_col, + logfdr_col, + order = c("desc", "asc"), + ncol_wrap = 2, + free_y = TRUE, + fill_limits = NULL, + fill_palette = c("white", "red"), + theme_params = list() +) { + defaults <- list( + side_label_size = 35, + geneset_text_size = 5, + collection_text_size = 5, + panel_widths = c(4,25,15,3,10,3), + bar_col = "black", + bar_size = 0.5, + bar_width = 0.6, + col_size = 1, + hline_size = 2, + axis_title_size = 45, + axis_text_size_x = 30, + axis_text_size_y = 50, + tick_size = 1.5, + tick_length = 0.3, + strip_text_size = 50, + panel_spacing_single = 4, + panel_spacing_multi = 0.6 + ) + params <- utils::modifyList(defaults, theme_params) + if (logFDR) data$logFDR <- -log10(data[[fdr_col]]) else data$logFDR <- data[[fdr_col]] + order <- match.arg(order) + data <- data[order(data[[axis_y]], decreasing = (order == "desc")), ] + if (length(unique(data[[Comparison]])) == 1) { + if (!requireNamespace("patchwork", quietly = TRUE)) stop("patchwork required", call. = FALSE) + if (!requireNamespace("cowplot", quietly = TRUE)) stop("cowplot required", call. = FALSE) + df <- data[, c(geneset_col, collection_col, nes_col, logfdr_col)] + colnames(df) <- c("Geneset", "Collection", "NES", "logFDR") + df$Geneset <- factor(df$Geneset, levels = rev(unique(df$Geneset))) + df$Collection <- factor(df$Collection, levels = unique(df$Collection)) + plot_text_pathways <- ggplot() + + annotate("text", label = "Pathways", fontface = "bold.italic", angle = 90, + size = params$side_label_size, x = 0, y = 0.5) + theme_void() + plot_left <- ggplot(df, aes(y = .data$Geneset, x = 0, label = .data$Geneset)) + + geom_text(hjust = 1, size = params$geneset_text_size) + theme_void() + + theme(axis.text.y = element_blank(), plot.margin = margin(0, 0, 0, -50)) + plot_center <- ggplot(df, aes(x = .data$NES, y = .data$Geneset, fill = .data$logFDR)) + + geom_col(color = params$bar_col, size = params$col_size) + + scale_fill_gradient(low = fill_palette[1], high = fill_palette[2], + limits = fill_limits, breaks = scales::pretty_breaks()) + + scale_y_discrete(position = "right") + facet_grid(Collection ~ ., scales = "free_y", space = "free_y") + + theme_bw() + labs(x = "NES", y = "") + + theme(axis.text.y = element_blank(), strip.background = element_rect(fill = "white", color = "black", linewidth = 1), + axis.ticks.y = element_line(size = params$tick_size), + axis.ticks.length = grid::unit(params$tick_length, "cm"), + strip.text.y = element_text(size = 1), legend.position = "none", + axis.title.x = element_text(size = params$axis_title_size), + axis.text.x = element_text(size = params$axis_text_size_x), + panel.spacing = grid::unit(params$panel_spacing_single, "lines")) + plot_text_msigdb <- ggplot() + + annotate("text", label = "MSigDB", fontface = "bold.italic", angle = 90, + size = params$side_label_size, x = 0, y = 0.5) + theme_void() + plot_right <- ggplot(df, aes(y = .data$Geneset, x = 1.5, label = .data$Collection)) + + geom_text(aes(label = ifelse(duplicated(.data$Collection), "", .data$Collection)), + hjust = 0.5, size = params$collection_text_size, fontface = "bold") + + facet_grid(Collection ~ ., scales = "free_y", space = "free", switch = "y") + theme_void() + + theme(strip.text.y = element_text(size = params$collection_text_size), + panel.spacing = grid::unit(1, "lines")) + plot_legend <- ggplot(df, aes(x = .data$NES, y = .data$Geneset, fill = .data$logFDR)) + + geom_tile() + scale_fill_gradient(low = fill_palette[1], high = fill_palette[2], + name = expression(-log[10] ~ FDR), limits = fill_limits, + guide = guide_colorbar(ticks.colour = "black", ticks.linewidth = 1.5, + draw.ulim = TRUE, draw.llim = TRUE)) + theme_bw() + + theme(legend.title = element_text(size = 44, face = "bold"), + legend.text = element_text(size = 30), + legend.key.size = grid::unit(1.5, "cm"), + legend.key.height = grid::unit(2, "cm"), + legend.spacing = grid::unit(3.5, "cm"), + legend.box.margin = margin(10, 20, 10, 10)) + plot_right_legend <- cowplot::get_legend(plot_legend) + final_plot <- plot_text_pathways + plot_left + plot_center + plot_right + + plot_text_msigdb + plot_right_legend + + patchwork::plot_layout(ncol = 6, widths = params$panel_widths) + } else { + final_plot <- ggplot(data, aes(x = .data[[Comparison]], y = .data[[axis_y]], fill = .data$logFDR)) + + geom_bar(stat = "identity", color = params$bar_col, size = params$bar_size, + width = params$bar_width) + + scale_fill_gradient(low = fill_palette[1], high = fill_palette[2], + limits = fill_limits, oob = scales::squish, + guide = guide_colorbar(barwidth = 3, barheight = 18)) + + labs(x = "Comparisons", y = axis_y) + theme_bw() + + theme(axis.line.x = element_blank(), axis.line = element_line(size = 0.5), + axis.title.x = element_text(size = params$axis_title_size), + axis.title.y = element_text(size = params$axis_title_size), + axis.text.x = element_text(size = params$axis_text_size_x), + axis.text.y = element_text(size = params$axis_text_size_y), + axis.ticks = element_line(size = params$tick_size), + axis.ticks.length = grid::unit(params$tick_length, "cm"), + strip.text = element_text(size = params$strip_text_size), + panel.spacing = grid::unit(params$panel_spacing_multi, "lines")) + + geom_hline(yintercept = 0, size = params$hline_size) + expand_limits(y = 0) + + facet_wrap(~ .data$New_name, ncol = ncol_wrap, + scales = if (free_y) "free_y" else "fixed") + if (!is.null(custom_labels)) final_plot <- final_plot + + scale_x_discrete(labels = custom_labels) + } return(final_plot) } diff --git a/man/barplot_GSEA.Rd b/man/barplot_GSEA.Rd deleted file mode 100644 index ba47ad0..0000000 --- a/man/barplot_GSEA.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/barplot_GSEA.R -\name{barplot_GSEA} -\alias{barplot_GSEA} -\title{Create and save a customized barplot for GSEA results} -\usage{ -barplot_GSEA(data, output_path, custom_labels, axis_y = "NES") -} -\arguments{ -\item{data}{A data frame containing GSEA results with columns such as \code{datatype}, \code{NES}, \code{-Log10FDR}, and \code{New_name}.} - -\item{output_path}{The file path where the barplot will be saved (SVG format).} - -\item{custom_labels}{A named vector of custom expressions for x-axis labels.} - -\item{axis_y}{Name of the column to use for the y-axis aesthetic, as a string. Default: "NES".} -} -\description{ -This function generates a customized barplot with: -\itemize{ -\item Grouped bars. -\item Adjusted aesthetics. -\item Personalized axis labels. -\item Optionally save the result in SVG format. -} -} diff --git a/man/plot_GSEA.Rd b/man/plot_GSEA.Rd index 9e39ad3..3d3b412 100644 --- a/man/plot_GSEA.Rd +++ b/man/plot_GSEA.Rd @@ -2,37 +2,87 @@ % Please edit documentation in R/plot_GSEA.R \name{plot_GSEA} \alias{plot_GSEA} -\title{Plot global GSEA results} +\title{Unified GSEA plotting function with theme configuration} \usage{ plot_GSEA( data, + Comparison = "Comparison", + custom_labels = NULL, + axis_y = "NES", + fdr_col = "FDR", + logFDR = TRUE, geneset_col, collection_col, nes_col, logfdr_col, - text_size_genesets = 5, - text_size_collection = 5 + order = c("desc", "asc"), + ncol_wrap = 2, + free_y = TRUE, + fill_limits = NULL, + fill_palette = c("white", "red"), + theme_params = list() ) } \arguments{ -\item{data}{Data frame containing the GSEA results.} +\item{data}{A data frame containing GSEA results.} -\item{geneset_col}{Name of the column containing the genesets.} +\item{Comparison}{Name of the column defining different comparisons. Default: "Comparison".} -\item{collection_col}{Name of the column containing the collections.} +\item{custom_labels}{Named vector of labels for the x-axis discrete scale (barplot mode only). Default: NULL.} -\item{nes_col}{Name of the column containing the NES values.} +\item{axis_y}{Name of the column to use for the y-axis aesthetic. Default: "NES".} -\item{logfdr_col}{Name of the column containing \eqn{-\log_{10}(FDR)} values.} +\item{fdr_col}{Name of the column containing FDR values. Default: "FDR".} -\item{text_size_genesets}{Text size for the geneset labels.} +\item{logFDR}{Logical; if TRUE, compute -log10(FDR) from \code{fdr_col}, otherwise use \code{fdr_col} directly. Default: TRUE.} -\item{text_size_collection}{Text size for the collection labels.} +\item{geneset_col}{Name of the column containing the geneset labels (single comparison mode).} + +\item{collection_col}{Name of the column containing the MSigDB collections (single comparison mode).} + +\item{nes_col}{Name of the column containing NES values (single comparison mode).} + +\item{logfdr_col}{Name of the column containing -log10(FDR) or similar (single comparison mode).} + +\item{order}{One of "desc" or "asc"; order of \code{axis_y} values. Default: c("desc","asc").} + +\item{ncol_wrap}{Number of columns for \code{facet_wrap} in barplot mode. Default: 2.} + +\item{free_y}{Logical; if TRUE, allow free y scales in facets. Default: TRUE.} + +\item{fill_limits}{Numeric vector of length 2 to set fill gradient limits (barplot mode). Default: NULL.} + +\item{fill_palette}{Character vector of two colors for fill gradient. Default: c("white","red").} + +\item{theme_params}{Named list to override default theme parameters (see details).} } \value{ -GSEA barplots arranged in a grid. +A ggplot or patchwork object for the GSEA plot. } \description{ -Generates a composite plot displaying NES values, pathway labels, -and a \emph{logFDR} legend, organized by MSigDB collections. +Creates either a global GSEA plot or a faceted barplot depending on the number of unique +comparisons in the \code{Comparison} column. Allows customizing all previously hard-coded theme +parameters via a single \code{theme_params} list. +} +\details{ +theme_params may include: +\describe{ +\item{side_label_size}{Size for side panel labels (default 35)} +\item{geneset_text_size}{Text size for geneset labels (default 5)} +\item{collection_text_size}{Text size for collection labels (default 5)} +\item{panel_widths}{Patchwork widths vector (default c(4,25,15,3,10,3))} +\item{bar_col}{Bar/col border color (default "black")} +\item{bar_size}{Border size for bars (default 0.5)} +\item{bar_width}{Width for bars (default 0.6)} +\item{col_size}{Border size for geom_col (default 1)} +\item{hline_size}{Size for horizontal line at y=0 (default 2)} +\item{axis_title_size}{Font size for axis titles (default 45)} +\item{axis_text_size_x}{Font size for x-axis text (default 30)} +\item{axis_text_size_y}{Font size for y-axis text (default 50)} +\item{tick_size}{Size for axis ticks (default 1.5)} +\item{tick_length}{Length for axis ticks in cm (default 0.3)} +\item{strip_text_size}{Font size for strip text (default 50)} +\item{panel_spacing_single}{Facet spacing single mode (default 4)} +\item{panel_spacing_multi}{Facet spacing multi mode (default 0.6)} +} } From ecad8fd1d92ea58f58a68e81f4f8eb2baede7333 Mon Sep 17 00:00:00 2001 From: DanielGarbozo Date: Mon, 15 Sep 2025 15:42:40 -0400 Subject: [PATCH 3/3] Replace names of GSEA functions --- NAMESPACE | 6 +++--- R/{heatmap_GSEA.R => heatmap_PA.R} | 8 ++++---- R/{merge_GSEA.R => merge_PA.R} | 6 +++--- R/{plot_GSEA.R => plot_PA.R} | 4 ++-- man/{heatmap_GSEA.Rd => heatmap_PA.Rd} | 12 ++++++------ man/{merge_GSEA.Rd => merge_PA.Rd} | 10 +++++----- man/{plot_GSEA.Rd => plot_PA.Rd} | 10 +++++----- 7 files changed, 28 insertions(+), 28 deletions(-) rename R/{heatmap_GSEA.R => heatmap_PA.R} (96%) rename R/{merge_GSEA.R => merge_PA.R} (93%) rename R/{plot_GSEA.R => plot_PA.R} (98%) rename man/{heatmap_GSEA.Rd => heatmap_PA.Rd} (83%) rename man/{merge_GSEA.Rd => merge_PA.Rd} (57%) rename man/{plot_GSEA.Rd => plot_PA.Rd} (95%) diff --git a/NAMESPACE b/NAMESPACE index d7c9dc4..cd794b9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,15 +4,15 @@ export(add_annotations) export(detect_filter) export(get_annotations) export(get_stars) -export(heatmap_GSEA) -export(merge_GSEA) +export(heatmap_PA) +export(merge_PA) export(nice_KM) export(nice_PCA) export(nice_UMAP) export(nice_VSB) export(nice_Volcano) export(nice_tSNE) -export(plot_GSEA) +export(plot_PA) export(power_analysis) export(save_results) export(split_cases) diff --git a/R/heatmap_GSEA.R b/R/heatmap_PA.R similarity index 96% rename from R/heatmap_GSEA.R rename to R/heatmap_PA.R index ff39ff6..56f6e90 100644 --- a/R/heatmap_GSEA.R +++ b/R/heatmap_PA.R @@ -1,10 +1,10 @@ ######################### -# Function heatmap_GSEA # +# Function heatmap_PA # ######################### -#' Plot leading edge heatmaps from GSEA results. +#' Plot leading edge heatmaps from GSEA/CAMERA/PADOG results. #' -#' Generates heatmaps of leading edge genes for each gene set from GSEA output. +#' Generates heatmaps based on normalized data of genes for each gene set from GSEA/CAMERA/PADOG output. #' #' @param main_dir Optional base directory. If supplied, it will be prepended to all relative file paths. #' @param expression_file Path to the expression data file (tab-delimited) or relative to main_dir. @@ -19,7 +19,7 @@ #' @return Saves one PDF and one JPG heatmap per gene set under output_dir; optionally saves intermediate TSV. #' @export -heatmap_GSEA <- function(main_dir = NULL, expression_file, metadata_file, gmt_file, +heatmap_PA <- function(main_dir = NULL, expression_file, metadata_file, gmt_file, ranked_genes_file, gsea_file, output_dir = "leading_edge_heatmaps", sample_col = "Sample", group_col = "group", save_dataframe = FALSE) { diff --git a/R/merge_GSEA.R b/R/merge_PA.R similarity index 93% rename from R/merge_GSEA.R rename to R/merge_PA.R index 64e10fb..5f40792 100644 --- a/R/merge_GSEA.R +++ b/R/merge_PA.R @@ -1,16 +1,16 @@ ####################### -# Function merge_GSEA # +# Function merge_PA # ####################### #' Merge GSEA results data frames. #' -#' After running GSEA_all.sh from GSEA.sh, merge_GSEA function joins .tsv files to a single file +#' After running GSEA_all.sh from GSEA.sh, merge_PA function joins .tsv files to a single file #' #' @param input_directory The directory containing the GSEA collection results in TSV format. #' @param output_file The output file to save the merged data. If not provided, the file will be saved in the input directory. #' @importFrom magrittr %>% #' @export -merge_GSEA <- function(input_directory, output_file = "collections_merged_gsea_data.tsv") { +merge_PA <- function(input_directory, output_file = "collections_merged_gsea_data.tsv") { # Avoid check NOTES for global variables across multiple functions utils::globalVariables(c( diff --git a/R/plot_GSEA.R b/R/plot_PA.R similarity index 98% rename from R/plot_GSEA.R rename to R/plot_PA.R index cf31eae..1205d48 100644 --- a/R/plot_GSEA.R +++ b/R/plot_PA.R @@ -4,7 +4,7 @@ utils::globalVariables(c( "FDR q-val","Log10FDR","FWER p-val","Comparison" )) -#' Unified GSEA plotting function with theme configuration +#' Unified Pathway analysis results plotting function with theme configuration #' #' Creates either a global GSEA plot or a faceted barplot depending on the number of unique #' comparisons in the `Comparison` column. Allows customizing all previously hard-coded theme @@ -53,7 +53,7 @@ utils::globalVariables(c( #' @importFrom cowplot get_legend #' @importFrom utils modifyList #' @export -plot_GSEA <- function( +plot_PA <- function( data, Comparison = "Comparison", custom_labels = NULL, diff --git a/man/heatmap_GSEA.Rd b/man/heatmap_PA.Rd similarity index 83% rename from man/heatmap_GSEA.Rd rename to man/heatmap_PA.Rd index 788d4b0..23a8f53 100644 --- a/man/heatmap_GSEA.Rd +++ b/man/heatmap_PA.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/heatmap_GSEA.R -\name{heatmap_GSEA} -\alias{heatmap_GSEA} -\title{Plot leading edge heatmaps from GSEA results.} +% Please edit documentation in R/heatmap_PA.R +\name{heatmap_PA} +\alias{heatmap_PA} +\title{Plot leading edge heatmaps from GSEA/CAMERA/PADOG results.} \usage{ -heatmap_GSEA( +heatmap_PA( main_dir = NULL, expression_file, metadata_file, @@ -42,5 +42,5 @@ heatmap_GSEA( Saves one PDF and one JPG heatmap per gene set under output_dir; optionally saves intermediate TSV. } \description{ -Generates heatmaps of leading edge genes for each gene set from GSEA output. +Generates heatmaps based on normalized data of genes for each gene set from GSEA/CAMERA/PADOG output. } diff --git a/man/merge_GSEA.Rd b/man/merge_PA.Rd similarity index 57% rename from man/merge_GSEA.Rd rename to man/merge_PA.Rd index d845bc8..c0a5bc9 100644 --- a/man/merge_GSEA.Rd +++ b/man/merge_PA.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/merge_GSEA.R -\name{merge_GSEA} -\alias{merge_GSEA} +% Please edit documentation in R/merge_PA.R +\name{merge_PA} +\alias{merge_PA} \title{Merge GSEA results data frames.} \usage{ -merge_GSEA(input_directory, output_file = "collections_merged_gsea_data.tsv") +merge_PA(input_directory, output_file = "collections_merged_gsea_data.tsv") } \arguments{ \item{input_directory}{The directory containing the GSEA collection results in TSV format.} @@ -12,5 +12,5 @@ merge_GSEA(input_directory, output_file = "collections_merged_gsea_data.tsv") \item{output_file}{The output file to save the merged data. If not provided, the file will be saved in the input directory.} } \description{ -After running GSEA_all.sh from GSEA.sh, merge_GSEA function joins .tsv files to a single file +After running GSEA_all.sh from GSEA.sh, merge_PA function joins .tsv files to a single file } diff --git a/man/plot_GSEA.Rd b/man/plot_PA.Rd similarity index 95% rename from man/plot_GSEA.Rd rename to man/plot_PA.Rd index 3d3b412..3fb9ced 100644 --- a/man/plot_GSEA.Rd +++ b/man/plot_PA.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot_GSEA.R -\name{plot_GSEA} -\alias{plot_GSEA} -\title{Unified GSEA plotting function with theme configuration} +% Please edit documentation in R/plot_PA.R +\name{plot_PA} +\alias{plot_PA} +\title{Unified Pathway analysis results plotting function with theme configuration} \usage{ -plot_GSEA( +plot_PA( data, Comparison = "Comparison", custom_labels = NULL,