From f1c82aa7bab015ae65768ab09cbc467499fdb5a9 Mon Sep 17 00:00:00 2001 From: pamonlan Date: Thu, 10 Aug 2023 10:16:34 +0200 Subject: [PATCH] Add 'render' function to bypass plot generation --- DESCRIPTION | 4 ++-- NAMESPACE | 18 ++++++++++-------- R/combining_mv.R | 44 +++++++++++++++++++++++++------------------- R/rem_mv.R | 39 ++++++++++++++++++++++++--------------- man/combining_mv.Rd | 24 ++++++++++++++++++++---- man/diffexplist.Rd | 6 ++++-- man/draw_forest.Rd | 14 +++++++++++--- man/rem_mv.Rd | 30 ++++++++++++++++++++++++------ man/votecount_mv.Rd | 18 ++++++++++++++---- 9 files changed, 134 insertions(+), 63 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0c31722..68d7b36 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: MetaVolcanoR Type: Package Title: Gene Expression Meta-analysis Visualization Tool -Version: 1.0.1 +Version: 1.0.2 Authors@R: c(person("Cesar", "Prada", email = "cesar.prada@usp.br", role = c("aut", "cre")), person("Diogenes", "Lima", email = "diogenes.lima@usp.br", role = c("aut")), person("Helder", "Nakaya", email = "hnkaya@usp.br", @@ -39,4 +39,4 @@ biocViews: GeneExpression, DifferentialExpression, Transcriptomics, mRNAMicroarr LazyData: true roxygennote: 6.1.1.9000 VignetteBuilder: knitr -RoxygenNote: 6.1.1 +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE index ac3e917..d7dc1fe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,19 +15,21 @@ export(remodel) export(rename_col) export(set_degbar_data) export(votecount_mv) +import(dplyr) import(ggplot2) -import(data.table) -import(graphics) -import(stats) -import(tidyr) -importFrom(grDevices, pdf, dev.off) -importFrom(htmlwidgets, saveWidget) importFrom(cowplot,plot_grid) +importFrom(grDevices,dev.off) +importFrom(grDevices,pdf) +importFrom(graphics,plot) +importFrom(htmlwidgets,saveWidget) importFrom(methods,'slot<-') importFrom(methods,is) importFrom(methods,new) importFrom(methods,show) importFrom(parallel,mclapply) -importFrom(plotly, as_widget, ggplotly) +importFrom(plotly,as_widget) +importFrom(plotly,ggplotly) +importFrom(stats,median) +importFrom(stats,quantile) +importFrom(stats,setNames) importFrom(topconfects,normal_confects) -importFrom(dplyr, mutate, arrange, select, matches, '%>%') diff --git a/R/combining_mv.R b/R/combining_mv.R index 1c800d2..58e82f9 100644 --- a/R/combining_mv.R +++ b/R/combining_mv.R @@ -25,6 +25,11 @@ NULL #' @param outputfolder /path where to write the results/ #' @param draw wheather or not to draw the .pdf or .html visualization #' +#' @param render A boolean parameter that determines whether the plot should be rendered. +#' If `TRUE`, the function will produce and save the plot based on the specified `draw` +#' parameter (either as an HTML or PDF file). If `FALSE` (default), no plot will be +#' rendered or saved. It's useful for cases where you might want to run the function +#' for its side effects or calculations without necessarily visualizing the result. #' @return \code{MetaVolcano} object #' @keywords write 'combining meta-analysis' metavolcano #' @export @@ -36,7 +41,7 @@ combining_mv <- function(diffexp=list(), pcriteria="pvalue", foldchangecol="Log2FC", genenamecol="Symbol", geneidcol=NULL, metafc="Mean", metathr=0.01, collaps="FALSE", jobname="MetaVolcano", - outputfolder=".", draw="HTML") { + outputfolder=".", draw="HTML", render = F) { if(!draw %in% c('PDF', 'HTML')) { @@ -159,24 +164,25 @@ combining_mv <- function(diffexp=list(), pcriteria="pvalue", # --- Drawing combining MetaVolcano gg <- plot_mv(meta_diffexp, NULL, genecol, TRUE, metafc) - - if(draw == "HTML") { - - # --- Writing html device for offline visualization - saveWidget(as_widget(ggplotly(gg)), - paste0(normalizePath(outputfolder), - '/combining_method_MetaVolcano_', jobname, ".html")) - - } else if(draw == "PDF") { - - # --- Writing PDF visualization - pdf(paste0(normalizePath(outputfolder), - '/combining_method_MetaVolcano_', jobname, ".pdf"), - width = 4, height = 5) - plot(gg) - dev.off() - - } + if(render) { + if(draw == "HTML") { + + # --- Writing html device for offline visualization + saveWidget(as_widget(ggplotly(gg)), + paste0(normalizePath(outputfolder), + '/combining_method_MetaVolcano_', jobname, ".html")) + + } else if(draw == "PDF") { + + # --- Writing PDF visualization + pdf(paste0(normalizePath(outputfolder), + '/combining_method_MetaVolcano_', jobname, ".pdf"), + width = 4, height = 5) + plot(gg) + dev.off() + + } + } # Set combining result icols <- paste(c(genecol, pcriteria, foldchangecol), collapse="|") diff --git a/R/rem_mv.R b/R/rem_mv.R index 50ed3a9..1ab4487 100644 --- a/R/rem_mv.R +++ b/R/rem_mv.R @@ -47,6 +47,11 @@ setClass('MetaVolcano', slots = list(input='data.frame', #' @param outputfolder /path where to write the results/ #' @param draw wheather or not to draw the .html visualization #' @param ncores the number of processors the user wants to use +#' #' @param render A boolean parameter that determines whether the plot should be rendered. +#' If `TRUE`, the function will produce and save the plot based on the specified `draw` +#' parameter (either as an HTML or PDF file). If `FALSE` (default), no plot will be +#' rendered or saved. It's useful for cases where you might want to run the function +#' for its side effects or calculations without necessarily visualizing the result. #' @keywords write 'combining meta-analysis' metavolcano #' @return MetaVolcano object #' @export @@ -61,7 +66,7 @@ rem_mv <- function(diffexp=list(), pcriteria="pvalue", foldchangecol="Log2FC", genenamecol="Symbol", geneidcol=NULL, collaps=FALSE, llcol="CI.L", rlcol="CI.R", vcol=NULL, cvar=TRUE, metathr=0.01, jobname="MetaVolcano", outputfolder=".", - draw='HTML', ncores=1) { + draw='HTML', ncores=1, render = F) { if(!draw %in% c('PDF', 'HTML')) { @@ -199,24 +204,28 @@ rem_mv <- function(diffexp=list(), pcriteria="pvalue", foldchangecol="Log2FC", # --- Draw REM MetaVolcano gg <- plot_rem(meta_diffexp, jobname, outputfolder, genecol, metathr) - if(draw == "HTML") { + if(render) { + + if(draw == "HTML") { # --- Writing html device for offline visualization saveWidget(as_widget(ggplotly(gg)), - paste0(normalizePath(outputfolder), - "/RandomEffectModel_MetaVolcano_", - jobname, ".html")) - - } else if(draw == "PDF") { - + paste0(normalizePath(outputfolder), + "/RandomEffectModel_MetaVolcano_", + jobname, ".html")) + + } else if(draw == "PDF") { + # --- Writing PDF visualization - pdf(paste0(normalizePath(outputfolder), - "/RandomEffectModel_MetaVolcano_", jobname, - ".pdf"), width = 7, height = 6) - plot(gg) - dev.off() - - } + pdf(paste0(normalizePath(outputfolder), + "/RandomEffectModel_MetaVolcano_", jobname, + ".pdf"), width = 7, height = 6) + plot(gg) + dev.off() + + } + + } # Set REM result icols <- paste(c(genecol, pcriteria, foldchangecol, llcol, rlcol, vcol), diff --git a/man/combining_mv.Rd b/man/combining_mv.Rd index 3752d0a..bcafcd8 100644 --- a/man/combining_mv.Rd +++ b/man/combining_mv.Rd @@ -4,10 +4,20 @@ \alias{combining_mv} \title{A function to draw the 'Combining meta-analysis' MetaVolcano} \usage{ -combining_mv(diffexp = list(), pcriteria = "pvalue", - foldchangecol = "Log2FC", genenamecol = "Symbol", geneidcol = NULL, - metafc = "Mean", metathr = 0.01, collaps = "FALSE", - jobname = "MetaVolcano", outputfolder = ".", draw = "HTML") +combining_mv( + diffexp = list(), + pcriteria = "pvalue", + foldchangecol = "Log2FC", + genenamecol = "Symbol", + geneidcol = NULL, + metafc = "Mean", + metathr = 0.01, + collaps = "FALSE", + jobname = "MetaVolcano", + outputfolder = ".", + draw = "HTML", + render = F +) } \arguments{ \item{diffexp}{list of data.frame/data.table (s) with DE results where lines @@ -37,6 +47,12 @@ c("Mean", "Median") } \item{draw}{wheather or not to draw the .pdf or .html visualization } + +\item{render}{A boolean parameter that determines whether the plot should be rendered. +If `TRUE`, the function will produce and save the plot based on the specified `draw` +parameter (either as an HTML or PDF file). If `FALSE` (default), no plot will be +rendered or saved. It's useful for cases where you might want to run the function +for its side effects or calculations without necessarily visualizing the result.} } \value{ \code{MetaVolcano} object diff --git a/man/diffexplist.Rd b/man/diffexplist.Rd index 993bb6d..ea3ec9d 100644 --- a/man/diffexplist.Rd +++ b/man/diffexplist.Rd @@ -4,12 +4,14 @@ \name{diffexplist} \alias{diffexplist} \title{Differential expression results from five studies} -\format{A named list with 5 data frames with ~20k genes and 5 variables: +\format{ +A named list with 5 data frames with ~20k genes and 5 variables: \describe{ \item{GSE12050}{differential expression result, disease vs healthy} \item{GSE24883}{differential expression result, disease vs healthy} ... -}} +} +} \source{ \url{https://www.ncbi.nlm.nih.gov/geo/} } diff --git a/man/draw_forest.Rd b/man/draw_forest.Rd index 484eb6e..6580db3 100644 --- a/man/draw_forest.Rd +++ b/man/draw_forest.Rd @@ -4,9 +4,17 @@ \alias{draw_forest} \title{A function to draw a forest plot from the REM MetaVolcano result} \usage{ -draw_forest(remres, gene = "MMP9", genecol = "Symbol", - foldchangecol = "Log2FC", llcol = "CI.L", rlcol = "CI.R", - jobname = "MetaVolcano", outputfolder = ".", draw = "PDF") +draw_forest( + remres, + gene = "MMP9", + genecol = "Symbol", + foldchangecol = "Log2FC", + llcol = "CI.L", + rlcol = "CI.R", + jobname = "MetaVolcano", + outputfolder = ".", + draw = "PDF" +) } \arguments{ \item{remres}{MetaVolcano object. Output of the rem_mv() function diff --git a/man/rem_mv.Rd b/man/rem_mv.Rd index 2c31e81..ef34f23 100644 --- a/man/rem_mv.Rd +++ b/man/rem_mv.Rd @@ -4,11 +4,24 @@ \alias{rem_mv} \title{A function to perform the Random Effect Model (REM) MetaVolcano} \usage{ -rem_mv(diffexp = list(), pcriteria = "pvalue", - foldchangecol = "Log2FC", genenamecol = "Symbol", geneidcol = NULL, - collaps = FALSE, llcol = "CI.L", rlcol = "CI.R", vcol = NULL, - cvar = TRUE, metathr = 0.01, jobname = "MetaVolcano", - outputfolder = ".", draw = "HTML", ncores = 1) +rem_mv( + diffexp = list(), + pcriteria = "pvalue", + foldchangecol = "Log2FC", + genenamecol = "Symbol", + geneidcol = NULL, + collaps = FALSE, + llcol = "CI.L", + rlcol = "CI.R", + vcol = NULL, + cvar = TRUE, + metathr = 0.01, + jobname = "MetaVolcano", + outputfolder = ".", + draw = "HTML", + ncores = 1, + render = F +) } \arguments{ \item{diffexp}{list of data.frame/data.table (s) with DE results where lines @@ -45,7 +58,12 @@ interval limits } \item{draw}{wheather or not to draw the .html visualization } -\item{ncores}{the number of processors the user wants to use } +\item{ncores}{the number of processors the user wants to use +#' @param render A boolean parameter that determines whether the plot should be rendered. +If `TRUE`, the function will produce and save the plot based on the specified `draw` +parameter (either as an HTML or PDF file). If `FALSE` (default), no plot will be +rendered or saved. It's useful for cases where you might want to run the function +for its side effects or calculations without necessarily visualizing the result.} } \value{ MetaVolcano object diff --git a/man/votecount_mv.Rd b/man/votecount_mv.Rd index 3df69ef..d070e96 100644 --- a/man/votecount_mv.Rd +++ b/man/votecount_mv.Rd @@ -4,10 +4,20 @@ \alias{votecount_mv} \title{A function to draw the 'Vote-counting meta-analysis' MetaVolcano} \usage{ -votecount_mv(diffexp = list(), pcriteria = "pvalue", - foldchangecol = "Log2FC", genenamecol = "Symbol", geneidcol = NULL, - pvalue = 0.05, foldchange = 0, metathr = 0.01, collaps = FALSE, - jobname = "MetaVolcano", outputfolder = ".", draw = "HTML") +votecount_mv( + diffexp = list(), + pcriteria = "pvalue", + foldchangecol = "Log2FC", + genenamecol = "Symbol", + geneidcol = NULL, + pvalue = 0.05, + foldchange = 0, + metathr = 0.01, + collaps = FALSE, + jobname = "MetaVolcano", + outputfolder = ".", + draw = "HTML" +) } \arguments{ \item{diffexp}{list of data.frame/data.table (s) with DE results where lines