From 5eedb79c90365069552dbc1be753eae08fc2cc39 Mon Sep 17 00:00:00 2001 From: michaelgruenstaeudl Date: Wed, 28 Feb 2024 15:50:11 -0600 Subject: [PATCH 1/3] Increase logger use, improve logger format --- CHANGELOG.md | 1 + DESCRIPTION | 4 ++-- R/PACVr.R | 14 ++++++++------ R/RCircosOps.R | 16 ++++++++-------- R/coverageCalcOps.R | 4 ++-- R/helpers.R | 4 ++-- R/visualisationOps.R | 8 +++----- inst/extdata/PACVr_Rscript.R | 8 ++++---- inst/extdata/PACVr_run_parallel.R | 26 +++++++++++++------------- man/PACVr.complete.Rd | 8 ++++---- vignettes/PACVr_Vignette.Rnw | 2 +- 11 files changed, 48 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e259e59d..01ab1c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG #### Version 1.0.9 (2024.02.29) * Improving variable and file names * Correcting output plot specifications +* Increase logger use, improve logger format #### Version 1.0.8 (2024.02.28) * Handling of GenBank features with multiple qualifiers of the same name diff --git a/DESCRIPTION b/DESCRIPTION index d0e77535..216d41b6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: PACVr -Version: 1.0.8 -Date: 2024-02-28 +Version: 1.0.9 +Date: 2024-02-29 Title: Plastome Assembly Coverage Visualization Authors@R: c(person("Gregory", "Smith", role=c("ctb")), person("Nils", "Jenke", role=c("ctb")), diff --git a/R/PACVr.R b/R/PACVr.R index e45a27f7..191f20a5 100644 --- a/R/PACVr.R +++ b/R/PACVr.R @@ -83,7 +83,7 @@ PACVr.vizWithRCircos <- function(gbkData, #' value of the average coverage instead of an absolute value #' @param textSize a numeric value that specifies the relative font size of the #' text element in the visualization -#' @param verbose a boolean, that when TRUE, generates additional files with +#' @param tabularCovStats a boolean, that when TRUE, generates additional files with #' detailed genomic region information #' @param output a character string that specifies the name of, and path to, #' the output file @@ -98,7 +98,7 @@ PACVr.vizWithRCircos <- function(gbkData, #' outFile <- paste(tempdir(), "/NC_045072__all_reads.pdf", sep="") #' PACVr.complete(gbkFile=gbkFile, bamFile=bamFile, windowSize=250, logScale=FALSE, #' threshold=0.5, IRCheck=1, relative=TRUE, textSize=0.5, -#' verbose=FALSE, output=outFile) +#' tabularCovStats=FALSE, output=outFile) #' } #' \dontrun{ #' gbkFile <- system.file("extdata", "MG936619/MG936619.gb", package="PACVr") @@ -106,7 +106,7 @@ PACVr.vizWithRCircos <- function(gbkData, #' outFile <- paste(tempdir(), "/MG936619_CoverageViz.pdf", sep="") #' PACVr.complete(gbkFile=gbkFile, bamFile=bamFile, windowSize=50, logScale=FALSE, #' threshold=0.5, IRCheck=NA, relative=TRUE, textSize=0.5, -#' verbose=FALSE, output=outFile) +#' tabularCovStats=FALSE, output=outFile) #' } PACVr.complete <- function(gbkFile, @@ -117,7 +117,7 @@ PACVr.complete <- function(gbkFile, IRCheck=NA, relative=TRUE, textSize=0.5, - verbose=FALSE, + tabularCovStats=FALSE, output=NA) { ###################################################################### read.gbData <- PACVr.read.gb(gbkFile) @@ -131,7 +131,9 @@ PACVr.complete <- function(gbkFile, logger::log_fatal('Parsing of any sequence features unsuccessful.') return(-1) } - + ################################### + logger <- logger::layout_glue_generator(format='{time} {gbkData$sampleName} -- {level}: {msg}') + logger::log_layout(logger) ################################### plotSpecs <- getPlotSpecs(logScale, threshold, @@ -145,7 +147,7 @@ PACVr.complete <- function(gbkFile, plotSpecs$logScale) ################################### - if (verbose) { + if (tabularCovStats) { PACVr.compileCovStats(gbkData, coverage$raw, analysisSpecs, diff --git a/R/RCircosOps.R b/R/RCircosOps.R index 03f6dd5c..a2d2dad4 100644 --- a/R/RCircosOps.R +++ b/R/RCircosOps.R @@ -42,19 +42,19 @@ PACVr.Histogram.Plot <- function(hist.data = NULL, genomic.columns = 3, is.sorted = TRUE) { if (is.null(hist.data)) { - warning("Genomic data missing in input.") - stop() + logger::log_error("Genomic data missing in input.") + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } boundary <- RCircos::RCircos.Get.Plot.Boundary(track.num, side, inside.pos, outside.pos, FALSE) outerPos <- boundary[1] innerPos <- boundary[2] if (is.null(genomic.columns) || genomic.columns < 2 || genomic.columns > 3) { - warning("Number of columns for genomic position incorrect.") - stop() + logger::log_error("Number of columns for genomic position incorrect.") + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } if (is.null(data.col) || data.col <= genomic.columns) { - warning(paste("Number of input columns must be > ", genomic.columns, ".", sep="")) - stop() + logger::log_error(paste("Number of input columns must be > ", genomic.columns, ".", sep="")) + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } RCircos.Pos <- RCircos::RCircos.Get.Plot.Positions() RCircos.Par <- RCircos::RCircos.Get.Plot.Parameters() @@ -72,8 +72,8 @@ PACVr.Histogram.Plot <- function(hist.data = NULL, min.value <- min(histValues) } else { if (min.value > max.value) { - warning("min.value must be greater than max.value.") - stop() + logger::log_error("min.value must be greater than max.value.") + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } } histHeight <- RCircos::RCircos.Get.Data.Point.Height(histValues, diff --git a/R/coverageCalcOps.R b/R/coverageCalcOps.R index a454ffc1..e7044405 100644 --- a/R/coverageCalcOps.R +++ b/R/coverageCalcOps.R @@ -13,8 +13,8 @@ CovCalc <- function(coverageRaw, # RETURNS: # data.frame with region names, chromosome start, chromosome end and coverage calcucation if (!is.numeric(windowSize) | windowSize < 0) { - warning("User-selected window size must be >= 1.") - stop() + logger::log_error("User-selected window size must be >= 1.") + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } bins <- GenomicRanges::tileGenome( sum(IRanges::runLength(coverageRaw)), diff --git a/R/helpers.R b/R/helpers.R index b89c7ecf..692dbbe9 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -12,8 +12,8 @@ HistCol <- function(cov, threshold, relative, logScale) { # color vector # Error handling if (!is.numeric(threshold) | threshold < 0) { - warning("User-defined coverage depth threshold must be >=1.") - stop() + logger::log_error("User-defined coverage depth threshold must be >=1.") + stop() # Should 'stop()' be replaced with 'return(NULL)' ? } if (relative == TRUE & logScale) { threshold <- mean(cov[, 4]) + log(threshold) diff --git a/R/visualisationOps.R b/R/visualisationOps.R index 2107d8c2..366599e2 100644 --- a/R/visualisationOps.R +++ b/R/visualisationOps.R @@ -216,15 +216,13 @@ createVizFile <- function(plotSpecs) { if (outputType == "pdf") { pdf(output, width=10, - height=10, - units="cm", - res=600) + height=10) } else if (outputType == "png") { png(output, width=10, height=10, - units="cm", - res=600) + units="in", + res=300) } } diff --git a/inst/extdata/PACVr_Rscript.R b/inst/extdata/PACVr_Rscript.R index ff34c3bf..92809eca 100644 --- a/inst/extdata/PACVr_Rscript.R +++ b/inst/extdata/PACVr_Rscript.R @@ -44,7 +44,7 @@ CmdLineArgs <- function() { dest = "threshold", help = "a numeric value that specifies the threshold for plotting coverage depth bars in red as opposed to the default black [default = %default]", metavar = "integer"), - make_option(opt_str = c("-irc","--IRCheck"), + make_option(opt_str = c("-i","--IRCheck"), type = "numeric", default = 1, dest = "IRCheck", @@ -69,10 +69,10 @@ CmdLineArgs <- function() { dest = "textSize", help = "a numeric value that specifies the relative font size of the text element in the visualization [default = %default]", metavar = "integer"), - make_option(opt_str = c("-v","--verbose"), + make_option(opt_str = c("-c","--tabularCovStats"), type = "logical", default = FALSE, - dest = "verbose", + dest = "tabularCovStats", help = paste("a boolean, that when TRUE, generates additional files with", "detailed genomic region information"), metavar = "logical"), @@ -111,7 +111,7 @@ PACVr.complete(gbkFile = opt$gbkFile, IRCheck = opt$IRCheck, relative = opt$relative, textSize = opt$textSize, - verbose = opt$verbose, + tabularCovStats = opt$tabularCovStats, output = opt$output) ######################################################################## diff --git a/inst/extdata/PACVr_run_parallel.R b/inst/extdata/PACVr_run_parallel.R index ab18351c..83401dea 100644 --- a/inst/extdata/PACVr_run_parallel.R +++ b/inst/extdata/PACVr_run_parallel.R @@ -25,29 +25,29 @@ run_PACVr <- function(f) { gbkFile <- paste0(inFileDir, basename(f)) bamFile <- paste0(inFileDir, accNum, "_mapping_OneMoreLocations.sorted.bam") - tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheckFALSE") - #sink(paste0(tmpName, ".log")) - outFile <- paste0(tmpName, ".png") - PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, - threshold=0.5, relative=TRUE, textSize=0.5, - output=outFile) - #sink() +# tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheckFALSE") +# outFile <- paste0(tmpName, ".png") +# PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, +# threshold=0.5, relative=TRUE, textSize=0.5, +# output=outFile) # tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheck0") -# sink(paste0(tmpName, ".log")) # outFile <- paste0(tmpName, ".png") # PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, # threshold=0.5, relative=TRUE, textSize=0.5, # IRCheck=0, output=outFile) -# sink() -# tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheck1") -# sink(paste0(tmpName, ".log")) + tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheck1") + outFile <- paste0(tmpName, ".png") + PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, + threshold=0.5, relative=TRUE, textSize=0.5, + IRCheck=1, output=outFile) + +# tmpName <- paste0(inFileDir, accNum, "_CoverageViz_IRCheck1_withStats") # outFile <- paste0(tmpName, ".png") # PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, # threshold=0.5, relative=TRUE, textSize=0.5, -# IRCheck=1, output=outFile) -# sink() +# IRCheck=1, tabularCovStats=TRUE, output=outFile) } foreach(i=1:length(inFiles), .packages=c("PACVr")) %dopar% { diff --git a/man/PACVr.complete.Rd b/man/PACVr.complete.Rd index 1f8ead4e..96f45749 100644 --- a/man/PACVr.complete.Rd +++ b/man/PACVr.complete.Rd @@ -13,7 +13,7 @@ PACVr.complete( IRCheck = NA, relative = TRUE, textSize = 0.5, - verbose = FALSE, + tabularCovStats = FALSE, output = NA ) } @@ -47,7 +47,7 @@ value of the average coverage instead of an absolute value} \item{textSize}{a numeric value that specifies the relative font size of the text element in the visualization} -\item{verbose}{a boolean, that when TRUE, generates additional files with +\item{tabularCovStats}{a boolean, that when TRUE, generates additional files with detailed genomic region information} \item{output}{a character string that specifies the name of, and path to, @@ -69,7 +69,7 @@ bamFile <- system.file("extdata", "NC_045072/NC_045072_subsampled.bam", package= outFile <- paste(tempdir(), "/NC_045072__all_reads.pdf", sep="") PACVr.complete(gbkFile=gbkFile, bamFile=bamFile, windowSize=250, logScale=FALSE, threshold=0.5, IRCheck=1, relative=TRUE, textSize=0.5, - verbose=FALSE, output=outFile) + tabularCovStats=FALSE, output=outFile) } \dontrun{ gbkFile <- system.file("extdata", "MG936619/MG936619.gb", package="PACVr") @@ -77,6 +77,6 @@ bamFile <- system.file("extdata", "MG936619/MG936619_subsampled.bam", package="P outFile <- paste(tempdir(), "/MG936619_CoverageViz.pdf", sep="") PACVr.complete(gbkFile=gbkFile, bamFile=bamFile, windowSize=50, logScale=FALSE, threshold=0.5, IRCheck=NA, relative=TRUE, textSize=0.5, - verbose=FALSE, output=outFile) + tabularCovStats=FALSE, output=outFile) } } diff --git a/vignettes/PACVr_Vignette.Rnw b/vignettes/PACVr_Vignette.Rnw index 555536cc..13bc5958 100644 --- a/vignettes/PACVr_Vignette.Rnw +++ b/vignettes/PACVr_Vignette.Rnw @@ -72,7 +72,7 @@ outFile <- paste(tempdir(), "/NC_045072_CoverageViz.pdf", sep="") PACVr.complete(gbkFile, bamFile, windowSize=250, logScale=FALSE, threshold=0.5, syntenyLineType=1, relative=TRUE, textSize=0.5, regionsCheck=FALSE, - verbose=FALSE, output=outFile) + tabularCovStats=FALSE, output=outFile) \end{BGVerbatim} \subsection{Via Unix shell} From a5f27b97c1196cf262607a04cd76140746022840 Mon Sep 17 00:00:00 2001 From: michaelgruenstaeudl Date: Wed, 28 Feb 2024 16:10:27 -0600 Subject: [PATCH 2/3] defining correct metavariable for logger --- R/PACVr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/PACVr.R b/R/PACVr.R index af601592..012f61c6 100644 --- a/R/PACVr.R +++ b/R/PACVr.R @@ -132,7 +132,7 @@ PACVr.complete <- function(gbkFile, return(-1) } ################################### - logger <- logger::layout_glue_generator(format='{time} {gbkData$sampleName} -- {level}: {msg}') + logger <- logger::layout_glue_generator(format='{time} {fn} {level}: {msg}') logger::log_layout(logger) ################################### plotSpecs <- getPlotSpecs(logScale, From ff19b9c477d580e35e146a220b9a4d10639cc158 Mon Sep 17 00:00:00 2001 From: michaelgruenstaeudl Date: Wed, 28 Feb 2024 16:21:27 -0600 Subject: [PATCH 3/3] Removing custom logger --- R/PACVr.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/R/PACVr.R b/R/PACVr.R index 012f61c6..abbbbe40 100644 --- a/R/PACVr.R +++ b/R/PACVr.R @@ -132,9 +132,6 @@ PACVr.complete <- function(gbkFile, return(-1) } ################################### - logger <- logger::layout_glue_generator(format='{time} {fn} {level}: {msg}') - logger::log_layout(logger) - ################################### plotSpecs <- getPlotSpecs(logScale, threshold, relative,