diff --git a/DESCRIPTION b/DESCRIPTION index c0a519a..1431fd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gencoreBulk Title: NPRC Genomics Core Bulk RNA Analysis Utilities -Version: 0.2.2 +Version: 0.2.3 Date: 2024-03-22 Author: person("Derrik", "Gratz", email = "derrik.gratz@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0009-0002-5934-576X")) diff --git a/NAMESPACE b/NAMESPACE index 0585539..f2e8962 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,7 @@ export(plotFilterByExpr) export(plotGeneExpression) export(plotPCAFromConfig) export(plotVoomByGroup) +export(read_excel_allsheets) export(runfgsea) export(voomByGroup) export(writeCountTables) diff --git a/R/PCA.R b/R/PCA.R index 286b48e..241508c 100644 --- a/R/PCA.R +++ b/R/PCA.R @@ -117,7 +117,7 @@ plotPCAFromConfig <- function(analysis, #' } #' pcaPlotSimple <- function(counts, metadata, xpc = 1, ypc = 2, ntop = 500) { - if (colnames(counts) != rownames(metadata)) { + if (all(colnames(counts) != rownames(metadata))) { stop('Colnames of counts does not match rownames of metadata') } rv <- matrixStats::rowVars(counts) diff --git a/R/gseaDotplot.R b/R/gseaDotplot.R new file mode 100644 index 0000000..38f362b --- /dev/null +++ b/R/gseaDotplot.R @@ -0,0 +1,238 @@ +#' GSEA dotplot for multiple contrasts +#' +#' Make dotplot from fGSEA result, showing top n pathways +#' +#' @rdname gseaDotplot_joint +#' +#' @param gsea_results A table with multiple GSEA results from `fgsea::fgseaSimple()` +#' combined by `combine_GSEA_results()` +#' @param pathway_order Order of pathways to plot +#' @param x_order Order of comparisons on X axis +#' @param significance A vector of values to indicate significance with asterisks. +#' Each subsequent value will add an extra asterisk. E.g. `c(0.05, 0.01)` will +#' give one asteriks to values below 0.05 and two asterisks to values below 0.01. +#' If this is null, no asterisks will be plotted. +#' @param p_val_col Column to use for significance values. Default 'pval'. +#' @inheritParams ggplot2::scale_radius +#' +#' @return A ggplot object +#' @export +#' +#' @importFrom rlang .data +#' @import ggplot2 +#' @import dplyr +#' +#' @examples +#' \dontrun{ +#' combine_GSEA_results <- function(gsea_results, +#' pathways){ +#' gsea_results <- lapply(gsea_results, function(x){x %>% filter(pathway %in% pathways)}) +#' gsea_results <- data.table::rbindlist(gsea_results, idcol='ID') +#' } +#' +#' pathways = c('REACTOME_SIGNALING_BY_GPCR', 'REACTOME_SIGNALING_BY_NTRKS') +#' gsea_results <- list('FAC vs Cont' = gsea_result, 'LiproxposFAC vs Cont' = gsea_result_2) +#' joint_GSEA_results <- combine_GSEA_results(gsea_results, pathways) +#' gseaDotplot_joint(joint_GSEA_results) +#' } +gseaDotplot_joint <- function(gsea_results, + pathway_order = NULL, + x_order = NULL, + significance = c(0.05, 0.01, 0.001), + range = c(1,8), + breaks = -log10(c(0.1,0.01,0.001,0.0001)), + labels = c(0.1,0.01,0.001,0.0001), + p_val_col = 'pval'){ + if (!is.null(pathway_order)) { + if (all(pathway_order %in% unique(gsea_results$pathway))){ + pathway_order <- order(factor(gsea_results$pathway, levels = pathway_order)) + gsea_results$pathway <- .wrap_underscore_strings_balance(gsea_results$pathway,36) + ## reordering + gsea_results <- gsea_results[pathway_order,] + gsea_results$pathway <- factor(gsea_results$pathway, levels = unique(gsea_results$pathway)) + } else { + warning('pathways specified in pathway_order not found, defaulting to arbitrary order') + } + } else { + gsea_results$pathway <- .wrap_underscore_strings_balance(gsea_results$pathway,36) + } + + if (!is.null(x_order)) { + if (all(x_order %in% unique(gsea_results$ID))){ + gsea_results$ID <- factor(gsea_results$ID, levels = x_order) + } else { + warning('Specified x_order not all found in data, defaulting to arbitrary order') + } + } + + gsea_results$label <- NA + caption <- '' + if (!is.null(significance)) { + if (is.numeric(significance)) { + label <- '*' + for (cutoff in significance) { + gsea_results$label <- ifelse(gsea_results[[p_val_col]] < cutoff, label, gsea_results$label) + caption <- paste(caption, label, '<', cutoff, ';', sep = ' ') + label <- paste0(label, '*') + } + # gsea_results$label[is.numeric(gsea_results$label)] <- NA + } else { + stop('Significance argument should be a numeric vector') + } + } + ggplot(gsea_results, aes(x=.data$ID, y=.data$pathway, size=-log(.data[[p_val_col]]), + color=.data$NES, label = .data$label)) + + geom_point() + + scale_color_gradient2(low="blue", + mid="white", + high="red", + midpoint=0, + breaks=c(-2,-1,0,1,2), + limits=c(min(gsea_results$NES,-1), + max(gsea_results$NES,1))) + + theme_classic(11) + + theme(panel.grid.major = element_line(colour = "grey92"), + panel.grid.minor = element_line(colour = "grey92"), + panel.grid.major.y = element_line(colour = "grey92"),#element_blank(), + panel.grid.minor.y = element_line(colour = "grey92")) + + theme(axis.text.x = element_text(angle = 90, + vjust = 0.5, + hjust=1)) + + labs(x="Comparison", + y="Gene set", + color = "Normalized\nenrichment\nscore", + size="Nom p-val", + title="GSEA pathway enrichments", + caption = caption) + + scale_radius(name="NOM p-val", + range=range, + breaks=breaks, + labels=labels) + + geom_text(na.rm = TRUE, color = 'white', size = 3) +} + +#' GSEA dotplot for a single contrast +#' +#' Make dotplot from an fGSEA result, showing top n pathways +#' +#' @rdname gseaDotplot_single +#' @param result A table with GSEA results from `fgsea::fgseaSimple()` +#' @param min_size Minimum size of gene set to plot +#' @param filter_source Character vector of pathway sources to filter for +#' @param signif_only If TRUE, only plot results with p value < `sig_cutoff` +#' @param top_n Show the top N results sorted by pval +#' @param sig_cutoff Threshold for significance, default to 0.05 +#' @param significance A vector of values to indicate significance with asterisks. +#' Each subsequent value will add an extra asterisk. E.g. `c(0.05, 0.01)` will +#' give one asteriks to values below 0.05 and two asterisks to values below 0.01. +#' If this is null, no asterisks will be plotted. +#' @param use_shortened_pathway_names Pull names from column 'pathway_short' +#' rather than pathway (if `runfgsea()` call had `breakdown_pathway_names` set +#' to `TRUE`) +#' @param p_val_col Column to use for significance values. Default 'pval'. +#' @inheritParams ggplot2::scale_radius +#' +#' @return A ggplot object +#' @export +#' +#' @importFrom rlang .data +#' @importFrom utils head +#' @import ggplot2 +#' @import dplyr +#' +#' @examples +#' \dontrun{ +#' res <- runfgsea(result, gmt.file) +#' gseaDotplot(res, filter_source = "HALLMARK") +#' } +gseaDotplot_single <- function(result, + filter_source = NULL, + signif_only = FALSE, + top_n = 20, + min_size = 5, + sig_cutoff = 0.05, + use_shortened_pathway_names = FALSE, + significance = c(0.05, 0.01, 0.001), + range = c(1,8), + breaks = -log10(c(0.1,0.01,0.001,0.0001)), + labels = c(0.1,0.01,0.001,0.0001), + p_val_col = 'pval') { + if (use_shortened_pathway_names){ + result$pathway <- result$pathway_short + } + result <- result %>% + arrange(.data[[p_val_col]], desc(.data$NES)) %>% + mutate(perc = 100 * lengths(.data$leadingEdge) / .data$size) %>% + mutate(name = paste0(.wrap_underscore_strings_balance(.data$pathway, 36), "\nn=", .data$size)) %>% + filter(.data$size >= min_size) + if (!is.null(filter_source)) { + result <- result %>% + filter(.data$source %in% filter_source) + } + if (signif_only) { + result <- result %>% + filter(.data[[p_val_col]] < sig_cutoff) + } + + result$label <- NA + caption <- '' + if (!is.null(significance)) { + if (is.numeric(significance)) { + label <- '*' + for (cutoff in significance) { + result$label <- ifelse(result$pval < cutoff, label, result$label) + caption <- paste(caption, label, '<', cutoff, ';', sep = ' ') + label <- paste0(label, '*') + } + # gsea_results$label[is.numeric(gsea_results$label)] <- NA + } else { + stop('Significance argument should be a numeric vector') + } + } + + + toppaths <- rbind(utils::head(result, n = top_n)) + toppaths$name <- factor(toppaths$name) + dotplot <- ggplot(toppaths, + aes( + x = .data[['perc']], + y = .data[['name']], + size = -log10(.data[['pval']]), + color = .data[['NES']], + label = .data[['label']])) + + geom_point() + + scale_color_gradient2( + low = "blue", + mid = "white", + high = "red", + midpoint = 0, + breaks = c(-2, -1, 0, 1, 2), + limits = c( + min(toppaths$NES, -1), + max(toppaths$NES, 1) + ) + ) + + theme_classic(11) + + theme( + panel.grid.major = element_line(colour = "grey92"), + panel.grid.minor = element_line(colour = "grey92"), + panel.grid.major.y = element_line(colour = "grey92"), + panel.grid.minor.y = element_line(colour = "grey92") + ) + + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + + labs( + x = "% of genes in leading edge", y = "Gene set", + color = "Normalized\nenrichment\nscore", + size = "Nom p-val", title = "Top enriched pathways", + caption = paste0("n = number of genes in pathway\n", caption)) + + scale_radius( + name = "NOM p-val", + range = range, + breaks = breaks, + # limits = c(0, 3), + labels = labels + ) + + scale_y_discrete(limits = toppaths$name) + + geom_text(na.rm = TRUE, color = 'white', size = 3) + return(dotplot) +} diff --git a/R/gseaDotplot_joint.R b/R/gseaDotplot_joint.R deleted file mode 100644 index 28f3f19..0000000 --- a/R/gseaDotplot_joint.R +++ /dev/null @@ -1,108 +0,0 @@ -#' GSEA dotplot -#' -#' Make dotplot from fGSEA result, showing top n pathways -#' -#' @rdname gseaDotplot_joint -#' -#' @param gsea_results A table with multiple GSEA results from `fgsea::fgseaSimple()` -#' combined by `combine_GSEA_results()` -#' @param pathway_order Order of pathways to plot -#' @param x_order Order of comparisons on X axis -#' @param significance A vector of values to indicate significance with asterisks. -#' Each subsequent value will add an extra asterisk. E.g. `c(0.05, 0.01)` will -#' give one asteriks to values below 0.05 and two asterisks to values below 0.01. -#' If this is null, no asterisks will be plotted. -#' @param p_val_col Column to use for significance values. Default 'pval'. -#' -#' @return A ggplot object -#' @export -#' -#' @importFrom rlang .data -#' @import ggplot2 -#' @import dplyr -#' -#' @examples -#' \dontrun{ -#' combine_GSEA_results <- function(gsea_results, -#' pathways){ -#' gsea_results <- lapply(gsea_results, function(x){x %>% filter(pathway %in% pathways)}) -#' gsea_results <- data.table::rbindlist(gsea_results, idcol='ID') -#' } -#' -#' pathways = c('REACTOME_SIGNALING_BY_GPCR', 'REACTOME_SIGNALING_BY_NTRKS') -#' gsea_results <- list('FAC vs Cont' = gsea_result, 'LiproxposFAC vs Cont' = gsea_result_2) -#' joint_GSEA_results <- combine_GSEA_results(gsea_results, pathways) -#' gseaDotplot_joint(joint_GSEA_results) -#' } -gseaDotplot_joint <- function(gsea_results, - pathway_order = NULL, - x_order = NULL, - significance = c(0.05, 0.01, 0.001), - p_val_col = 'pval'){ - if (!is.null(pathway_order)) { - if (all(pathway_order %in% unique(gsea_results$pathway))){ - pathway_order <- order(factor(gsea_results$pathway, levels = pathway_order)) - gsea_results$pathway <- .wrap_underscore_strings_balance(gsea_results$pathway,36) - ## reordering - gsea_results <- gsea_results[pathway_order,] - gsea_results$pathway <- factor(gsea_results$pathway, levels = unique(gsea_results$pathway)) - } else { - warning('pathways specified in pathway_order not found, defaulting to arbitrary order') - } - } else { - gsea_results$pathway <- .wrap_underscore_strings_balance(gsea_results$pathway,36) - } - - if (!is.null(x_order)) { - if (all(x_order %in% unique(gsea_results$ID))){ - gsea_results$ID <- factor(gsea_results$ID, levels = x_order) - } else { - warning('Specified x_order not all found in data, defaulting to arbitrary order') - } - } - - gsea_results$label <- NA - caption <- '' - if (!is.null(significance)) { - if (is.numeric(significance)) { - label <- '*' - for (cutoff in significance) { - gsea_results$label <- ifelse(gsea_results[[p_val_col]] < cutoff, label, gsea_results$label) - caption <- paste(caption, label, '<', cutoff, ';', sep = ' ') - label <- paste0(label, '*') - } - # gsea_results$label[is.numeric(gsea_results$label)] <- NA - } else { - stop('Significance argument should be a numeric vector') - } - } - ggplot(gsea_results, aes(x=.data$ID, y=.data$pathway, size=-log(.data[[p_val_col]]), - color=.data$NES, label = .data$label)) + - geom_point() + - scale_color_gradient2(low="blue", - mid="white", - high="red", - midpoint=0, - breaks=c(-2,-1,0,1,2), - limits=c(min(gsea_results$NES,-1), - max(gsea_results$NES,1))) + - theme_classic(11) + - theme(panel.grid.major = element_line(colour = "grey92"), - panel.grid.minor = element_line(colour = "grey92"), - panel.grid.major.y = element_line(colour = "grey92"),#element_blank(), - panel.grid.minor.y = element_line(colour = "grey92")) + - theme(axis.text.x = element_text(angle = 90, - vjust = 0.5, - hjust=1)) + - labs(x="Comparison", - y="Gene set", - color = "Normalized\nenrichment\nscore", - size="Nom p-val", - title="GSEA pathway enrichments", - caption = caption) + - scale_radius(name="NOM p-val", - range=c(1,8), - breaks=-log10(c(0.1,0.01,0.001,0.0001)), - labels=c(0.1,0.01,0.001,0.0001)) + - geom_text(na.rm = TRUE, color = 'white', size = 3) -} \ No newline at end of file diff --git a/R/gseaDotplot_single.R b/R/gseaDotplot_single.R deleted file mode 100644 index 0fcae4c..0000000 --- a/R/gseaDotplot_single.R +++ /dev/null @@ -1,121 +0,0 @@ -#' GSEA dotplot -#' -#' Make dotplot from fGSEA result, showing top n pathways -#' -#' @rdname gseaDotplot_single -#' @param result A table with GSEA results from `fgsea::fgseaSimple()` -#' @param min_size Minimum size of gene set to plot -#' @param filter_source Character vector of pathway sources to filter for -#' @param signif_only If TRUE, only plot results with p value < `sig_cutoff` -#' @param top_n Show the top N results sorted by pval -#' @param sig_cutoff Threshold for significance, default to 0.05 -#' @param significance A vector of values to indicate significance with asterisks. -#' Each subsequent value will add an extra asterisk. E.g. `c(0.05, 0.01)` will -#' give one asteriks to values below 0.05 and two asterisks to values below 0.01. -#' If this is null, no asterisks will be plotted. -#' @param use_shortened_pathway_names Pull names from column 'pathway_short' -#' rather than pathway (if `runfgsea()` call had `breakdown_pathway_names` set -#' to `TRUE`) -#' @param p_val_col Column to use for significance values. Default 'pval'. -#' -#' @return A ggplot object -#' @export -#' -#' @importFrom rlang .data -#' @importFrom utils head -#' @import ggplot2 -#' @import dplyr -#' -#' @examples -#' \dontrun{ -#' res <- runfgsea(result, gmt.file) -#' gseaDotplot(res, filter_source = "HALLMARK") -#' } -gseaDotplot_single <- function(result, - filter_source = NULL, - signif_only = FALSE, - top_n = 20, - min_size = 5, - sig_cutoff = 0.05, - use_shortened_pathway_names = FALSE, - significance = c(0.05, 0.01, 0.001), - p_val_col = 'pval') { - if (use_shortened_pathway_names){ - result$pathway <- result$pathway_short - } - result <- result %>% - arrange(.data[[p_val_col]], desc(.data$size)) %>% - mutate(perc = 100 * lengths(.data$leadingEdge) / .data$size) %>% - mutate(name = paste0(.wrap_underscore_strings_balance(.data$pathway, 36), "\nn=", .data$size)) %>% - filter(.data$size >= min_size) - if (!is.null(filter_source)) { - result <- result %>% - filter(.data$source %in% filter_source) - } - if (signif_only) { - result <- result %>% - filter(.data[[p_val_col]] < sig_cutoff) - } - - result$label <- NA - caption <- '' - if (!is.null(significance)) { - if (is.numeric(significance)) { - label <- '*' - for (cutoff in significance) { - result$label <- ifelse(result$pval < cutoff, label, result$label) - caption <- paste(caption, label, '<', cutoff, ';', sep = ' ') - label <- paste0(label, '*') - } - # gsea_results$label[is.numeric(gsea_results$label)] <- NA - } else { - stop('Significance argument should be a numeric vector') - } - } - - - toppaths <- rbind(utils::head(result, n = top_n)) - toppaths$name <- factor(toppaths$name) - dotplot <- ggplot(toppaths, - aes( - x = .data[['perc']], - y = .data[['name']], - size = -log10(.data[['pval']]), - color = .data[['NES']], - label = .data[['label']])) + - geom_point() + - scale_color_gradient2( - low = "blue", - mid = "white", - high = "red", - midpoint = 0, - breaks = c(-2, -1, 0, 1, 2), - limits = c( - min(toppaths$NES, -1), - max(toppaths$NES, 1) - ) - ) + - theme_classic(11) + - theme( - panel.grid.major = element_line(colour = "grey92"), - panel.grid.minor = element_line(colour = "grey92"), - panel.grid.major.y = element_line(colour = "grey92"), - panel.grid.minor.y = element_line(colour = "grey92") - ) + - theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + - labs( - x = "% of genes in leading edge", y = "Gene set", - color = "Normalized\nenrichment\nscore", - size = "Nom p-val", title = "Top enriched pathways", - caption = paste0("n = number of genes in pathway\n", caption)) + - scale_radius( - name = "NOM p-val", - range = c(1, 8), - breaks = -log10(c(0.5, 0.1, 0.01, 0.001)), - limits = c(0, 3), - labels = c(0.5, 0.1, 0.01, 0.001) - ) + - scale_y_discrete(limits = toppaths$name) + - geom_text(na.rm = TRUE, color = 'black', size = 3) - return(dotplot) -} diff --git a/R/heatmapFromGenelist.R b/R/heatmapFromGenelist.R index 67d5782..23da82f 100644 --- a/R/heatmapFromGenelist.R +++ b/R/heatmapFromGenelist.R @@ -45,20 +45,15 @@ #' ## Simple call #' heatmapFromGenelist( #' geneList = c("Ccl2", "Cxcl1", "Cxcl2", "Postn", "Fn1", "Thbs1"), -#' data_to_plot, -#' baseline_grouping = "Group", -#' baseline = "Cont" +#' data_to_plot #' ) #' -#' ## run with custom reordering of data and labeled slices +#' ## run with labeled slices #' heatmapFromGenelist( #' geneList = c("Ccl2", "Cxcl1", "Cxcl2", "Postn", "Fn1", "Thbs1"), #' data_to_plot, -#' baseline_grouping = "Group", -#' baseline = "Cont", #' column_split = c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3)), -#' slice_labels = c("Cont", "Fac", "L", "M"), -#' data = assays(analysis$dds)$rld[, sort(colnames(assays(analysis$dds)$rld))] +#' slice_labels = c("Cont", "Fac", "L", "M") #' ) #' } #' diff --git a/R/utils.R b/R/utils.R index ec7a969..26b26eb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -21,3 +21,32 @@ string }, character(1), width, indent, exdent, USE.NAMES = USE.NAMES) } + + +#' Read an excel workbook with sheets to a list of tables +#' +#' Read an excel workbook with sheets to a list of tables +#' +#' @param filename File in format .xls or .xlsx +#' @param tibble BOOL, Return the data as a tibble instead of a data.frame +#' @param \dots Additional arguments passed to `openxlsx::read.xlsx()` +#' +#' @returns A list of data.frames (or tibbles) +#' +#' @import openxlsx +#' @export +#' +#' @examples +#' \dontrun{ +#' dge_results <- read_excel_allsheets(here('outputs/dge.xlsx')) +#' } +read_excel_allsheets <- function(filename, + tibble = FALSE, + ...) { + # https://stackoverflow.com/a/12945838/15664425 + sheets <- openxlsx::getSheetNames(filename) + x <- lapply(sheets, function(X) openxlsx::read.xlsx(filename, sheet = X, ...)) + if(!tibble) x <- lapply(x, as.data.frame) + names(x) <- sheets + x +} \ No newline at end of file diff --git a/man/gseaDotplot_joint.Rd b/man/gseaDotplot_joint.Rd index 3d95732..0f2ad13 100644 --- a/man/gseaDotplot_joint.Rd +++ b/man/gseaDotplot_joint.Rd @@ -1,14 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gseaDotplot_joint.R +% Please edit documentation in R/gseaDotplot.R \name{gseaDotplot_joint} \alias{gseaDotplot_joint} -\title{GSEA dotplot} +\title{GSEA dotplot for multiple contrasts} \usage{ gseaDotplot_joint( gsea_results, pathway_order = NULL, x_order = NULL, significance = c(0.05, 0.01, 0.001), + range = c(1, 8), + breaks = -log10(c(0.1, 0.01, 0.001, 1e-04)), + labels = c(0.1, 0.01, 0.001, 1e-04), p_val_col = "pval" ) } @@ -25,6 +28,32 @@ Each subsequent value will add an extra asterisk. E.g. \code{c(0.05, 0.01)} will give one asteriks to values below 0.05 and two asterisks to values below 0.01. If this is null, no asterisks will be plotted.} +\item{range}{a numeric vector of length 2 that specifies the minimum and +maximum size of the plotting symbol after transformation.} + +\item{breaks}{One of: +\itemize{ +\item \code{NULL} for no breaks +\item \code{waiver()} for the default breaks computed by the +\link[scales:trans_new]{transformation object} +\item A numeric vector of positions +\item A function that takes the limits as input and returns breaks +as output (e.g., a function returned by \code{\link[scales:breaks_extended]{scales::extended_breaks()}}). +Also accepts rlang \link[rlang:as_function]{lambda} function notation. +}} + +\item{labels}{One of: +\itemize{ +\item \code{NULL} for no labels +\item \code{waiver()} for the default labels computed by the +transformation object +\item A character vector giving labels (must be same length as \code{breaks}) +\item An expression vector (must be the same length as breaks). See ?plotmath for details. +\item A function that takes the breaks as input and returns labels +as output. Also accepts rlang \link[rlang:as_function]{lambda} function +notation. +}} + \item{p_val_col}{Column to use for significance values. Default 'pval'.} } \value{ diff --git a/man/gseaDotplot_single.Rd b/man/gseaDotplot_single.Rd index b3ebc22..6d83006 100644 --- a/man/gseaDotplot_single.Rd +++ b/man/gseaDotplot_single.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gseaDotplot_single.R +% Please edit documentation in R/gseaDotplot.R \name{gseaDotplot_single} \alias{gseaDotplot_single} -\title{GSEA dotplot} +\title{GSEA dotplot for a single contrast} \usage{ gseaDotplot_single( result, @@ -13,6 +13,9 @@ gseaDotplot_single( sig_cutoff = 0.05, use_shortened_pathway_names = FALSE, significance = c(0.05, 0.01, 0.001), + range = c(1, 8), + breaks = -log10(c(0.1, 0.01, 0.001, 1e-04)), + labels = c(0.1, 0.01, 0.001, 1e-04), p_val_col = "pval" ) } @@ -38,13 +41,39 @@ Each subsequent value will add an extra asterisk. E.g. \code{c(0.05, 0.01)} will give one asteriks to values below 0.05 and two asterisks to values below 0.01. If this is null, no asterisks will be plotted.} +\item{range}{a numeric vector of length 2 that specifies the minimum and +maximum size of the plotting symbol after transformation.} + +\item{breaks}{One of: +\itemize{ +\item \code{NULL} for no breaks +\item \code{waiver()} for the default breaks computed by the +\link[scales:trans_new]{transformation object} +\item A numeric vector of positions +\item A function that takes the limits as input and returns breaks +as output (e.g., a function returned by \code{\link[scales:breaks_extended]{scales::extended_breaks()}}). +Also accepts rlang \link[rlang:as_function]{lambda} function notation. +}} + +\item{labels}{One of: +\itemize{ +\item \code{NULL} for no labels +\item \code{waiver()} for the default labels computed by the +transformation object +\item A character vector giving labels (must be same length as \code{breaks}) +\item An expression vector (must be the same length as breaks). See ?plotmath for details. +\item A function that takes the breaks as input and returns labels +as output. Also accepts rlang \link[rlang:as_function]{lambda} function +notation. +}} + \item{p_val_col}{Column to use for significance values. Default 'pval'.} } \value{ A ggplot object } \description{ -Make dotplot from fGSEA result, showing top n pathways +Make dotplot from an fGSEA result, showing top n pathways } \examples{ \dontrun{ diff --git a/man/heatmapFromGenelist.Rd b/man/heatmapFromGenelist.Rd index 61062d4..2c907d5 100644 --- a/man/heatmapFromGenelist.Rd +++ b/man/heatmapFromGenelist.Rd @@ -172,20 +172,15 @@ data_to_plot <- normalizeCountsForHeatmapByIndividual(assay(assays(obj.pbmc)$rld ## Simple call heatmapFromGenelist( geneList = c("Ccl2", "Cxcl1", "Cxcl2", "Postn", "Fn1", "Thbs1"), - data_to_plot, - baseline_grouping = "Group", - baseline = "Cont" + data_to_plot ) -## run with custom reordering of data and labeled slices +## run with labeled slices heatmapFromGenelist( geneList = c("Ccl2", "Cxcl1", "Cxcl2", "Postn", "Fn1", "Thbs1"), data_to_plot, - baseline_grouping = "Group", - baseline = "Cont", column_split = c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3)), - slice_labels = c("Cont", "Fac", "L", "M"), - data = assays(analysis$dds)$rld[, sort(colnames(assays(analysis$dds)$rld))] + slice_labels = c("Cont", "Fac", "L", "M") ) } diff --git a/man/read_excel_allsheets.Rd b/man/read_excel_allsheets.Rd new file mode 100644 index 0000000..a0e582c --- /dev/null +++ b/man/read_excel_allsheets.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{read_excel_allsheets} +\alias{read_excel_allsheets} +\title{Read an excel workbook with sheets to a list of tables} +\usage{ +read_excel_allsheets(filename, tibble = FALSE, ...) +} +\arguments{ +\item{filename}{File in format .xls or .xlsx} + +\item{tibble}{BOOL, Return the data as a tibble instead of a data.frame} + +\item{\dots}{Additional arguments passed to \code{openxlsx::read.xlsx()}} +} +\value{ +A list of data.frames (or tibbles) +} +\description{ +Read an excel workbook with sheets to a list of tables +} +\examples{ +\dontrun{ + dge_results <- read_excel_allsheets(here('outputs/dge.xlsx')) +} +}