From a40cf78f62b4edf527e2f29a281b8e46beeb6449 Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Fri, 1 Apr 2022 00:06:56 +0100 Subject: [PATCH 01/16] - BiocParallel implementation - no resetWorkers arg --- R/peakPantheR_parallelAnnotation.R | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index 5aa8eee..9229368 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -155,21 +155,22 @@ #' @import mzR #' #' @export -peakPantheR_parallelAnnotation <- function(object, ncores = 0, +peakPantheR_parallelAnnotation <- function(object, BPPARAM=NULL, ncores = 0, getAcquTime = TRUE, resetWorkers = 1, centroided = TRUE, curveModel='skewedGaussian', verbose=TRUE, ...){ # Check inputs, Initialise variables and outputs - initRes <- parallelAnnotation_init(object, resetWorkers, verbose) + initRes <- parallelAnnotation_init(object, BPPARAM, ncores, resetWorkers, verbose) file_paths = initRes$file_paths; target_peak_table=initRes$target_peak_table input_FIR = initRes$input_FIR; resetWorkersMulti = initRes$resetWorkersMulti + BPPARAMObject <- initRes$BPPARAMObject stime <- Sys.time() - + # Run singleFileSearch # (list, each item is the result of a file, errors are passed into the list) allFilesRes <- parallelAnnotation_runSingleFileSearch(object, file_paths, - target_peak_table, input_FIR, ncores, getAcquTime, resetWorkersMulti, + target_peak_table, input_FIR, BPPARAM = BPPARAMObject, ncores, getAcquTime, resetWorkersMulti, centroided, curveModel, verbose,...) # Collect, process and reorder results @@ -277,7 +278,7 @@ curveModel='skewedGaussian', inVerbose=TRUE,...){ ## Check inputs, Initialise variables and outputs -parallelAnnotation_init <- function(object, resetWorkers, verbose) { +parallelAnnotation_init <- function(object, BPPARAM, nCores, resetWorkers, verbose) { # check validity of object validObject(object) # check resetWorkers value @@ -288,6 +289,23 @@ parallelAnnotation_init <- function(object, resetWorkers, verbose) { if (resetWorkersMulti < 0) { stop("Check input, resetWorkers must be a positive integer") } + nCores <- as.integer(nCores) + if (nCores < 0) { + stop("Check input, nCores must be a positive integer") + } + + # Handle default BPParams + if (is.null(BPPARAM)) { + if (.Platform$OS.type == 'windows') { + BPPARAM <- BiocParallel::SnowParam(workers = nCores) + } + else { + BPPARAM <- BiocParallel::MulticoreParam(workers = nCores) + } + } + else if (!is(BPPARAM, 'BiocParallelParam')) { + stop("Check input, BPPARAM must be a BiocParallel Param object") + } # Initialise parameters from object use_uROI <- useUROI(object) @@ -316,14 +334,14 @@ parallelAnnotation_init <- function(object, resetWorkers, verbose) { } return(list(file_paths=file_paths, target_peak_table=target_peak_table, - input_FIR=input_FIR, resetWorkersMulti=resetWorkersMulti)) + input_FIR=input_FIR, resetWorkersMulti=resetWorkersMulti, BPPARAMObject=BPPARAM)) } ## Run singleFileSearch # (list, each item is the result of a file, errors are passed into the list) parallelAnnotation_runSingleFileSearch <- function(object, file_paths, -target_peak_table, input_FIR, ncores, getAcquTime, resetWorkersMulti,centroided, +target_peak_table, input_FIR, BPPARAM, ncores, getAcquTime, resetWorkersMulti,centroided, curveModel, verbose,...) { if (ncores != 0) { # Parallel # Reinitialise the cluster after ncores files @@ -355,17 +373,27 @@ curveModel, verbose,...) { centr = centroided, curveModel=curveModel, inVerbose = verbose, ...) parallel::stopCluster(cl) } # Close - } else { # Single cluster init (workload can be balanced across workers) - cl <- parallel::makeCluster(ncores) - doParallel::registerDoParallel(cl) - allFilesRes <- foreach::foreach( # Run - x = file_paths, .packages = c("MSnbase", "mzR"), - .inorder = TRUE) %dopar% parallelAnnotation_parallelHelper(x, - target_peak_table, inFIR=input_FIR, inGetAcquTime=getAcquTime, - centr=centroided, curveModel=curveModel, - inVerbose = verbose,...)#.errorhandling='pass' + + } else { + # Single cluster init (workload can be balanced across workers) + # cl <- parallel::makeCluster(ncores) + BiocParallel::register(BPPARAM) + BiocParallel::bpstart(BPPARAM) + allFilesRes <- BiocParallel::bplapply(X=file_paths, FUN = parallelAnnotation_parallelHelper, + targetFeatTable=input_targetFeatTable, + inGetAcquTime=getAcquTime, inFIR=input_FIR, + centr=centroided, curveModel=curveModel, inVerbose = verbose, + BPPARAM = BPPARAM) + #allFilesRes <- BiocParallel:::foreach( # Run + # x = file_paths, .packages = c("MSnbase", "mzR"), + # .inorder = TRUE) %dopar% parallelAnnotation_parallelHelper(x, + # target_peak_table, inFIR=input_FIR, inGetAcquTime=getAcquTime, + # centr=centroided, curveModel=curveModel, + # inVerbose = verbose,...) + #.errorhandling='pass' # #.export=c('findTargetFeatures', 'getTargetFeatureStatistic') - parallel::stopCluster(cl) } # Close + BiocParallel::bpstop(BPPARAM) + } # Close } else { # Serial allFilesRes <- lapply(file_paths, function(x) parallelAnnotation_parallelHelper(x, target_peak_table, From c1136af3d5d7f4fe8907015a85e53c99ab6691b1 Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Fri, 1 Apr 2022 00:45:19 +0100 Subject: [PATCH 02/16] - BiocParallel implementation - no resetWorkers arg --- R/peakPantheR_parallelAnnotation.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index 9229368..22e9f08 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -380,7 +380,7 @@ curveModel, verbose,...) { BiocParallel::register(BPPARAM) BiocParallel::bpstart(BPPARAM) allFilesRes <- BiocParallel::bplapply(X=file_paths, FUN = parallelAnnotation_parallelHelper, - targetFeatTable=input_targetFeatTable, + targetFeatTable=target_peak_table, inGetAcquTime=getAcquTime, inFIR=input_FIR, centr=centroided, curveModel=curveModel, inVerbose = verbose, BPPARAM = BPPARAM) From b0f25403cbf462a4fc5d1d193bb7488e0f930190 Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Tue, 5 Apr 2022 23:53:07 +0100 Subject: [PATCH 03/16] - BiocParallel implementation: unittest changes --- DESCRIPTION | 3 +- NAMESPACE | 3 +- R/methods_peakPantheRAnnotation.R | 68 +++++----- R/peakPantheR_parallelAnnotation.R | 123 +++++------------- .../test_peakPantheR_parallelAnnotation.R | 120 ++--------------- vignettes/parallel-annotation.Rmd | 29 +++-- vignettes/peakPantheR-GUI.Rmd | 2 +- 7 files changed, 105 insertions(+), 243 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5bcd9fd..7b10a8b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,8 +12,6 @@ Description: An automated pipeline for the detection, integration and reporting Depends: R (>= 4.1) Imports: - foreach (>= 1.4.4), - doParallel (>= 1.0.11), ggplot2 (>= 3.3.0), gridExtra (>= 2.3), MSnbase (>= 2.4.0), @@ -28,6 +26,7 @@ Imports: shinycssloaders (>= 1.0.0), DT (>= 0.15), pracma (>= 2.2.3), + BiocParallel (>= 1.28.3), utils biocViews: MassSpectrometry, Metabolomics, PeakDetection License: GPL-3 diff --git a/NAMESPACE b/NAMESPACE index d9b2515..3742dfd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,8 +49,7 @@ exportMethods(uROIExist) exportMethods(useFIR) exportMethods(useUROI) import(XML) -import(doParallel) -import(foreach) +import(BiocParallel) import(methods) import(mzR) import(scales) diff --git a/R/methods_peakPantheRAnnotation.R b/R/methods_peakPantheRAnnotation.R index 3bf3244..93be072 100644 --- a/R/methods_peakPantheRAnnotation.R +++ b/R/methods_peakPantheRAnnotation.R @@ -1598,7 +1598,7 @@ singleDiagnosticPlots <- function(tmp_annotation,sampleColour,sampling,verbose){ ## fitted compound setGeneric("outputAnnotationDiagnostic", function(object, saveFolder, savePlots = TRUE, sampleColour = NULL, - verbose = TRUE, ncores = 0, ...) + verbose = TRUE, nCores = 1, BPPARAM=NULL, ...) standardGeneric("outputAnnotationDiagnostic")) #' @title Save to disk the annotation parameters as CSV and a diagnostic plot #' per fitted compound @@ -1612,7 +1612,8 @@ setGeneric("outputAnnotationDiagnostic", #' @param savePlots (bool) If TRUE save a diagnostic plot for each compound #' @param sampleColour (str) NULL or vector colour for each sample #' @param verbose (bool) If TRUE message progress -#' @param ncores (int) Number of cores to use to save plots in parallel +#' @param nCores (int) Number of cores to use to save plots in parallel +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object #' @param ... Additional parameters for plotting i.e. \code{sampling} for the #' number of points to employ when plotting fittedCurve #' @return None @@ -1654,7 +1655,7 @@ setGeneric("outputAnnotationDiagnostic", #' verbose=TRUE) #' } setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", - function(object, saveFolder, savePlots, sampleColour, verbose, ncores,...) { + function(object, saveFolder, savePlots, sampleColour, verbose, nCores, BPPARAM, ...) { # Save standardised csv outputAnnotationParamsCSV(object, saveFolder = saveFolder,verbose = verbose) @@ -1665,34 +1666,41 @@ setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", nbCpd <- nbCompounds(object) # run in parallel - if (ncores > 0) { - if (verbose) { - message("Saving ", nbCpd, " diagnostic plots in ", saveFolder) } - - # Open parallel interface - cl <- parallel::makeCluster(ncores) - doParallel::registerDoParallel(cl) - # Run - savedPlots <- foreach::foreach(x = seq_len(nbCpd), - .inorder = TRUE) %dopar% - outputAnnotationDiagnostic_saveSingleMultiPlot(cpdNb = x, - annotation = object, saveFolder = saveFolder, - sampleColour = sampleColour, nbCpd = nbCpd, - verbose = verbose, ...) - # Close - parallel::stopCluster(cl) - if (verbose) { message("All plots saved") } - - # run serial - } else { - if (verbose) { message("Saving diagnostic plots:") } - for (cpd in seq_len(nbCpd)) { - outputAnnotationDiagnostic_saveSingleMultiPlot(cpdNb = cpd, - annotation = object, saveFolder = saveFolder, - sampleColour = sampleColour, nbCpd = nbCpd, - verbose = verbose, ...) - } + nCores <- as.integer(nCores) + if (nCores < 0) { + stop("Check input, nCores must be a positive integer") + } + # Handle default BPParams + if (is.null(BPPARAM)) { + if (nCores > 1) { + if (.Platform$OS.type == 'windows') { + BPPARAM <- BiocParallel::SnowParam(workers = nCores) + } + else { + BPPARAM <- BiocParallel::MulticoreParam(workers = nCores) + } + } else { + BPPARAM <- BiocParallel::SerialParam()} } + else if (!is(BPPARAM, 'BiocParallelParam')) { + stop("Check input, BPPARAM must be a BiocParallel Param object") + } + + if (verbose) { + message("Saving ", nbCpd, " diagnostic plots in ", saveFolder) } + + # Open parallel interface + BiocParallel::register(BPPARAM) + BiocParallel::bpstart(BPPARAM) + # Run + savedPlots <- BiocParallel::bplapply(X=seq_len(nbCpd), FUN = outputAnnotationDiagnostic_saveSingleMultiPlot, + annotation = object, saveFolder = saveFolder, + sampleColour = sampleColour, nbCpd = nbCpd, + verbose = verbose, BPPARAM = BPPARAM) + # Close parallel interface + BiocParallel::bpstop(BPPARAM) + if (verbose) { message("All plots saved") } + } }) # outputAnnotationDiagnostic diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index 22e9f08..e85af1c 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -4,8 +4,8 @@ #' initialised input object and store results. The use of updated ROI and the #' integration of FIR are controled by the input object slots \code{useUROI} and #' \code{useFIR}. Files are processed in parallel using -#' \link{peakPantheR_singleFileSearch}; \code{ncores} controls the number of -#' cores used for parallelisation, with \code{ncores=0} corresponding to serial +#' \link{peakPantheR_singleFileSearch}; \code{nCores} controls the number of +#' cores used for parallelisation, with \code{nCores=1} corresponding to serial #' processing. If the processing of a file fails (file does not exist or error #' during execution) the sample is removed from the outputed object. #' @@ -13,18 +13,10 @@ #' object defining the samples to process and compounds to target. The slots #' \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR #' integrated if a feature is not found -#' @param ncores (int) Number of cores to use for parallelisation. Default 0 for +#' @param nCores (int) Number of cores to use for parallelisation. Default 1 for #' no parallelisation. #' @param getAcquTime (bool) If TRUE will extract sample acquisition date-time #' from the mzML metadata (the additional file access will impact run time) -#' @param resetWorkers (int) If 0, the parallel cluster is only initiated once. -#' If >0 the cluster will be reset (and the memory of each worker freed) once -#' \code{ncores * resetWorkers} files have been processed. Default value is 1, -#' the cluster is reset once \code{ncores} files have been processed. While -#' potentially impacting performance (need to wait until all \code{ncores * -#' resetWorkers} files are processed before restarting the cluster), shutting -#' down the workers processes regularly will ensure the OS can reallocate memory -#' more efficiently. For values >1, ensure sufficient system memory is available #' @param centroided (bool) use TRUE if the data is centroided, used by #' \code{\link[MSnbase]{readMSData}} when reading the raw data files #' @param curveModel (str) specify the peak-shape model to fit, @@ -75,7 +67,7 @@ #' #' # Run serially #' result_parallelAnnotation <- peakPantheR_parallelAnnotation(initAnnotation, -#' ncores=0, +#' nCores=1, #' getAcquTime=FALSE, #' verbose=TRUE) #' # Processing 4 compounds in 3 samples: @@ -155,22 +147,21 @@ #' @import mzR #' #' @export -peakPantheR_parallelAnnotation <- function(object, BPPARAM=NULL, ncores = 0, - getAcquTime = TRUE, resetWorkers = 1, centroided = TRUE, +peakPantheR_parallelAnnotation <- function(object, BPPARAM=NULL, nCores = 1, + getAcquTime = TRUE, centroided = TRUE, curveModel='skewedGaussian', verbose=TRUE, ...){ # Check inputs, Initialise variables and outputs - initRes <- parallelAnnotation_init(object, BPPARAM, ncores, resetWorkers, verbose) + initRes <- parallelAnnotation_init(object, BPPARAM, nCores, verbose) file_paths = initRes$file_paths; target_peak_table=initRes$target_peak_table - input_FIR = initRes$input_FIR; resetWorkersMulti = initRes$resetWorkersMulti - BPPARAMObject <- initRes$BPPARAMObject + input_FIR = initRes$input_FIR; BPPARAMObject <- initRes$BPPARAMObject stime <- Sys.time() # Run singleFileSearch # (list, each item is the result of a file, errors are passed into the list) - allFilesRes <- parallelAnnotation_runSingleFileSearch(object, file_paths, - target_peak_table, input_FIR, BPPARAM = BPPARAMObject, ncores, getAcquTime, resetWorkersMulti, + allFilesRes <- parallelAnnotation_runSingleFileSearch(file_paths, + target_peak_table, input_FIR, BPPARAM = BPPARAMObject, getAcquTime, centroided, curveModel, verbose,...) # Collect, process and reorder results @@ -278,17 +269,10 @@ curveModel='skewedGaussian', inVerbose=TRUE,...){ ## Check inputs, Initialise variables and outputs -parallelAnnotation_init <- function(object, BPPARAM, nCores, resetWorkers, verbose) { +parallelAnnotation_init <- function(object, BPPARAM, nCores, verbose) { # check validity of object validObject(object) - # check resetWorkers value - if (!is.numeric(resetWorkers)) { - stop("Check input, resetWorkers must be an integer") - } - resetWorkersMulti <- as.integer(resetWorkers) - if (resetWorkersMulti < 0) { - stop("Check input, resetWorkers must be a positive integer") - } + nCores <- as.integer(nCores) if (nCores < 0) { stop("Check input, nCores must be a positive integer") @@ -296,12 +280,16 @@ parallelAnnotation_init <- function(object, BPPARAM, nCores, resetWorkers, verbo # Handle default BPParams if (is.null(BPPARAM)) { - if (.Platform$OS.type == 'windows') { + if (nCores > 1) { + if (.Platform$OS.type == 'windows') { BPPARAM <- BiocParallel::SnowParam(workers = nCores) - } - else { + } + else { BPPARAM <- BiocParallel::MulticoreParam(workers = nCores) - } + } + + } else { + BPPARAM <- BiocParallel::SerialParam()} } else if (!is(BPPARAM, 'BiocParallelParam')) { stop("Check input, BPPARAM must be a BiocParallel Param object") @@ -334,73 +322,26 @@ parallelAnnotation_init <- function(object, BPPARAM, nCores, resetWorkers, verbo } return(list(file_paths=file_paths, target_peak_table=target_peak_table, - input_FIR=input_FIR, resetWorkersMulti=resetWorkersMulti, BPPARAMObject=BPPARAM)) + input_FIR=input_FIR, BPPARAMObject=BPPARAM)) } ## Run singleFileSearch # (list, each item is the result of a file, errors are passed into the list) -parallelAnnotation_runSingleFileSearch <- function(object, file_paths, -target_peak_table, input_FIR, BPPARAM, ncores, getAcquTime, resetWorkersMulti,centroided, +parallelAnnotation_runSingleFileSearch <- function(file_paths, +target_peak_table, input_FIR, BPPARAM, getAcquTime, centroided, curveModel, verbose,...) { - if (ncores != 0) { # Parallel - # Reinitialise the cluster after ncores files - # (reset worker processes, freed memory can be reallocated by the OS) - if (resetWorkersMulti != 0) { - # Init - nFiles <- nbSamples(object) - allFilesRes <- vector("list", nFiles) - nFilesPerClust <- (ncores * resetWorkersMulti) - nClust <- ceiling(nFiles/nFilesPerClust) - if (verbose) { message("Running ", nClust, " clusters of ", - nFilesPerClust, " files over ", ncores, " cores:") } - # in each round start a new cluster and store results - for (iClust in seq(0, nClust - 1, 1)) { - if (verbose) { - message(" starting cluster ", iClust + 1, "/", nClust) } - # init - idxStart <- 1 + iClust * nFilesPerClust - idxEnd <- min((nFilesPerClust + iClust * nFilesPerClust),nFiles) - # to not overshoot the number of files - tmp_file_paths <- file_paths[idxStart:idxEnd] - cl <- parallel::makeCluster(ncores) - doParallel::registerDoParallel(cl) - # Run - allFilesRes[idxStart:idxEnd] <- foreach::foreach( - x = tmp_file_paths, .packages = c("MSnbase", "mzR"), - .inorder=TRUE) %dopar% parallelAnnotation_parallelHelper(x, - target_peak_table,inFIR=input_FIR,inGetAcquTime=getAcquTime, - centr = centroided, curveModel=curveModel, - inVerbose = verbose, ...) - parallel::stopCluster(cl) } # Close - } else { - # Single cluster init (workload can be balanced across workers) - # cl <- parallel::makeCluster(ncores) - BiocParallel::register(BPPARAM) - BiocParallel::bpstart(BPPARAM) - allFilesRes <- BiocParallel::bplapply(X=file_paths, FUN = parallelAnnotation_parallelHelper, - targetFeatTable=target_peak_table, - inGetAcquTime=getAcquTime, inFIR=input_FIR, - centr=centroided, curveModel=curveModel, inVerbose = verbose, - BPPARAM = BPPARAM) - #allFilesRes <- BiocParallel:::foreach( # Run - # x = file_paths, .packages = c("MSnbase", "mzR"), - # .inorder = TRUE) %dopar% parallelAnnotation_parallelHelper(x, - # target_peak_table, inFIR=input_FIR, inGetAcquTime=getAcquTime, - # centr=centroided, curveModel=curveModel, - # inVerbose = verbose,...) - #.errorhandling='pass' - # #.export=c('findTargetFeatures', 'getTargetFeatureStatistic') - BiocParallel::bpstop(BPPARAM) - } # Close - } else { # Serial - allFilesRes <- lapply(file_paths, - function(x) parallelAnnotation_parallelHelper(x, target_peak_table, - inFIR=input_FIR, inGetAcquTime=getAcquTime, centr=centroided, - curveModel=curveModel, inVerbose=verbose, ...)) } - return(allFilesRes) } + BiocParallel::register(BPPARAM) + BiocParallel::bpstart(BPPARAM) + allFilesRes <- BiocParallel::bplapply(X=file_paths, FUN = parallelAnnotation_parallelHelper, + targetFeatTable=target_peak_table, + inGetAcquTime=getAcquTime, inFIR=input_FIR, + centr=centroided, curveModel=curveModel, inVerbose = verbose, + BPPARAM = BPPARAM) + BiocParallel::bpstop(BPPARAM) + return(allFilesRes) } ## Collect, process and reorder results parallelAnnotation_process <- function(allFilesRes, object, verbose) { diff --git a/tests/testthat/test_peakPantheR_parallelAnnotation.R b/tests/testthat/test_peakPantheR_parallelAnnotation.R index eed6357..e762409 100644 --- a/tests/testthat/test_peakPantheR_parallelAnnotation.R +++ b/tests/testthat/test_peakPantheR_parallelAnnotation.R @@ -132,7 +132,7 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -165,7 +165,7 @@ test_that('3 files (1 missing), 4 compounds, no uROI, no FIR, no getAcquTime, no expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -222,7 +222,7 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, mo expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE, params=new_params)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE, params=new_params)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -273,7 +273,7 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, pe expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -325,7 +325,7 @@ test_that('3 files, 4 compounds, no uROI, FIR replace peaks not found (cpd #3), expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -358,7 +358,7 @@ test_that('3 files, 4 compounds, uROI, no FIR, no fitGauss, no getAcquTime, no v expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -407,7 +407,7 @@ test_that('serial: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks no expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "----- ko15 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Fit of ROI #3 is unsuccessful (try err)\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "Error file does not exist: aaa/bbb.cdf\n", "----- ko18 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #2\n", "Fit of ROI #3 is unsuccessful (try err)\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #4\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=TRUE, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=TRUE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -418,7 +418,7 @@ test_that('serial: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks no expect_equal(result_parallelAnnotation$messages[c(1:7,9,10,13,14,18:22,24:27,30,31,35,36,37,38,40)], expected_message) }) -test_that('parallel (with cluster reset): 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { +test_that('parallel: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { # sample 2 is missing # Cpd #3 will not give results noMatch_uROI3 <- input_uROI @@ -453,10 +453,10 @@ test_that('parallel (with cluster reset): 3 files, (1 missing), 4 compounds, uRO names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) # Expected message - expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "Running 3 clusters of 1 files over 1 cores:\n", " starting cluster 1/3\n", " starting cluster 2/3\n", " starting cluster 3/3\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") + expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=1, getAcquTime=TRUE, resetWorkers=1, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=SnowParam(1), getAcquTime=TRUE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -467,56 +467,7 @@ test_that('parallel (with cluster reset): 3 files, (1 missing), 4 compounds, uRO expect_equal(result_parallelAnnotation$messages[c(1:11,13)], expected_message) }) -test_that('parallel (without cluster reset): 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { - # sample 2 is missing - # Cpd #3 will not give results - noMatch_uROI3 <- input_uROI - noMatch_uROI3[3,4:6] <- c(52.194778, 52.2, 52.205222) - - # Object fully initialised - initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) - - # Expected annotation - expected_annotation <- initAnnotation[c(1,3),] - expected_annotation@TIC <- c(2410533091, 2332817115) - tmp_peakTables <- expected_peakTables[c(1,3)] - tmp_peakTables[[1]][3,c(2:11,13:16)] <- c(3444.524, 3454.435, 3478.431, 464.1995, 464.20001220703125, 464.2005, 8939889, 8939889, 380736, as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA)) - tmp_peakTables[[1]]$is_filled[3] <- TRUE - tmp_peakTables[[2]][3,c(2:11,13:16)] <- c(3444.524, 3460.696, 3478.431, 464.1995, 464.20001220703125, 464.2005, 7414831, 7414831, 319488, as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA)) - tmp_peakTables[[2]]$found[3] <- TRUE - tmp_peakTables[[2]]$is_filled[3] <- TRUE - expected_annotation@peakTables <- tmp_peakTables - tmp_peakFit <- expected_peakFit[c(1,3)] - tmp_peakFit[[1]][[3]] <- NA - tmp_peakFit[[2]][[3]] <- NA - expected_annotation@peakFit <- tmp_peakFit - tmp_dataPoints <- expected_dataPoints[c(1,3)] - tmp_dataPoints[[1]][[3]] <- data.frame(rt=numeric(), mz=numeric(), int=numeric()) - tmp_dataPoints[[2]][[3]] <- data.frame(rt=numeric(), mz=numeric(), int=numeric()) - expected_annotation@dataPoints <- tmp_dataPoints - expected_annotation@isAnnotated <- TRUE - # Expected failures - tmp_status <- 'Error file does not exist: aaa/bbb.cdf' - names(tmp_status) <- 'aaa/bbb.cdf' - tmp_failures <- !is.na(tmp_status) - names(tmp_failures) <- NULL - expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") - - # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=1, getAcquTime=TRUE, resetWorkers=0, verbose=TRUE)) - - # Check results - expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) - expect_equal(result_parallelAnnotation$result$failures, expected_failures) - - # Check messages (no timing) - expect_equal(length(result_parallelAnnotation$messages), 9) - expect_equal(result_parallelAnnotation$messages[c(1:7,9)], expected_message) -}) - -test_that('serial and parallel (with cluster reset) give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { +test_that('serial and parallel give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { # sample 2 is missing # Cpd #3 will not give results noMatch_uROI3 <- input_uROI @@ -550,55 +501,6 @@ test_that('serial and parallel (without cluster reset) give the same result: 3 f expect_equal(result_serial$result, result_parallel$result, tolerance=1e-6) }) -test_that('change to resetWorkers alters the number of parallel cluster reset', { - # sample 2 is missing - # Cpd #3 will not give results - noMatch_uROI3 <- input_uROI - noMatch_uROI3[3,4:6] <- c(52.194778, 52.2, 52.205222) - - # Object fully initialised - initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) - - # Expected annotation - expected_annotation <- initAnnotation[c(1,3),] - expected_annotation@TIC <- c(2410533091, 2332817115) - tmp_peakTables <- expected_peakTables[c(1,3)] - tmp_peakTables[[1]][3,c(2:11,13:16)] <- c(3444.524, 3454.435, 3478.431, 464.1995, 464.20001220703125, 464.2005, 8939889, 8939889, 380736, as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA)) - tmp_peakTables[[1]]$is_filled[3] <- TRUE - tmp_peakTables[[2]][3,c(2:11,13:16)] <- c(3444.524, 3460.696, 3478.431, 464.1995, 464.20001220703125, 464.2005, 7414831, 7414831, 319488, as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA), as.numeric(NA)) - tmp_peakTables[[2]]$found[3] <- TRUE - tmp_peakTables[[2]]$is_filled[3] <- TRUE - expected_annotation@peakTables <- tmp_peakTables - tmp_peakFit <- expected_peakFit[c(1,3)] - tmp_peakFit[[1]][[3]] <- NA - tmp_peakFit[[2]][[3]] <- NA - expected_annotation@peakFit <- tmp_peakFit - tmp_dataPoints <- expected_dataPoints[c(1,3)] - tmp_dataPoints[[1]][[3]] <- data.frame(rt=numeric(), mz=numeric(), int=numeric()) - tmp_dataPoints[[2]][[3]] <- data.frame(rt=numeric(), mz=numeric(), int=numeric()) - expected_annotation@dataPoints <- tmp_dataPoints - expected_annotation@isAnnotated <- TRUE - # Expected failures - tmp_status <- 'Error file does not exist: aaa/bbb.cdf' - names(tmp_status) <- 'aaa/bbb.cdf' - tmp_failures <- !is.na(tmp_status) - names(tmp_failures) <- NULL - expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "Running 2 clusters of 2 files over 1 cores:\n", " starting cluster 1/2\n", " starting cluster 2/2\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") - - # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=1, getAcquTime=TRUE, resetWorkers=2, verbose=TRUE)) - - # Check results - expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) - expect_equal(result_parallelAnnotation$result$failures, expected_failures) - - # Check messages (no timing) - expect_equal(length(result_parallelAnnotation$messages), 12) - expect_equal(result_parallelAnnotation$messages[c(1:10,12)], expected_message) -}) - test_that('already annotated message in verbose', { # use "serial: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose" diff --git a/vignettes/parallel-annotation.Rmd b/vignettes/parallel-annotation.Rmd index 4f16d6c..c99abb5 100644 --- a/vignettes/parallel-annotation.Rmd +++ b/vignettes/parallel-annotation.Rmd @@ -1,6 +1,6 @@ --- title: "Parallel Annotation" -date: "2020-10-11" +date: "2022-04-1" package: peakPantheR output: BiocStyle::html_document: @@ -9,7 +9,7 @@ vignette: > %\VignetteIndexEntry{Parallel Annotation} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} - %\VignetteDepends{peakPantheR,faahKO,pander,BiocStyle,foreach,doParallel} + %\VignetteDepends{peakPantheR,faahKO,pander,BiocStyle,BiocParallel} %\VignettePackage{peakPantheR} %\VignetteKeywords{mass spectrometry, metabolomics} --- @@ -33,8 +33,7 @@ library(BiocStyle) library(peakPantheR) library(faahKO) library(pander) -library(doParallel) -library(foreach) +library(BiocParallel) ``` # Introduction @@ -215,11 +214,11 @@ init_annotation ``` `peakPantheR_parallelAnnotation()` will run the annotation across files in -parallel (if `ncores` >0) and return the successful annotations +parallel (if `nCores` > 1) and return the successful annotations (`result$annotation`) and failures (`result$failures`): ```{r} # annotate files serially -annotation_result <- peakPantheR_parallelAnnotation(init_annotation, ncores=0, +annotation_result <- peakPantheR_parallelAnnotation(init_annotation, nCores=1, curveModel='skewedGaussian', verbose=TRUE) @@ -232,6 +231,20 @@ data_annotation annotation_result$failures ``` +`peakPantheR_parallelAnnotation()` will run the annotation across files in +parallel (if `nCores` > 1) and return the successful annotations +(`result$annotation`) and failures (`result$failures`): +```{r} +# annotate files in parallel using two workers +annotation_result <- peakPantheR_parallelAnnotation(init_annotation, nCores=2, + curveModel='skewedGaussian', + verbose=TRUE) + +# successful fit +nbSamples(annotation_result$annotation) +data_annotation <- annotation_result$annotation +data_annotation +``` ## Process Parallel Annotation Results @@ -254,7 +267,7 @@ updated_annotation `annotationParameters_summary.csv` containing the original `ROI` and newly determined `uROI` and `FIR` for manual validation. Additionnaly a diagnostic plot for each compound is saved for reference and can be generated in parallel -with the argument `ncores`: +with the argument `nCores`: ```{r, eval=FALSE} # create a colourScale based on the sampleType uniq_sType <- sort(unique(spectraMetadata(updated_annotation)$sampleType), @@ -269,7 +282,7 @@ output_folder <- tempdir() # output fit diagnostic to disk outputAnnotationDiagnostic(updated_annotation, saveFolder=output_folder, savePlots=TRUE, sampleColour=col_sType, - verbose=TRUE, ncores=2) + verbose=TRUE, nCores=2) ``` The data saved in `annotationParameters_summary.csv` is as follow: diff --git a/vignettes/peakPantheR-GUI.Rmd b/vignettes/peakPantheR-GUI.Rmd index 7d795cb..87fe2d1 100644 --- a/vignettes/peakPantheR-GUI.Rmd +++ b/vignettes/peakPantheR-GUI.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteIndexEntry{peakPantheR Graphical User Interface} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} - %\VignetteDepends{peakPantheR,faahKO,pander,BiocStyle,foreach,doParallel} + %\VignetteDepends{peakPantheR,faahKO,pander,BiocStyle,BiocParallel} %\VignettePackage{peakPantheR} %\VignetteKeywords{mass spectrometry, metabolomics} --- From bb4647fb73a8fab510643ca1cb344220253ed79c Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Wed, 6 Apr 2022 13:02:00 +0100 Subject: [PATCH 04/16] - BiocParallel implementation: unittest changes --- R/methods_peakPantheRAnnotation.R | 2 +- R/peakPantheR_ROIStatistics.R | 17 ++--- R/peakPantheR_parallelAnnotation.R | 4 +- ...tation_outputAnnotationDiagnostic-method.R | 31 ++++---- .../testthat/test_peakPantheR_ROIStatistics.R | 51 +++++++------ .../test_peakPantheR_parallelAnnotation.R | 72 +++++++++---------- 6 files changed, 91 insertions(+), 86 deletions(-) diff --git a/R/methods_peakPantheRAnnotation.R b/R/methods_peakPantheRAnnotation.R index 93be072..fb2ca09 100644 --- a/R/methods_peakPantheRAnnotation.R +++ b/R/methods_peakPantheRAnnotation.R @@ -1696,7 +1696,7 @@ setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", savedPlots <- BiocParallel::bplapply(X=seq_len(nbCpd), FUN = outputAnnotationDiagnostic_saveSingleMultiPlot, annotation = object, saveFolder = saveFolder, sampleColour = sampleColour, nbCpd = nbCpd, - verbose = verbose, BPPARAM = BPPARAM) + verbose = verbose, BPPARAM = BPPARAM, ...) # Close parallel interface BiocParallel::bpstop(BPPARAM) if (verbose) { message("All plots saved") } diff --git a/R/peakPantheR_ROIStatistics.R b/R/peakPantheR_ROIStatistics.R index 5e479d0..79e29f1 100644 --- a/R/peakPantheR_ROIStatistics.R +++ b/R/peakPantheR_ROIStatistics.R @@ -17,7 +17,8 @@ #' (float), \code{mz} (float or \emph{NA}), \code{mzMax} (float) (if NULL IS #' mean RT is not calculated and saved in \code{IS_mean_RT.csv}) #' @param sampleColour (str) NULL or vector colour for each sample -#' @param ncores (int) Number of cores to use to integrate IS in parallel +#' @param nCores (int) Number of cores to use to integrate IS in parallel +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object #' @param saveISPlots (bool) If TRUE save a diagnostic plot for each IS to #' \code{saveFolder/IS_search} compound #' @param verbose (bool) If TRUE message progress @@ -54,12 +55,12 @@ #' # Calculate ROI statiscs #' peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, #' IS_ROI=input_IS_ROI, sampleColour=sampleColour, -#' ncores=0, saveISPlots=TRUE, verbose=TRUE) +#' nCores=0, saveISPlots=TRUE, verbose=TRUE) #' } peakPantheR_ROIStatistics <- function(referenceSpectraFiles, saveFolder, ROI = NULL, IS_ROI = NULL, - sampleColour = NULL, ncores = 0, - saveISPlots = TRUE, verbose = TRUE) { + sampleColour = NULL, nCores = 1, + saveISPlots = TRUE, verbose = TRUE, BPPARAM=NULL) { # Check and process input parameters resInit <- ROIStatistics_init_checks(referenceSpectraFiles, saveFolder, ROI, IS_ROI, sampleColour, verbose) @@ -77,7 +78,7 @@ peakPantheR_ROIStatistics <- function(referenceSpectraFiles, saveFolder, # calculate mean IS for each RT if (calculateMeanISRT) { ROIStatistics_calculateMeanISRT(referenceSpectraFiles, saveFolder, - IS_ROI, saveISPlots, ncores, sampleColour, verbose) + IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM) } } @@ -239,7 +240,7 @@ ROIStatistics_saveEICsROI <- function(referenceSpectraFiles, saveFolder, ROI, } # Calculate mean RT for each IS ROIStatistics_calculateMeanISRT <- function(referenceSpectraFiles, saveFolder, - IS_ROI, saveISPlots, ncores, sampleColour, verbose){ + IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM){ if (verbose) { message("\n-- Calculating mean RT for each IS --") } @@ -247,7 +248,7 @@ ROIStatistics_calculateMeanISRT <- function(referenceSpectraFiles, saveFolder, spectraPaths = referenceSpectraFiles, targetFeatTable = IS_ROI) IS_annotation_results <- peakPantheR_parallelAnnotation(IS_annotation, - ncores = ncores, verbose = verbose) + nCores = nCores, verbose = verbose, BPPARAM=BPPARAM) IS_annotation <- IS_annotation_results$annotation # save IS fit diagnostic plots @@ -255,7 +256,7 @@ ROIStatistics_calculateMeanISRT <- function(referenceSpectraFiles, saveFolder, outputAnnotationDiagnostic(IS_annotation, saveFolder = file.path(saveFolder, "IS_search"), savePlots = TRUE, sampleColour=sampleColour, verbose = verbose, - ncores = ncores) + nCores = nCores) } # calculate statistics diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index e85af1c..8c44296 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -330,7 +330,7 @@ parallelAnnotation_init <- function(object, BPPARAM, nCores, verbose) { # (list, each item is the result of a file, errors are passed into the list) parallelAnnotation_runSingleFileSearch <- function(file_paths, target_peak_table, input_FIR, BPPARAM, getAcquTime, centroided, -curveModel, verbose,...) { +curveModel, verbose, ...) { BiocParallel::register(BPPARAM) BiocParallel::bpstart(BPPARAM) @@ -338,7 +338,7 @@ curveModel, verbose,...) { targetFeatTable=target_peak_table, inGetAcquTime=getAcquTime, inFIR=input_FIR, centr=centroided, curveModel=curveModel, inVerbose = verbose, - BPPARAM = BPPARAM) + BPPARAM = BPPARAM, ...) BiocParallel::bpstop(BPPARAM) return(allFilesRes) } diff --git a/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R b/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R index 68061a3..4862a99 100644 --- a/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R +++ b/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R @@ -116,7 +116,8 @@ test_that('default output, with plots and colours, serial, verbose, no verbose', expected_CSV[,-c(1,2,3,10,17)] <- sapply(expected_CSV[,-c(1,2,3,10,17)], as.numeric) # results (output, warnings and messages) - result_save <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath1, savePlots=TRUE, sampleColour=input_colour, verbose=TRUE, ncores=0)) + result_save <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath1, + savePlots=TRUE, sampleColour=input_colour, verbose=TRUE, nCores=1)) # Check CSV has been produced expect_true(file.exists(expected_path_CSV)) @@ -127,16 +128,17 @@ test_that('default output, with plots and colours, serial, verbose, no verbose', # Check values saved saved_CSV <- read.csv(expected_path_CSV, header=TRUE, sep=",", quote="\"", stringsAsFactors=FALSE) expect_equal(saved_CSV, expected_CSV) - + # Check result messages (save path) - expect_equal(length(result_save$messages), 4) + expect_equal(length(result_save$messages), 5) ## no verbose savePath2 <- tempdir() # clear temp folder suppressWarnings(do.call(file.remove, list(list.files(savePath2, full.names = TRUE)))) - result_save2 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath2, savePlots=TRUE, sampleColour=input_colour, verbose=FALSE, ncores=0) + result_save2 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath2, savePlots=TRUE, + sampleColour=input_colour, verbose=FALSE, nCores=1) ) expect_equal(length(result_save2$messages), 0) }) @@ -161,7 +163,9 @@ test_that('default output, with plots and colours, parallel, verbose, no verbose expected_CSV[,-c(1,2,3,10,17)] <- sapply(expected_CSV[,-c(1,2,3,10,17)], as.numeric) # results (output, warnings and messages) - result_save3 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath3, savePlots=TRUE, sampleColour=input_colour, verbose=TRUE, ncores=1)) + BPParam <- BiocParallel::SnowParam(1) + result_save3 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath3, savePlots=TRUE, sampleColour=input_colour, + verbose=TRUE, nCores=1, BPPARAM=BPParam)) # Check CSV has been produced expect_true(file.exists(expected_path_CSV)) @@ -174,14 +178,15 @@ test_that('default output, with plots and colours, parallel, verbose, no verbose expect_equal(saved_CSV, expected_CSV) # Check result messages (save path) - expect_equal(length(result_save3$messages), 3) + expect_equal(length(result_save3$messages), 4) ## no verbose savePath4 <- tempdir() # clear temp folder suppressWarnings(do.call(file.remove, list(list.files(savePath4, full.names = TRUE)))) - result_save4 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath4, savePlots=TRUE, sampleColour=input_colour, verbose=FALSE, ncores=1) + result_save4 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath4, savePlots=TRUE, + sampleColour=input_colour, verbose=FALSE, nCores=1, BPPARAM=BPParam) ) expect_equal(length(result_save4$messages), 0) }) @@ -239,10 +244,10 @@ test_that('no data to plot, serial, verbose', { expected_CSV[2,] <- c('ID-2', 'Cpd 2', '|', 3385.577, 496.2, 3280., 3440., 496.195038, 496.204962, '|', NA, NA, NA, NA, NA, NA, '|', NA, NA, NA, NA) expected_CSV[,-c(1,2,3,10:21)] <- sapply(expected_CSV[,-c(1,2,3,10:21)], as.numeric) expected_CSV[,c(11:16, 18:21)] <- sapply(expected_CSV[,c(11:16, 18:21)], as.logical) - expected_message <- c("Saving diagnostic plots:\n", "Warning: the object has not been annotated, return an empty diagnostic plot list\n", " No plot to save for compound 1/2\n", "Warning: the object has not been annotated, return an empty diagnostic plot list\n", " No plot to save for compound 2/2\n" ) + expected_message <- c("Warning: the object has not been annotated, return an empty diagnostic plot list\n", " No plot to save for compound 1/2\n", "Warning: the object has not been annotated, return an empty diagnostic plot list\n", " No plot to save for compound 2/2\n", "All plots saved\n") # results (output, warnings and messages) - result_save6 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath6, savePlots=TRUE, verbose=TRUE, ncores=0)) + result_save6 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath6, savePlots=TRUE, verbose=TRUE, nCores=1)) # Check CSV has been produced expect_true(file.exists(expected_path_CSV)) @@ -255,8 +260,8 @@ test_that('no data to plot, serial, verbose', { expect_equal(saved_CSV, expected_CSV) # Check result messages (without save path) - expect_equal(length(result_save6$messages), 6) - expect_equal(result_save6$messages[2:6], expected_message) + expect_equal(length(result_save6$messages), 7) + expect_equal(result_save6$messages[3:7], expected_message) }) test_that('no data to plot, parallel, verbose', { @@ -281,7 +286,7 @@ test_that('no data to plot, parallel, verbose', { expected_CSV[,c(11:16, 18:21)] <- sapply(expected_CSV[,c(11:16, 18:21)], as.logical) # results (output, warnings and messages) - result_save7 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath7, savePlots=TRUE, verbose=TRUE, ncores=1)) + result_save7 <- evaluate_promise(outputAnnotationDiagnostic(input_annotation, saveFolder=savePath7, savePlots=TRUE, verbose=TRUE, nCores=1)) # Check CSV has been produced expect_true(file.exists(expected_path_CSV)) @@ -294,5 +299,5 @@ test_that('no data to plot, parallel, verbose', { expect_equal(saved_CSV, expected_CSV) # Check result messages (without save path) - expect_equal(length(result_save7$messages), 3) + expect_equal(length(result_save7$messages), 7) }) diff --git a/tests/testthat/test_peakPantheR_ROIStatistics.R b/tests/testthat/test_peakPantheR_ROIStatistics.R index b5f07b7..4de00fd 100644 --- a/tests/testthat/test_peakPantheR_ROIStatistics.R +++ b/tests/testthat/test_peakPantheR_ROIStatistics.R @@ -52,11 +52,11 @@ test_that('3 files, save EICS, mean IS RT, save IS fit, with sampleColour, verbo expected_meanIS[4,] <- c('ID-4', 3712.859261) expected_meanIS[,2] <- vapply(expected_meanIS[,2], as.numeric, FUN.VALUE=numeric(1)) # Expected message - expected_message <- c(" 4 ROI in 3 reference samples\n", " 4 IS in 3 reference samples\n", "\n-- Saving EICs for each ROI --\n","Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "\n-- Calculating mean RT for each IS --\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "----- ko15 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #3\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 0 failure(s)\n", "Saving diagnostic plots:\n") + expected_message <- c(" 4 ROI in 3 reference samples\n", " 4 IS in 3 reference samples\n", "\n-- Saving EICs for each ROI --\n","Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n", "\n-- Calculating mean RT for each IS --\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "----- ko15 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #3\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 0 failure(s)\n") # results (output, warnings and messages) - result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=0, saveISPlots=TRUE, verbose=TRUE)) + result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, nCores=1, saveISPlots=TRUE, verbose=TRUE)) # Check saved EIC plots expect_true(file.exists(expected_path_plot1)) @@ -74,11 +74,11 @@ test_that('3 files, save EICS, mean IS RT, save IS fit, with sampleColour, verbo expect_equal(saved_CSV, expected_meanIS, tolerance=1e-4) # Check messages (no filepaths) - expect_equal(length(result_ROIstatsV$messages), 64) - expect_equal(result_ROIstatsV$messages[c(2, 4:7, 9:10, 12:13, 16:23, 25:26, 54:55, 57, 59)], expected_message) + expect_equal(length(result_ROIstatsV$messages), 65) + expect_equal(result_ROIstatsV$messages[c(2, 4:7, 9:10, 12:13, 16:23, 25:26, 54:55, 57)], expected_message) # no verbose - result_ROIstatsNoV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=0, saveISPlots=TRUE, verbose=FALSE)) + result_ROIstatsNoV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, nCores=1, saveISPlots=TRUE, verbose=FALSE)) expect_equal(length(result_ROIstatsNoV$messages), 6) }) @@ -107,7 +107,7 @@ test_that('3 files (1 missing), save EICs, no IS RT, no IS fit, sampleColour is expected_message <- c("Check input, \"sampleColour\" must be a vector of colour of same length as \"referenceSpectraFile\": default colour used instead\n", "No IS_ROI provided, mean RT of IS will not be calculated\n", " 4 ROI in 3 reference samples\n", "- Mean RT of IS will not be calculated\n", "\n-- Saving EICs for each ROI --\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Reading data from 4 windows\n") # results (output, warnings and messages) - result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder2, ROI=input_ROI, IS_ROI=NULL, sampleColour=sampleColour, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder2, ROI=input_ROI, IS_ROI=NULL, sampleColour=sampleColour, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check saved EIC plots expect_true(file.exists(expected_path_plot1)) @@ -145,7 +145,7 @@ test_that('3 files, no save EICs, mean IS RT, no IS fit, without sampleColour, v # results (output, warnings and messages) - result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder3, ROI=NULL, IS_ROI=input_IS_ROI, sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder3, ROI=NULL, IS_ROI=input_IS_ROI, sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check mean IS RT expect_true(file.exists(expected_path_CSV)) @@ -175,7 +175,7 @@ test_that('3 files, no save EICs (not a data.frame), no mean IS RT (not a data.f # results (output, warnings and messages) - result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder4, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=42, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsV <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder4, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=42, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsV$messages), 5) @@ -200,56 +200,56 @@ test_that('3 files, no save EICs (wrong columns), no mean IS RT (wrong columns), ## no cpdID # results (output, warnings and messages) - result_ROIstatsNoCpdID <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-1], IS_ROI=input_IS_ROI[,-1], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoCpdID <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-1], IS_ROI=input_IS_ROI[,-1], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoCpdID$messages), 4) expect_equal(result_ROIstatsNoCpdID$messages, expected_message) ## no cpdName # results (output, warnings and messages) - result_ROIstatsNoCpdName <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-2], IS_ROI=input_IS_ROI[,-2], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoCpdName <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-2], IS_ROI=input_IS_ROI[,-2], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoCpdName$messages), 4) expect_equal(result_ROIstatsNoCpdName$messages, expected_message) ## no rtMin # results (output, warnings and messages) - result_ROIstatsNoRtMin <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-3], IS_ROI=input_IS_ROI[,-3], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoRtMin <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-3], IS_ROI=input_IS_ROI[,-3], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoRtMin$messages), 4) expect_equal(result_ROIstatsNoRtMin$messages, expected_message) ## no rt # results (output, warnings and messages) - result_ROIstatsNoRt <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-4], IS_ROI=input_IS_ROI[,-4], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoRt <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-4], IS_ROI=input_IS_ROI[,-4], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoRt$messages), 4) expect_equal(result_ROIstatsNoRt$messages, expected_message) ## no rtMax # results (output, warnings and messages) - result_ROIstatsNoRtMax <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-5], IS_ROI=input_IS_ROI[,-5], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoRtMax <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-5], IS_ROI=input_IS_ROI[,-5], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoRtMax$messages), 4) expect_equal(result_ROIstatsNoRtMax$messages, expected_message) ## no mzMin # results (output, warnings and messages) - result_ROIstatsNoMzMin <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-6], IS_ROI=input_IS_ROI[,-6], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoMzMin <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-6], IS_ROI=input_IS_ROI[,-6], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoMzMin$messages), 4) expect_equal(result_ROIstatsNoMzMin$messages, expected_message) ## no mz # results (output, warnings and messages) - result_ROIstatsNoMz <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-7], IS_ROI=input_IS_ROI[,-7], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoMz <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-7], IS_ROI=input_IS_ROI[,-7], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoMz$messages), 4) expect_equal(result_ROIstatsNoMz$messages, expected_message) ## no mzMax # results (output, warnings and messages) - result_ROIstatsNoMzMax <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-8], IS_ROI=input_IS_ROI[,-8], sampleColour=NULL, ncores=0, saveISPlots=FALSE, verbose=TRUE)) + result_ROIstatsNoMzMax <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder5, ROI=input_ROI[,-8], IS_ROI=input_IS_ROI[,-8], sampleColour=NULL, nCores=1, saveISPlots=FALSE, verbose=TRUE)) # Check messages expect_equal(length(result_ROIstatsNoMzMax$messages), 4) expect_equal(result_ROIstatsNoMzMax$messages, expected_message) @@ -282,11 +282,16 @@ test_that('parallel give the same result: 3 files, no save EICs, mean IS RT, sav expected_path_IS_plot3 <- file.path(saveFolder6,"IS_search", "cpd_3.png") expected_path_IS_plot4 <- file.path(saveFolder6,"IS_search", "cpd_4.png") # Expected message - expected_message_parallel <- c("No ROI provided, EICs of ROI windows will not be saved\n", "- EICs of ROI windows will not be saved\n", " 4 IS in 3 reference samples\n", "\n-- Calculating mean RT for each IS --\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "Running 3 clusters of 1 files over 1 cores:\n", " starting cluster 1/3\n", " starting cluster 2/3\n", " starting cluster 3/3\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 0 failure(s)\n", "All plots saved\n") + expected_message_parallel <- c("No ROI provided, EICs of ROI windows will not be saved\n", "- EICs of ROI windows will not be saved\n", " 4 IS in 3 reference samples\n", "\n-- Calculating mean RT for each IS --\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 0 failure(s)\n", "All plots saved\n") # results (output, warnings and messages) - result_ROIstats_parallel <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder6, ROI=NULL, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=1, saveISPlots=TRUE, verbose=TRUE)) + if (.Platform$OS.type == "windows") { + BPParam <- BiocParallel::SnowParam(1) + } else {BPParam <- BiocParallel::MulticoreParam(1) } + result_ROIstats_parallel <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder6, ROI=NULL, IS_ROI=input_IS_ROI, + sampleColour=sampleColour, nCores=1, BPPARAM=BPParam, + saveISPlots=TRUE, verbose=TRUE)) # Check saved IS fit expect_true(file.exists(expected_path_IS_plot1)) @@ -297,10 +302,9 @@ test_that('parallel give the same result: 3 files, no save EICs, mean IS RT, sav expect_true(file.exists(expected_path_CSV)) saved_CSV <- read.csv(expected_path_CSV, header=TRUE, sep=",", quote="\"", stringsAsFactors=FALSE) expect_equal(saved_CSV, expected_meanIS, tolerance=1e-4) - # Check messages (no filepaths) expect_equal(length(result_ROIstats_parallel$messages), 20) - expect_equal(result_ROIstats_parallel$messages[c(1,2,4:14,16,19)], expected_message_parallel) + expect_equal(result_ROIstats_parallel$messages[c(1,2,4:10,12,19)], expected_message_parallel) }) test_that('raise errors', { @@ -315,13 +319,14 @@ test_that('raise errors', { # referenceSpectraFiles is not a character vector error_msg1 <- 'Check input, "referenceSpectraFiles" must be a vector of spectra paths' - expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=42, saveFolder8, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=0, saveISPlots=TRUE, verbose=TRUE), error_msg1, fixed=TRUE) + expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=42, saveFolder8, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, nCores=1, saveISPlots=TRUE, verbose=TRUE), error_msg1, fixed=TRUE) # saveFolder is not a character error_msg2 <- 'Check input, "saveFolder" must be a path' - expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=refSpecFiles, saveFolder=42 , ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=0, saveISPlots=TRUE, verbose=TRUE), error_msg2, fixed=TRUE) + expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=refSpecFiles, saveFolder=42 , ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, nCores=1, saveISPlots=TRUE, verbose=TRUE), error_msg2, fixed=TRUE) # saveFolder is not of length 1 error_msg3 <- 'Check input, "saveFolder" must be a path' - expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=refSpecFiles, saveFolder=c('onePath','anotherPath','morePath') , ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, ncores=0, saveISPlots=TRUE, verbose=TRUE), error_msg3, fixed=TRUE) + expect_error(peakPantheR_ROIStatistics(referenceSpectraFiles=refSpecFiles, saveFolder=c('onePath','anotherPath','morePath') , ROI=input_ROI, IS_ROI=input_IS_ROI, + sampleColour=sampleColour, nCores=1, saveISPlots=TRUE, verbose=TRUE), error_msg3, fixed=TRUE) }) diff --git a/tests/testthat/test_peakPantheR_parallelAnnotation.R b/tests/testthat/test_peakPantheR_parallelAnnotation.R index e762409..1249a2e 100644 --- a/tests/testthat/test_peakPantheR_parallelAnnotation.R +++ b/tests/testthat/test_peakPantheR_parallelAnnotation.R @@ -114,7 +114,7 @@ if ((.Platform$OS.type != "windows") || (.Machine$sizeof.pointer == 8)) { test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { # Object fully initialised initAnnotation <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) - + # Expected annotation expected_annotation <- initAnnotation expected_annotation@TIC <- c(2410533091, 2524040155, 2332817115) @@ -155,6 +155,7 @@ test_that('3 files (1 missing), 4 compounds, no uROI, no FIR, no getAcquTime, no expected_annotation@peakFit <- expected_peakFit[c(1,3)] expected_annotation@dataPoints <- expected_dataPoints[c(1,3)] expected_annotation@isAnnotated <- TRUE + # Expected failures tmp_status <- 'Error file does not exist: aaa/bbb.cdf' names(tmp_status) <- 'aaa/bbb.cdf' @@ -180,7 +181,7 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, mo # Cpd 3 is now found in 3rd file # Object fully initialised initAnnotation <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) - + # Modify fit of window #3 tmp_params <- list(init_params = list(amplitude=1E5, center=3455., sigma=0.1, gamma=0), lower_bounds = list(amplitude=0, center=3450., sigma=0, gamma=-0.1), @@ -453,18 +454,22 @@ test_that('parallel: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) # Expected message - expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") - + expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", + "----------------\n" , "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") + + if (.Platform$OS.type == "windows") { + BPParam <- BiocParallel::SnowParam(1) + } else {BPParam <- BiocParallel::MulticoreParam(1) } # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=SnowParam(1), getAcquTime=TRUE, verbose=TRUE)) - + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=BPParam, getAcquTime=TRUE, verbose=TRUE)) + # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) expect_equal(result_parallelAnnotation$result$failures, expected_failures) # Check messages (no timing) - expect_equal(length(result_parallelAnnotation$messages), 13) - expect_equal(result_parallelAnnotation$messages[c(1:11,13)], expected_message) + expect_equal(length(result_parallelAnnotation$messages), 9) + expect_equal(result_parallelAnnotation$messages[c(1:7, 9)], expected_message) }) test_that('serial and parallel give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { @@ -477,26 +482,14 @@ test_that('serial and parallel give the same result: 3 files, (1 missing), 4 co initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) # results - result_serial <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=TRUE, verbose=TRUE)) - result_parallel <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=1, getAcquTime=TRUE, resetWorkers=1, verbose=TRUE)) + result_serial <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=TRUE, verbose=TRUE)) - # Check results - expect_equal(result_serial$result, result_parallel$result, tolerance=1e-6) -}) + if (.Platform$OS.type == "windows") { + BPParam <- BiocParallel::SnowParam(1) + } else {BPParam <- BiocParallel::MulticoreParam(1) } + result_parallel <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=BPParam, + getAcquTime=TRUE, verbose=TRUE)) -test_that('serial and parallel (without cluster reset) give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { - # sample 2 is missing - # Cpd #3 will not give results - noMatch_uROI3 <- input_uROI - noMatch_uROI3[3,4:6] <- c(52.194778, 52.2, 52.205222) - - # Object fully initialised - initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) - - # results - result_serial <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=TRUE, verbose=TRUE)) - result_parallel <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=1, getAcquTime=TRUE, resetWorkers=0, verbose=TRUE)) - # Check results expect_equal(result_serial$result, result_parallel$result, tolerance=1e-6) }) @@ -510,7 +503,8 @@ test_that('already annotated message in verbose', { noMatch_uROI3[3,4:6] <- c(52.194778, 52.2, 52.205222) # Object fully initialised - initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, isAnnotated=TRUE, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) + initAnnotation <- peakPantheRAnnotation(spectraPaths=input_missingSpectraPaths, targetFeatTable=input_badtargetFeatTable, uROIExist=TRUE, useUROI=TRUE, + uROI=noMatch_uROI3, useFIR=TRUE, FIR=input_FIR, isAnnotated=TRUE, cpdMetadata=input_cpdMetadata, spectraMetadata=input_spectraMetadata) # Expected annotation expected_annotation <- initAnnotation[c(1,3),] @@ -541,9 +535,9 @@ test_that('already annotated message in verbose', { expected_message <- c("!! Data was already annotated, results will be overwritten !!\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "----- ko15 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Fit of ROI #3 is unsuccessful (try err)\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "Error file does not exist: aaa/bbb.cdf\n", "----- ko18 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #2\n", "Fit of ROI #3 is unsuccessful (try err)\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #4\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=TRUE, verbose=TRUE)) - - # Check results + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=TRUE, verbose=TRUE)) + + # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) expect_equal(result_parallelAnnotation$result$failures, expected_failures) @@ -653,8 +647,8 @@ test_that('curveModel emgGaussian: 3 files, 4 compounds, no uROI, no FIR, no get expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Fit of ROI #3 is unsuccessful (cannot determine rtMin/rtMax)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE, curveModel='emgGaussian')) - + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE, curveModel='emgGaussian')) + # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) @@ -703,15 +697,15 @@ test_that('raise errors', { wrongInit <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable) wrongInit@TIC <- c(1, 2) msg1 <- paste('invalid class ', dQuote('peakPantheRAnnotation'),' object: TIC has 2 elements (samples). Should be 3', sep='') - expect_error(peakPantheR_parallelAnnotation(wrongInit, ncores=0, getAcquTime=FALSE, verbose=FALSE), msg1, fixed=TRUE) + expect_error(peakPantheR_parallelAnnotation(wrongInit, nCores=1, getAcquTime=FALSE, verbose=FALSE), msg1, fixed=TRUE) - # resetWorkers is not an integer + # BPPARAM is not BiocParallel BiocParallelParam is not an integer initAnnotation2 <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable) - msg2 <- "Check input, resetWorkers must be an integer" - expect_error(peakPantheR_parallelAnnotation(initAnnotation2, ncores=0, getAcquTime=FALSE, resetWorkers='not an Integer', verbose=FALSE), msg2, fixed=TRUE) + msg2 <- "Check input, BPPARAM must be a BiocParallel Param object" + expect_error(peakPantheR_parallelAnnotation(initAnnotation2, nCores=1, getAcquTime=FALSE, BPPARAM='not a BiocParallelParam object', verbose=FALSE), msg2, fixed=TRUE) - # resetWorkers is < 0 + # nCores is < 0 initAnnotation3 <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable) - msg3 <- "Check input, resetWorkers must be a positive integer" - expect_error(peakPantheR_parallelAnnotation(initAnnotation3, ncores=0, getAcquTime=FALSE, resetWorkers=-10, verbose=FALSE), msg3, fixed=TRUE) + msg3 <- "Check input, nCores must be a positive integer" + expect_error(peakPantheR_parallelAnnotation(initAnnotation3, nCores=-10, getAcquTime=FALSE, verbose=FALSE), msg3, fixed=TRUE) }) From 53e3c97f2a7dd3434578c59e1749f2a7c9f7aceb Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Wed, 6 Apr 2022 13:52:15 +0100 Subject: [PATCH 05/16] - BiocParallel implementation: update to continuum parallel annotation unittest --- inst/shiny-GUI/peakPantheR-App/server.R | 6 +++--- inst/shiny-GUI/peakPantheR-App/server/server_run.R | 2 +- inst/shiny-GUI/peakPantheR-App/ui.R | 10 +++++----- inst/shiny-GUI/peakPantheR-App/ui/ui_run.R | 2 +- tests/testthat/test_continuum_mode.R | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/inst/shiny-GUI/peakPantheR-App/server.R b/inst/shiny-GUI/peakPantheR-App/server.R index 5b0d26a..9d0cdd9 100644 --- a/inst/shiny-GUI/peakPantheR-App/server.R +++ b/inst/shiny-GUI/peakPantheR-App/server.R @@ -1,12 +1,12 @@ # server.R # peakPantheR-App -# Based on peakPantheR v1.3.0, R >= 4.0, shiny >= 1.0.5, shinythemes >= 1.1.1 +# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, shinythemes >= 1.1.1 # National Phenome Centre -# 11/10/2020 +# 05/04/2022 # Licensed under GPLv3 # -# Copyright (C) {2020} {National Phenome Centre} +# Copyright (C) {2022} {National Phenome Centre} # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/inst/shiny-GUI/peakPantheR-App/server/server_run.R b/inst/shiny-GUI/peakPantheR-App/server/server_run.R index 38b1299..fe106e3 100644 --- a/inst/shiny-GUI/peakPantheR-App/server/server_run.R +++ b/inst/shiny-GUI/peakPantheR-App/server/server_run.R @@ -123,7 +123,7 @@ observeEvent(input$goAnnotation, { useFIR=input$useFIR, verbose=FALSE) ## Annotate! - result <- peakPantheR_parallelAnnotation(tmp_annotation, ncores=ncoresInput(), curveModel=input$curveModel, verbose=TRUE) + result <- peakPantheR_parallelAnnotation(tmp_annotation, nCores=ncoresInput(), curveModel=input$curveModel, verbose=TRUE) # Store the annotation and failures into the reactiveValue values$annotation <- result$annotation diff --git a/inst/shiny-GUI/peakPantheR-App/ui.R b/inst/shiny-GUI/peakPantheR-App/ui.R index c70352b..802b998 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui.R +++ b/inst/shiny-GUI/peakPantheR-App/ui.R @@ -1,12 +1,12 @@ -# ui.R +# server.R # peakPantheR-App -# Based on peakPantheR v1.3.0, R >= 4.0, shiny >= 1.0.5, shinythemes >= 1.1.1 +# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, shinythemes >= 1.1.1 # National Phenome Centre -# 11/10/2020 -# Licensed under GPLv3 +# 05/04/2022 +# Licensed under GPLv3 # -# Copyright (C) {2020} {National Phenome Centre} +# Copyright (C) {2022} {National Phenome Centre} # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R b/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R index ee91b33..d55b01a 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R +++ b/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R @@ -31,7 +31,7 @@ tabPanel("Run annotation", uiOutput("curveModelSelectInput"), # curveModel ), # end column (useUROI, useFIR) - # ncores cpuslider + # nCores cpuslider column(4, offset=1, checkboxInput("parallelisation", label = p("Parallelisation", style="color:#3e648d;font-weight:bold"), diff --git a/tests/testthat/test_continuum_mode.R b/tests/testthat/test_continuum_mode.R index ac0fb57..8873234 100644 --- a/tests/testthat/test_continuum_mode.R +++ b/tests/testthat/test_continuum_mode.R @@ -192,7 +192,7 @@ test_that('peakPantheR_parallelAnnotation() continuum mode', { expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, centroided=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, centroided=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) From c692d284a1e5f86337842dfed6d115b200b16c3a Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Wed, 6 Apr 2022 15:55:14 +0100 Subject: [PATCH 06/16] - BiocParallel implementation: update to continuum parallel annotation unittest --- ...Diagnostic-peakPantheRAnnotation-method.Rd | 7 ++++-- man/peakPantheR_ROIStatistics.Rd | 23 +++++++++++-------- man/peakPantheR_parallelAnnotation.Rd | 21 +++++------------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd b/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd index 01826b1..191e285 100644 --- a/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd +++ b/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd @@ -13,7 +13,8 @@ per fitted compound} savePlots = TRUE, sampleColour = NULL, verbose = TRUE, - ncores = 0, + nCores = 1, + BPPARAM = NULL, ... ) } @@ -29,7 +30,9 @@ and plots will be saved} \item{verbose}{(bool) If TRUE message progress} -\item{ncores}{(int) Number of cores to use to save plots in parallel} +\item{nCores}{(int) Number of cores to use to save plots in parallel} + +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} \item{...}{Additional parameters for plotting i.e. \code{sampling} for the number of points to employ when plotting fittedCurve} diff --git a/man/peakPantheR_ROIStatistics.Rd b/man/peakPantheR_ROIStatistics.Rd index 0377ef4..c8eb352 100644 --- a/man/peakPantheR_ROIStatistics.Rd +++ b/man/peakPantheR_ROIStatistics.Rd @@ -5,14 +5,15 @@ \title{Save to disk each ROI EIC and mean IS RT} \usage{ peakPantheR_ROIStatistics( - referenceSpectraFiles, - saveFolder, - ROI = NULL, - IS_ROI = NULL, - sampleColour = NULL, - ncores = 0, - saveISPlots = TRUE, - verbose = TRUE + referenceSpectraFiles, + saveFolder, + ROI = NULL, + IS_ROI = NULL, + sampleColour = NULL, + nCores = 1, + saveISPlots = TRUE, + verbose = TRUE, + BPPARAM = NULL ) } \arguments{ @@ -36,12 +37,14 @@ mean RT is not calculated and saved in \code{IS_mean_RT.csv})} \item{sampleColour}{(str) NULL or vector colour for each sample} -\item{ncores}{(int) Number of cores to use to integrate IS in parallel} +\item{nCores}{(int) Number of cores to use to integrate IS in parallel} \item{saveISPlots}{(bool) If TRUE save a diagnostic plot for each IS to \code{saveFolder/IS_search} compound} \item{verbose}{(bool) If TRUE message progress} + +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} } \value{ None @@ -82,6 +85,6 @@ saveFolder1 <- tempdir() # Calculate ROI statiscs peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, - ncores=0, saveISPlots=TRUE, verbose=TRUE) + nCores=0, saveISPlots=TRUE, verbose=TRUE) } } diff --git a/man/peakPantheR_parallelAnnotation.Rd b/man/peakPantheR_parallelAnnotation.Rd index 067eaca..4888a0a 100644 --- a/man/peakPantheR_parallelAnnotation.Rd +++ b/man/peakPantheR_parallelAnnotation.Rd @@ -6,9 +6,9 @@ \usage{ peakPantheR_parallelAnnotation( object, - ncores = 0, + BPPARAM = NULL, + nCores = 1, getAcquTime = TRUE, - resetWorkers = 1, centroided = TRUE, curveModel = "skewedGaussian", verbose = TRUE, @@ -21,21 +21,12 @@ object defining the samples to process and compounds to target. The slots \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR integrated if a feature is not found} -\item{ncores}{(int) Number of cores to use for parallelisation. Default 0 for +\item{nCores}{(int) Number of cores to use for parallelisation. Default 1 for no parallelisation.} \item{getAcquTime}{(bool) If TRUE will extract sample acquisition date-time from the mzML metadata (the additional file access will impact run time)} -\item{resetWorkers}{(int) If 0, the parallel cluster is only initiated once. -If >0 the cluster will be reset (and the memory of each worker freed) once -\code{ncores * resetWorkers} files have been processed. Default value is 1, -the cluster is reset once \code{ncores} files have been processed. While -potentially impacting performance (need to wait until all \code{ncores * -resetWorkers} files are processed before restarting the cluster), shutting -down the workers processes regularly will ensure the OS can reallocate memory -more efficiently. For values >1, ensure sufficient system memory is available} - \item{centroided}{(bool) use TRUE if the data is centroided, used by \code{\link[MSnbase]{readMSData}} when reading the raw data files} @@ -59,8 +50,8 @@ Integrate all target features in all files defined in the initialised input object and store results. The use of updated ROI and the integration of FIR are controled by the input object slots \code{useUROI} and \code{useFIR}. Files are processed in parallel using -\link{peakPantheR_singleFileSearch}; \code{ncores} controls the number of -cores used for parallelisation, with \code{ncores=0} corresponding to serial +\link{peakPantheR_singleFileSearch}; \code{nCores} controls the number of +cores used for parallelisation, with \code{nCores=1} corresponding to serial processing. If the processing of a file fails (file does not exist or error during execution) the sample is removed from the outputed object. } @@ -100,7 +91,7 @@ initAnnotation <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, # Run serially result_parallelAnnotation <- peakPantheR_parallelAnnotation(initAnnotation, - ncores=0, + nCores=1, getAcquTime=FALSE, verbose=TRUE) # Processing 4 compounds in 3 samples: From a76f38c6e56cdd2d068a9171f6bd6abc8dfe5ba5 Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Thu, 7 Apr 2022 11:06:47 +0100 Subject: [PATCH 07/16] - BiocParallel implementation: import and argument fixes in doc comments --- NAMESPACE | 2 +- R/methods_peakPantheRAnnotation.R | 8 ++++---- R/peakPantheR.R | 3 +-- R/peakPantheR_parallelAnnotation.R | 4 ++-- R/peakPantheR_start_GUI.R | 3 +-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3742dfd..c1a5c89 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,8 +48,8 @@ exportMethods(uROI) exportMethods(uROIExist) exportMethods(useFIR) exportMethods(useUROI) -import(XML) import(BiocParallel) +import(XML) import(methods) import(mzR) import(scales) diff --git a/R/methods_peakPantheRAnnotation.R b/R/methods_peakPantheRAnnotation.R index fb2ca09..4c00d90 100644 --- a/R/methods_peakPantheRAnnotation.R +++ b/R/methods_peakPantheRAnnotation.R @@ -1646,7 +1646,7 @@ setGeneric("outputAnnotationDiagnostic", #' targetFeatTable=targetFeatTable) #' #' # Calculate annotation -#' annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, ncores=0, +#' annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, nCores=1, #' getAcquTime=FALSE, verbose=FALSE)$annotation #' #' # temporary location @@ -1670,7 +1670,7 @@ setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", if (nCores < 0) { stop("Check input, nCores must be a positive integer") } - # Handle default BPParams + # Handle default BPParam if (is.null(BPPARAM)) { if (nCores > 1) { if (.Platform$OS.type == 'windows') { @@ -1797,7 +1797,7 @@ setGeneric("outputAnnotationResult", #' targetFeatTable=targetFeatTable) #' #' # Calculate annotation -#' annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, ncores=0, +#' annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, nCores=1, #' getAcquTime=FALSE, verbose=FALSE)$annotation #' #' # temporary location @@ -2440,7 +2440,7 @@ setGeneric("retentionTimeCorrection", #' targetFeatTable=targetFeatTable) #' # annotate files serially #' annotation_result <- peakPantheR_parallelAnnotation(smallAnnotation, -#' ncores=0, verbose=TRUE) +#' nCores=1, verbose=TRUE) #' data_annotation <- annotation_result$annotation #' #' # Example with constant correction diff --git a/R/peakPantheR.R b/R/peakPantheR.R index d772139..e306ed5 100644 --- a/R/peakPantheR.R +++ b/R/peakPantheR.R @@ -47,8 +47,7 @@ #' @docType package #' @name peakPantheR #' -#' @import foreach -#' @import doParallel +#' @import BiocParallel #' "_PACKAGE" #> [1] "_PACKAGE" diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index 8c44296..a7770ab 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -13,6 +13,7 @@ #' object defining the samples to process and compounds to target. The slots #' \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR #' integrated if a feature is not found +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object #' @param nCores (int) Number of cores to use for parallelisation. Default 1 for #' no parallelisation. #' @param getAcquTime (bool) If TRUE will extract sample acquisition date-time @@ -142,9 +143,8 @@ #' @family peakPantheR #' @family parallelAnnotation #' -#' @import foreach -#' @import doParallel #' @import mzR +#' @import BiocParallel #' #' @export peakPantheR_parallelAnnotation <- function(object, BPPARAM=NULL, nCores = 1, diff --git a/R/peakPantheR_start_GUI.R b/R/peakPantheR_start_GUI.R index 7a7bc61..332768a 100644 --- a/R/peakPantheR_start_GUI.R +++ b/R/peakPantheR_start_GUI.R @@ -14,8 +14,7 @@ #' print("Start graphical interface, press 'ESC' in the command line to stop") #' # peakPantheR_start_GUI() #' -#' @import foreach -#' @import doParallel +#' @import BiocParallel #' @import shiny #' @import shinythemes #' @import shinycssloaders From f760a64c5ab15d23e2c14d8473bb678fe5b266fa Mon Sep 17 00:00:00 2001 From: gscorreia89 Date: Thu, 7 Apr 2022 12:21:19 +0100 Subject: [PATCH 08/16] - BiocParallel implementation: import and argument fixes in doc comments --- man/peakPantheR_parallelAnnotation.Rd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/peakPantheR_parallelAnnotation.Rd b/man/peakPantheR_parallelAnnotation.Rd index 4888a0a..a3b4cb0 100644 --- a/man/peakPantheR_parallelAnnotation.Rd +++ b/man/peakPantheR_parallelAnnotation.Rd @@ -21,6 +21,8 @@ object defining the samples to process and compounds to target. The slots \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR integrated if a feature is not found} +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} + \item{nCores}{(int) Number of cores to use for parallelisation. Default 1 for no parallelisation.} From 3786866fbbc137709f085b2af17aed649dfe2534 Mon Sep 17 00:00:00 2001 From: Arnaud Wolfer Date: Sun, 10 Apr 2022 00:07:08 +0200 Subject: [PATCH 09/16] update GUI to bslib instead of shinythemes --- DESCRIPTION | 2 +- NAMESPACE | 2 +- R/peakPantheR_start_GUI.R | 2 +- inst/shiny-GUI/peakPantheR-App/server.R | 2 +- inst/shiny-GUI/peakPantheR-App/ui.R | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7b10a8b..a981b5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Imports: minpack.lm (>= 1.2.1), scales(>= 0.5.0), shiny (>= 1.0.5), - shinythemes (>= 1.1.1), + bslib, shinycssloaders (>= 1.0.0), DT (>= 0.15), pracma (>= 2.2.3), diff --git a/NAMESPACE b/NAMESPACE index c1a5c89..f4efe00 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,7 +55,7 @@ import(mzR) import(scales) import(shiny) import(shinycssloaders) -import(shinythemes) +import(bslib) import(utils) importFrom(DT,DTOutput) importFrom(DT,datatable) diff --git a/R/peakPantheR_start_GUI.R b/R/peakPantheR_start_GUI.R index 332768a..7e3a36d 100644 --- a/R/peakPantheR_start_GUI.R +++ b/R/peakPantheR_start_GUI.R @@ -16,7 +16,7 @@ #' #' @import BiocParallel #' @import shiny -#' @import shinythemes +#' @import bslib #' @import shinycssloaders #' @importFrom DT DTOutput renderDT datatable #' diff --git a/inst/shiny-GUI/peakPantheR-App/server.R b/inst/shiny-GUI/peakPantheR-App/server.R index 9d0cdd9..00e9c40 100644 --- a/inst/shiny-GUI/peakPantheR-App/server.R +++ b/inst/shiny-GUI/peakPantheR-App/server.R @@ -1,7 +1,7 @@ # server.R # peakPantheR-App -# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, shinythemes >= 1.1.1 +# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, bslib # National Phenome Centre # 05/04/2022 # Licensed under GPLv3 diff --git a/inst/shiny-GUI/peakPantheR-App/ui.R b/inst/shiny-GUI/peakPantheR-App/ui.R index 802b998..91e87f3 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui.R +++ b/inst/shiny-GUI/peakPantheR-App/ui.R @@ -1,7 +1,7 @@ # server.R # peakPantheR-App -# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, shinythemes >= 1.1.1 +# Based on peakPantheR v1.9.2, R >= 4.1, shiny >= 1.0.5, bslib # National Phenome Centre # 05/04/2022 # Licensed under GPLv3 @@ -22,7 +22,7 @@ # along with this program. If not, see . #require(shiny) -#require(shinythemes) +#require(bslib) # NOTE: # @@ -33,9 +33,9 @@ # update + refit in UI? -shinyUI(fluidPage(theme = shinythemes::shinytheme("spacelab"), title='peakPantheR', +shinyUI(fluidPage(theme = bslib::bs_theme(bootswatch = "spacelab"), title='peakPantheR', navbarPage(title = textOutput("peakPantheR_ver"), - inverse = TRUE, + inverse = FALSE, collapsible = TRUE, windowTitle = textOutput("peakPantheR_ver"), From 688ef0c55ba1a25905c0ad07451d4b617d43c64a Mon Sep 17 00:00:00 2001 From: Arnaud Wolfer Date: Mon, 11 Apr 2022 13:25:34 +0200 Subject: [PATCH 10/16] BiocChecks --- .Rbuildignore | 1 + .gitignore | 1 + .vscode/settings.json | 5 + DESCRIPTION | 6 +- NAMESPACE | 2 +- R/GUI_utils.R | 2 +- R/methods_peakPantheRAnnotation.R | 9 +- R/peakPantheR_ROIStatistics.R | 10 +- R/peakPantheR_parallelAnnotation.R | 20 +-- man/peakPantheRAnnotation.Rd | 125 ++++++++++-------- man/peakPantheR_ROIStatistics.Rd | 18 +-- ...Correction-peakPantheRAnnotation-method.Rd | 2 +- 12 files changed, 115 insertions(+), 86 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.Rbuildignore b/.Rbuildignore index dc98bbf..d38a3ae 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -16,4 +16,5 @@ docs ^_pkgdown\.yml$ ^pkgdown$ ^\.github$ +^\.vscode$ CONTRIBUTIONS.md diff --git a/.gitignore b/.gitignore index 37c54dd..d7d1936 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,6 @@ doc/*.Rmd Rplots.pdf tests/testthat/Rplots.pdf .idea +.vscode docs inst/doc diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b5c0b1d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.rulers": [ + 80, 120 + ] +} \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index a981b5d..1786d96 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: peakPantheR Title: Peak Picking and Annotation of High Resolution Experiments -Version: 1.9.2 -Date: 2021-12-18 +Version: 1.9.3 +Date: 2022-04-11 Authors@R: c(person("Arnaud", "Wolfer", email = "adwolfer@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5856-3218")), person("Goncalo", "Correia", email = "gscorreia89@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-8271-9294")), person("Jake", "Pearce", email = "jake.pearce@gmail.com", role = "ctb"), @@ -10,7 +10,7 @@ Description: An automated pipeline for the detection, integration and reporting It enables the real time annotation of multiple compounds in a single file, or the parallel annotation of multiple compounds in multiple files. A graphical user interface as well as command line functions will assist in assessing the quality of annotation and update fitting parameters until a satisfactory result is obtained. Depends: - R (>= 4.1) + R (>= 4.2) Imports: ggplot2 (>= 3.3.0), gridExtra (>= 2.3), diff --git a/NAMESPACE b/NAMESPACE index f4efe00..e4e2fbd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,12 +50,12 @@ exportMethods(useFIR) exportMethods(useUROI) import(BiocParallel) import(XML) +import(bslib) import(methods) import(mzR) import(scales) import(shiny) import(shinycssloaders) -import(bslib) import(utils) importFrom(DT,DTOutput) importFrom(DT,datatable) diff --git a/R/GUI_utils.R b/R/GUI_utils.R index 8e7a144..39f0262 100644 --- a/R/GUI_utils.R +++ b/R/GUI_utils.R @@ -331,7 +331,7 @@ annotation_showMethod_UI_helper <- function(annotation){ #' # [[6]] #' # [1] "does not use fallback integration regions (FIR)" annotation_showText_UI_helper <- function(annotProp){ - UI_string = list( + UI_string <- list( if (annotProp$isAnnotated) {'Is annotated'} else {'Not annotated'}, paste0(annotProp$nbCompounds, ' compounds'), paste0(annotProp$nbSamples, ' samples'), diff --git a/R/methods_peakPantheRAnnotation.R b/R/methods_peakPantheRAnnotation.R index 4c00d90..fad9fc3 100644 --- a/R/methods_peakPantheRAnnotation.R +++ b/R/methods_peakPantheRAnnotation.R @@ -1613,7 +1613,8 @@ setGeneric("outputAnnotationDiagnostic", #' @param sampleColour (str) NULL or vector colour for each sample #' @param verbose (bool) If TRUE message progress #' @param nCores (int) Number of cores to use to save plots in parallel -#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel +#' processing. Must be a BiocParallelParam object #' @param ... Additional parameters for plotting i.e. \code{sampling} for the #' number of points to employ when plotting fittedCurve #' @return None @@ -1655,7 +1656,8 @@ setGeneric("outputAnnotationDiagnostic", #' verbose=TRUE) #' } setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", - function(object, saveFolder, savePlots, sampleColour, verbose, nCores, BPPARAM, ...) { + function(object, saveFolder, savePlots, sampleColour, verbose, nCores, + BPPARAM, ...) { # Save standardised csv outputAnnotationParamsCSV(object, saveFolder = saveFolder,verbose = verbose) @@ -1693,7 +1695,8 @@ setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation", BiocParallel::register(BPPARAM) BiocParallel::bpstart(BPPARAM) # Run - savedPlots <- BiocParallel::bplapply(X=seq_len(nbCpd), FUN = outputAnnotationDiagnostic_saveSingleMultiPlot, + savedPlots <- BiocParallel::bplapply(X=seq_len(nbCpd), + FUN = outputAnnotationDiagnostic_saveSingleMultiPlot, annotation = object, saveFolder = saveFolder, sampleColour = sampleColour, nbCpd = nbCpd, verbose = verbose, BPPARAM = BPPARAM, ...) diff --git a/R/peakPantheR_ROIStatistics.R b/R/peakPantheR_ROIStatistics.R index 79e29f1..d717eae 100644 --- a/R/peakPantheR_ROIStatistics.R +++ b/R/peakPantheR_ROIStatistics.R @@ -18,7 +18,8 @@ #' mean RT is not calculated and saved in \code{IS_mean_RT.csv}) #' @param sampleColour (str) NULL or vector colour for each sample #' @param nCores (int) Number of cores to use to integrate IS in parallel -#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel +#' processing. Must be a BiocParallelParam object #' @param saveISPlots (bool) If TRUE save a diagnostic plot for each IS to #' \code{saveFolder/IS_search} compound #' @param verbose (bool) If TRUE message progress @@ -60,7 +61,8 @@ peakPantheR_ROIStatistics <- function(referenceSpectraFiles, saveFolder, ROI = NULL, IS_ROI = NULL, sampleColour = NULL, nCores = 1, - saveISPlots = TRUE, verbose = TRUE, BPPARAM=NULL) { + saveISPlots = TRUE, verbose = TRUE, + BPPARAM=NULL) { # Check and process input parameters resInit <- ROIStatistics_init_checks(referenceSpectraFiles, saveFolder, ROI, IS_ROI, sampleColour, verbose) @@ -78,7 +80,7 @@ peakPantheR_ROIStatistics <- function(referenceSpectraFiles, saveFolder, # calculate mean IS for each RT if (calculateMeanISRT) { ROIStatistics_calculateMeanISRT(referenceSpectraFiles, saveFolder, - IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM) + IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM) } } @@ -240,7 +242,7 @@ ROIStatistics_saveEICsROI <- function(referenceSpectraFiles, saveFolder, ROI, } # Calculate mean RT for each IS ROIStatistics_calculateMeanISRT <- function(referenceSpectraFiles, saveFolder, - IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM){ + IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM){ if (verbose) { message("\n-- Calculating mean RT for each IS --") } diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index a7770ab..f610828 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -13,7 +13,8 @@ #' object defining the samples to process and compounds to target. The slots #' \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR #' integrated if a feature is not found -#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object +#' @param BPPARAM (BiocParallel::BiocParallelParam) Settings for parallel +#' processing. Must be a BiocParallelParam object #' @param nCores (int) Number of cores to use for parallelisation. Default 1 for #' no parallelisation. #' @param getAcquTime (bool) If TRUE will extract sample acquisition date-time @@ -152,9 +153,9 @@ peakPantheR_parallelAnnotation <- function(object, BPPARAM=NULL, nCores = 1, curveModel='skewedGaussian', verbose=TRUE, ...){ # Check inputs, Initialise variables and outputs - initRes <- parallelAnnotation_init(object, BPPARAM, nCores, verbose) - file_paths = initRes$file_paths; target_peak_table=initRes$target_peak_table - input_FIR = initRes$input_FIR; BPPARAMObject <- initRes$BPPARAMObject + initRes <- parallelAnnotation_init(object, BPPARAM, nCores, verbose) + file_paths<-initRes$file_paths; target_peak_table<-initRes$target_peak_table + input_FIR <- initRes$input_FIR; BPPARAMObject <- initRes$BPPARAMObject stime <- Sys.time() @@ -334,11 +335,12 @@ curveModel, verbose, ...) { BiocParallel::register(BPPARAM) BiocParallel::bpstart(BPPARAM) - allFilesRes <- BiocParallel::bplapply(X=file_paths, FUN = parallelAnnotation_parallelHelper, - targetFeatTable=target_peak_table, - inGetAcquTime=getAcquTime, inFIR=input_FIR, - centr=centroided, curveModel=curveModel, inVerbose = verbose, - BPPARAM = BPPARAM, ...) + allFilesRes <- BiocParallel::bplapply(X=file_paths, + FUN=parallelAnnotation_parallelHelper, + targetFeatTable=target_peak_table, + inGetAcquTime=getAcquTime, inFIR=input_FIR, + centr=centroided, curveModel=curveModel, inVerbose=verbose, + BPPARAM = BPPARAM, ...) BiocParallel::bpstop(BPPARAM) return(allFilesRes) } diff --git a/man/peakPantheRAnnotation.Rd b/man/peakPantheRAnnotation.Rd index 85561b1..f9854d4 100644 --- a/man/peakPantheRAnnotation.Rd +++ b/man/peakPantheRAnnotation.Rd @@ -6,33 +6,55 @@ \alias{peakPantheRAnnotation-class} \title{An S4 class to represent peakPantheR annotation results} \usage{ -peakPantheRAnnotation(spectraPaths = NULL, targetFeatTable = NULL, - cpdID = character(), cpdName = character(), ROI = data.frame(rtMin - = numeric(), rt = numeric(), rtMax = numeric(), mzMin = numeric(), mz = - numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = - numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), - mzMin = numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = - FALSE), filepath = character(), cpdMetadata = data.frame(), - spectraMetadata = data.frame(), acquisitionTime = character(), - uROIExist = FALSE, useUROI = FALSE, useFIR = FALSE, - TIC = numeric(), peakTables = list(), dataPoints = list(), - peakFit = list(), isAnnotated = FALSE) - -peakPantheRAnnotation(spectraPaths = NULL, targetFeatTable = NULL, - cpdID = character(), cpdName = character(), ROI = data.frame(rtMin - = numeric(), rt = numeric(), rtMax = numeric(), mzMin = numeric(), mz = - numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = - numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), - mzMin = numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = - FALSE), filepath = character(), cpdMetadata = data.frame(), - spectraMetadata = data.frame(), acquisitionTime = character(), - uROIExist = FALSE, useUROI = FALSE, useFIR = FALSE, - TIC = numeric(), peakTables = list(), dataPoints = list(), - peakFit = list(), isAnnotated = FALSE) +peakPantheRAnnotation( + spectraPaths = NULL, + targetFeatTable = NULL, + cpdID = character(), + cpdName = character(), + ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = + numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), mzMax = + numeric(), stringsAsFactors = FALSE), + uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = + numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + filepath = character(), + cpdMetadata = data.frame(), + spectraMetadata = data.frame(), + acquisitionTime = character(), + uROIExist = FALSE, + useUROI = FALSE, + useFIR = FALSE, + TIC = numeric(), + peakTables = list(), + dataPoints = list(), + peakFit = list(), + isAnnotated = FALSE +) + +peakPantheRAnnotation( + spectraPaths = NULL, + targetFeatTable = NULL, + cpdID = character(), + cpdName = character(), + ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = + numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), mzMax = + numeric(), stringsAsFactors = FALSE), + uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = + numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + filepath = character(), + cpdMetadata = data.frame(), + spectraMetadata = data.frame(), + acquisitionTime = character(), + uROIExist = FALSE, + useUROI = FALSE, + useFIR = FALSE, + TIC = numeric(), + peakTables = list(), + dataPoints = list(), + peakFit = list(), + isAnnotated = FALSE +) } \arguments{ \item{spectraPaths}{NULL or a character vector of spectra file paths, to set @@ -132,41 +154,36 @@ ROI as columns. \section{Slots}{ \describe{ -\item{\code{cpdID}}{A character vector of compound IDs, of length -number of compounds} +\item{\code{cpdID}}{A character vector of compound IDs, of length number of compounds} \item{\code{cpdName}}{A character vector of compound names, of length number of compounds} -\item{\code{ROI}}{A data.frame of Regions Of Interest (ROI) with -compounds as row and +\item{\code{ROI}}{A data.frame of Regions Of Interest (ROI) with compounds as row and ROI parameters as columns: \code{rtMin} (float in seconds), \code{rt} (float in seconds, or \emph{NA}), \code{rtMax} (float in seconds), \code{mzMin} (float), \code{mz} (float or \emph{NA}), \code{mzMax} (float).} -\item{\code{FIR}}{A data.frame of Fallback Integration Regions (FIR) -with compounds +\item{\code{FIR}}{A data.frame of Fallback Integration Regions (FIR) with compounds as row and FIR parameters as columns: \code{rtMin} (float in seconds), \code{rtMax} (float in seconds), \code{mzMin} (float), \code{mzMax} (float).} -\item{\code{uROI}}{A data.frame of updated Regions Of Interest -(uROI) with compounds +\item{\code{uROI}}{A data.frame of updated Regions Of Interest (uROI) with compounds as row and uROI parameters as columns: \code{rtMin} (float in seconds), \code{rt} (float in seconds, or \emph{NA}), \code{rtMax} (float in seconds), \code{mzMin} (float), \code{mz} (float or \emph{NA}), \code{mzMax} (float).} -\item{\code{filepath}}{A character vector of file paths, of -length number of spectra +\item{\code{filepath}}{A character vector of file paths, of length number of spectra files} -\item{\code{cpdMetadata}}{A data.frame of compound metadata, -with compounds as row and metadata as columns} +\item{\code{cpdMetadata}}{A data.frame of compound metadata, with compounds as row +and metadata as columns} -\item{\code{spectraMetadata}}{A data.frame of sample metadata, -with samples as row and metadata as columns} +\item{\code{spectraMetadata}}{A data.frame of sample metadata, with samples as row +and metadata as columns} -\item{\code{acquisitionTime}}{A character -vector of acquisition date-time (converted from POSIXct) or NA} +\item{\code{acquisitionTime}}{A character vector of acquisition date-time (converted +from POSIXct) or NA} \item{\code{uROIExist}}{A logical stating if uROI have been set} @@ -174,21 +191,19 @@ vector of acquisition date-time (converted from POSIXct) or NA} \item{\code{useFIR}}{A logical stating if FIR are to be used} -\item{\code{TIC}}{A numeric vector of TIC or NA, -of length number of spectra files} +\item{\code{TIC}}{A numeric vector of TIC or NA, of length number of spectra files} -\item{\code{peakTables}}{A list of peakTable data.frame, of -length number of spectra files. Each peakTable data.frame -has compounds as rows and peak annotation results as columns.} +\item{\code{peakTables}}{A list of peakTable data.frame, of length number of spectra +files. Each peakTable data.frame has compounds as rows and peak annotation +results as columns.} -\item{\code{dataPoints}}{A list of length number of spectra files. -Each list element is a \emph{ROIsDataPoint} list of \code{data.frame} -of raw data points for each ROI/uROI (retention time 'rt', -mass 'mz' and intensity 'int' (as column) of each raw data points (as row))} +\item{\code{dataPoints}}{A list of length number of spectra files. Each list element +is a \emph{ROIsDataPoint} list of \code{data.frame} of raw data points for +each ROI/uROI (retention time 'rt', mass 'mz' and intensity 'int' (as column) +of each raw data points (as row))} -\item{\code{peakFit}}{A list of length number of spectra files. -Each list element is a \emph{curveFit} list of -\code{peakPantheR_curveFit} or NA for each ROI} +\item{\code{peakFit}}{A list of length number of spectra files. Each list element is +a \emph{curveFit} list of \code{peakPantheR_curveFit} or NA for each ROI} \item{\code{isAnnotated}}{A logical stating if the annotation has taken place diff --git a/man/peakPantheR_ROIStatistics.Rd b/man/peakPantheR_ROIStatistics.Rd index c8eb352..df107b1 100644 --- a/man/peakPantheR_ROIStatistics.Rd +++ b/man/peakPantheR_ROIStatistics.Rd @@ -5,15 +5,15 @@ \title{Save to disk each ROI EIC and mean IS RT} \usage{ peakPantheR_ROIStatistics( - referenceSpectraFiles, - saveFolder, - ROI = NULL, - IS_ROI = NULL, - sampleColour = NULL, - nCores = 1, - saveISPlots = TRUE, - verbose = TRUE, - BPPARAM = NULL + referenceSpectraFiles, + saveFolder, + ROI = NULL, + IS_ROI = NULL, + sampleColour = NULL, + nCores = 1, + saveISPlots = TRUE, + verbose = TRUE, + BPPARAM = NULL ) } \arguments{ diff --git a/man/retentionTimeCorrection-peakPantheRAnnotation-method.Rd b/man/retentionTimeCorrection-peakPantheRAnnotation-method.Rd index 09d3b6a..448913c 100644 --- a/man/retentionTimeCorrection-peakPantheRAnnotation-method.Rd +++ b/man/retentionTimeCorrection-peakPantheRAnnotation-method.Rd @@ -81,7 +81,7 @@ smallAnnotation <- peakPantheRAnnotation(spectraPaths=spectraPaths, targetFeatTable=targetFeatTable) # annotate files serially annotation_result <- peakPantheR_parallelAnnotation(smallAnnotation, - ncores=0, verbose=TRUE) + nCores=1, verbose=TRUE) data_annotation <- annotation_result$annotation # Example with constant correction From e9964f7f5013693d365073ae3bb75cf5caf7aea0 Mon Sep 17 00:00:00 2001 From: Arnaud Wolfer Date: Mon, 11 Apr 2022 13:56:49 +0200 Subject: [PATCH 11/16] BiocChecks --- ...Diagnostic-peakPantheRAnnotation-method.Rd | 5 +- ...tionResult-peakPantheRAnnotation-method.Rd | 2 +- man/peakPantheRAnnotation.Rd | 88 ++++++++++--------- man/peakPantheR_ROIStatistics.Rd | 3 +- man/peakPantheR_parallelAnnotation.Rd | 3 +- 5 files changed, 56 insertions(+), 45 deletions(-) diff --git a/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd b/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd index 191e285..b1e2f6a 100644 --- a/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd +++ b/man/outputAnnotationDiagnostic-peakPantheRAnnotation-method.Rd @@ -32,7 +32,8 @@ and plots will be saved} \item{nCores}{(int) Number of cores to use to save plots in parallel} -\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel +processing. Must be a BiocParallelParam object} \item{...}{Additional parameters for plotting i.e. \code{sampling} for the number of points to employ when plotting fittedCurve} @@ -72,7 +73,7 @@ emptyAnnotation <- peakPantheRAnnotation(spectraPaths=spectraPaths, targetFeatTable=targetFeatTable) # Calculate annotation -annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, ncores=0, +annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE)$annotation # temporary location diff --git a/man/outputAnnotationResult-peakPantheRAnnotation-method.Rd b/man/outputAnnotationResult-peakPantheRAnnotation-method.Rd index 6cd1449..d78e9ac 100644 --- a/man/outputAnnotationResult-peakPantheRAnnotation-method.Rd +++ b/man/outputAnnotationResult-peakPantheRAnnotation-method.Rd @@ -62,7 +62,7 @@ emptyAnnotation <- peakPantheRAnnotation(spectraPaths=spectraPaths, targetFeatTable=targetFeatTable) # Calculate annotation -annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, ncores=0, +annotation <- peakPantheR_parallelAnnotation(emptyAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE)$annotation # temporary location diff --git a/man/peakPantheRAnnotation.Rd b/man/peakPantheRAnnotation.Rd index f9854d4..a32ba85 100644 --- a/man/peakPantheRAnnotation.Rd +++ b/man/peakPantheRAnnotation.Rd @@ -11,12 +11,14 @@ peakPantheRAnnotation( targetFeatTable = NULL, cpdID = character(), cpdName = character(), - ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = - numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), mzMax = - numeric(), stringsAsFactors = FALSE), - uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = - numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), + mzMin = numeric(), mz = numeric(), mzMax = numeric(), + stringsAsFactors = FALSE), + FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), + mzMax = numeric(), stringsAsFactors = FALSE), + uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), + mzMin = numeric(), mz = numeric(), mzMax = numeric(), + stringsAsFactors = FALSE), filepath = character(), cpdMetadata = data.frame(), spectraMetadata = data.frame(), @@ -36,12 +38,14 @@ peakPantheRAnnotation( targetFeatTable = NULL, cpdID = character(), cpdName = character(), - ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = - numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), - FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), mzMax = - numeric(), stringsAsFactors = FALSE), - uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), mzMin = - numeric(), mz = numeric(), mzMax = numeric(), stringsAsFactors = FALSE), + ROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), + mzMin = numeric(), mz = numeric(), mzMax = numeric(), + stringsAsFactors = FALSE), + FIR = data.frame(rtMin = numeric(), rtMax = numeric(), mzMin = numeric(), + mzMax = numeric(), stringsAsFactors = FALSE), + uROI = data.frame(rtMin = numeric(), rt = numeric(), rtMax = numeric(), + mzMin = numeric(), mz = numeric(), mzMax = numeric(), + stringsAsFactors = FALSE), filepath = character(), cpdMetadata = data.frame(), spectraMetadata = data.frame(), @@ -154,36 +158,38 @@ ROI as columns. \section{Slots}{ \describe{ -\item{\code{cpdID}}{A character vector of compound IDs, of length number of compounds} +\item{\code{cpdID}}{A character vector of compound IDs, of length number of +compounds} \item{\code{cpdName}}{A character vector of compound names, of length number of compounds} -\item{\code{ROI}}{A data.frame of Regions Of Interest (ROI) with compounds as row and -ROI parameters as columns: \code{rtMin} (float in seconds), \code{rt} (float -in seconds, or \emph{NA}), \code{rtMax} (float in seconds), \code{mzMin} +\item{\code{ROI}}{A data.frame of Regions Of Interest (ROI) with compounds as +row and ROI parameters as columns: \code{rtMin} (float in seconds), \code{rt} +(float in seconds, or \emph{NA}), \code{rtMax} (float in seconds), \code{mzMin} (float), \code{mz} (float or \emph{NA}), \code{mzMax} (float).} -\item{\code{FIR}}{A data.frame of Fallback Integration Regions (FIR) with compounds -as row and FIR parameters as columns: \code{rtMin} (float in seconds), +\item{\code{FIR}}{A data.frame of Fallback Integration Regions (FIR) with +compounds as row and FIR parameters as columns: \code{rtMin} (float in seconds), \code{rtMax} (float in seconds), \code{mzMin} (float), \code{mzMax} (float).} -\item{\code{uROI}}{A data.frame of updated Regions Of Interest (uROI) with compounds -as row and uROI parameters as columns: \code{rtMin} (float in seconds), -\code{rt} (float in seconds, or \emph{NA}), \code{rtMax} (float in seconds), -\code{mzMin} (float), \code{mz} (float or \emph{NA}), \code{mzMax} (float).} +\item{\code{uROI}}{A data.frame of updated Regions Of Interest (uROI) with +compounds as row and uROI parameters as columns: \code{rtMin} (float in +seconds), \code{rt} (float in seconds, or \emph{NA}), \code{rtMax} (float in +seconds), \code{mzMin} (float), \code{mz} (float or \emph{NA}), \code{mzMax} +(float).} -\item{\code{filepath}}{A character vector of file paths, of length number of spectra -files} +\item{\code{filepath}}{A character vector of file paths, of length number of +spectra files} -\item{\code{cpdMetadata}}{A data.frame of compound metadata, with compounds as row -and metadata as columns} +\item{\code{cpdMetadata}}{A data.frame of compound metadata, with compounds as +row and metadata as columns} -\item{\code{spectraMetadata}}{A data.frame of sample metadata, with samples as row -and metadata as columns} +\item{\code{spectraMetadata}}{A data.frame of sample metadata, with samples as +row and metadata as columns} -\item{\code{acquisitionTime}}{A character vector of acquisition date-time (converted -from POSIXct) or NA} +\item{\code{acquisitionTime}}{A character vector of acquisition date-time +(converted from POSIXct) or NA} \item{\code{uROIExist}}{A logical stating if uROI have been set} @@ -191,19 +197,21 @@ from POSIXct) or NA} \item{\code{useFIR}}{A logical stating if FIR are to be used} -\item{\code{TIC}}{A numeric vector of TIC or NA, of length number of spectra files} +\item{\code{TIC}}{A numeric vector of TIC or NA, of length number of spectra +files} -\item{\code{peakTables}}{A list of peakTable data.frame, of length number of spectra -files. Each peakTable data.frame has compounds as rows and peak annotation -results as columns.} +\item{\code{peakTables}}{A list of peakTable data.frame, of length number of +spectra files. Each peakTable data.frame has compounds as rows and peak +annotation results as columns.} -\item{\code{dataPoints}}{A list of length number of spectra files. Each list element -is a \emph{ROIsDataPoint} list of \code{data.frame} of raw data points for -each ROI/uROI (retention time 'rt', mass 'mz' and intensity 'int' (as column) -of each raw data points (as row))} +\item{\code{dataPoints}}{A list of length number of spectra files. Each list +element is a \emph{ROIsDataPoint} list of \code{data.frame} of raw data points +for each ROI/uROI (retention time 'rt', mass 'mz' and intensity 'int' +(as column) of each raw data points (as row))} -\item{\code{peakFit}}{A list of length number of spectra files. Each list element is -a \emph{curveFit} list of \code{peakPantheR_curveFit} or NA for each ROI} +\item{\code{peakFit}}{A list of length number of spectra files. Each list +element is a \emph{curveFit} list of \code{peakPantheR_curveFit} or NA for each +ROI} \item{\code{isAnnotated}}{A logical stating if the annotation has taken place diff --git a/man/peakPantheR_ROIStatistics.Rd b/man/peakPantheR_ROIStatistics.Rd index df107b1..2a23991 100644 --- a/man/peakPantheR_ROIStatistics.Rd +++ b/man/peakPantheR_ROIStatistics.Rd @@ -44,7 +44,8 @@ mean RT is not calculated and saved in \code{IS_mean_RT.csv})} \item{verbose}{(bool) If TRUE message progress} -\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel +processing. Must be a BiocParallelParam object} } \value{ None diff --git a/man/peakPantheR_parallelAnnotation.Rd b/man/peakPantheR_parallelAnnotation.Rd index a3b4cb0..ee5bef0 100644 --- a/man/peakPantheR_parallelAnnotation.Rd +++ b/man/peakPantheR_parallelAnnotation.Rd @@ -21,7 +21,8 @@ object defining the samples to process and compounds to target. The slots \code{useUROI} and \code{useFIR} controls if uROI must be used and FIR integrated if a feature is not found} -\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel processing. Must be a BiocParallelParam object} +\item{BPPARAM}{(BiocParallel::BiocParallelParam) Settings for parallel +processing. Must be a BiocParallelParam object} \item{nCores}{(int) Number of cores to use for parallelisation. Default 1 for no parallelisation.} From 9d2b6e43f9526e69991a01f88e7d1d20ed7628a6 Mon Sep 17 00:00:00 2001 From: Arnaud Wolfer Date: Mon, 11 Apr 2022 14:14:33 +0200 Subject: [PATCH 12/16] updated news --- inst/NEWS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/NEWS b/inst/NEWS index 3e72739..1dd62ee 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,2 +1,8 @@ +Changes in version 1.9.3 (2022-04-12) ++ Move to `BiocParallel` + +Changes in version 1.9.2 (2022-02-22) ++ GUI corrections and improvements (use of `bslib`) + Changes in version 1.9.1 (2021-12-18) + BiocCheck format update From 246fba8b6156b380d003f10ce6f8daf69cd4f278 Mon Sep 17 00:00:00 2001 From: Arnaud Wolfer Date: Mon, 11 Apr 2022 14:59:54 +0200 Subject: [PATCH 13/16] GUI chooser --- inst/shiny-GUI/peakPantheR-App/server.R | 2 +- inst/shiny-GUI/peakPantheR-App/ui.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/shiny-GUI/peakPantheR-App/server.R b/inst/shiny-GUI/peakPantheR-App/server.R index 00e9c40..7cc57bf 100644 --- a/inst/shiny-GUI/peakPantheR-App/server.R +++ b/inst/shiny-GUI/peakPantheR-App/server.R @@ -23,7 +23,6 @@ #require(shiny) - # increase upload size to 500MB options(shiny.maxRequestSize=500*1024^2) # define max number of parallel cores @@ -33,6 +32,7 @@ knownCurveModel <- c("skewedGaussian", "emgGaussian") shinyServer( function(input, output, session){ + bs_themer() # -- General Initialisation -- diff --git a/inst/shiny-GUI/peakPantheR-App/ui.R b/inst/shiny-GUI/peakPantheR-App/ui.R index 91e87f3..49d6807 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui.R +++ b/inst/shiny-GUI/peakPantheR-App/ui.R @@ -33,8 +33,8 @@ # update + refit in UI? -shinyUI(fluidPage(theme = bslib::bs_theme(bootswatch = "spacelab"), title='peakPantheR', - navbarPage(title = textOutput("peakPantheR_ver"), +shinyUI(fluidPage(theme = bslib::bs_theme(), title='peakPantheR', + navbarPage(theme = bslib::bs_theme(), title = textOutput("peakPantheR_ver"), inverse = FALSE, collapsible = TRUE, windowTitle = textOutput("peakPantheR_ver"), From 81a23329b145ea69255237dc2c210cbf45eb999f Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Mon, 18 Apr 2022 23:00:09 +0200 Subject: [PATCH 14/16] fix UI --- NAMESPACE | 2 +- R/peakPantheR_parallelAnnotation.R | 4 +- R/peakPantheR_start_GUI.R | 2 +- inst/shiny-GUI/peakPantheR-App/server.R | 2 - .../server/server_diagnostic.R | 6 ++- .../peakPantheR-App/server/server_export.R | 2 +- .../peakPantheR-App/server/server_import.R | 2 +- .../peakPantheR-App/server/server_run.R | 8 ++-- .../peakPantheR-App/ui/ui_diagnostic.R | 12 +++-- inst/shiny-GUI/peakPantheR-App/ui/ui_export.R | 10 ++-- inst/shiny-GUI/peakPantheR-App/ui/ui_import.R | 46 +++++++++++-------- inst/shiny-GUI/peakPantheR-App/ui/ui_run.R | 6 ++- 12 files changed, 59 insertions(+), 43 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e4e2fbd..3132588 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,7 +50,6 @@ exportMethods(useFIR) exportMethods(useUROI) import(BiocParallel) import(XML) -import(bslib) import(methods) import(mzR) import(scales) @@ -60,3 +59,4 @@ import(utils) importFrom(DT,DTOutput) importFrom(DT,datatable) importFrom(DT,renderDT) +importFrom(bslib,bs_theme) diff --git a/R/peakPantheR_parallelAnnotation.R b/R/peakPantheR_parallelAnnotation.R index f610828..ea0421f 100644 --- a/R/peakPantheR_parallelAnnotation.R +++ b/R/peakPantheR_parallelAnnotation.R @@ -275,7 +275,7 @@ parallelAnnotation_init <- function(object, BPPARAM, nCores, verbose) { validObject(object) nCores <- as.integer(nCores) - if (nCores < 0) { + if (nCores < 1) { stop("Check input, nCores must be a positive integer") } @@ -359,7 +359,7 @@ parallelAnnotation_process <- function(allFilesRes, object, verbose) { if ((sum(failures) != 0) & verbose) { message("----------------") message(sum(failures), " file(s) failed to process:\n", - paste0(capture.output(fail_table), collapse = "\n")) } + paste0(utils::capture.output(fail_table), collapse = "\n")) } # remove failures allFilesRes <- allFilesRes[!failures] # reshape the output object to match (remove failed samples) diff --git a/R/peakPantheR_start_GUI.R b/R/peakPantheR_start_GUI.R index 7e3a36d..86d15cb 100644 --- a/R/peakPantheR_start_GUI.R +++ b/R/peakPantheR_start_GUI.R @@ -16,7 +16,7 @@ #' #' @import BiocParallel #' @import shiny -#' @import bslib +#' @importFrom bslib bs_theme #' @import shinycssloaders #' @importFrom DT DTOutput renderDT datatable #' diff --git a/inst/shiny-GUI/peakPantheR-App/server.R b/inst/shiny-GUI/peakPantheR-App/server.R index bf298f1..a76609d 100644 --- a/inst/shiny-GUI/peakPantheR-App/server.R +++ b/inst/shiny-GUI/peakPantheR-App/server.R @@ -32,8 +32,6 @@ knownCurveModel <- c("skewedGaussian", "emgGaussian") shinyServer( function(input, output, session){ - bs_themer() - # -- General Initialisation -- # close app if tab is shut diff --git a/inst/shiny-GUI/peakPantheR-App/server/server_diagnostic.R b/inst/shiny-GUI/peakPantheR-App/server/server_diagnostic.R index f6e5744..599add3 100644 --- a/inst/shiny-GUI/peakPantheR-App/server/server_diagnostic.R +++ b/inst/shiny-GUI/peakPantheR-App/server/server_diagnostic.R @@ -50,7 +50,11 @@ output$table_fit_stat <- DT::renderDT ({ # UI block annotation fit statistic table output$annotationStatisticsTable <- renderUI ({ - DT::DTOutput("table_fit_stat") + fluidRow( + column(width = 12, offset = 0, + DT::DTOutput("table_fit_stat") + ) + ) }) diff --git a/inst/shiny-GUI/peakPantheR-App/server/server_export.R b/inst/shiny-GUI/peakPantheR-App/server/server_export.R index 0d9a4be..bca6591 100644 --- a/inst/shiny-GUI/peakPantheR-App/server/server_export.R +++ b/inst/shiny-GUI/peakPantheR-App/server/server_export.R @@ -200,7 +200,7 @@ output$controlExportPlotUI <- renderUI ({ output$cpuSliderDiag <- renderUI({ if(input$parallelisationDiag == 0) return(NULL) tagList( - sliderInput("ncoresDiag", label = paste("Available cores: ",maxCores,sep=""), min = 0, max = maxCores, value = maxCores, step=1) + sliderInput("ncoresDiag", label = paste("Available cores: ",maxCores,sep=""), min = 1, max = maxCores, value = maxCores, step=1) ) }) # correction when slider doesn't appear diff --git a/inst/shiny-GUI/peakPantheR-App/server/server_import.R b/inst/shiny-GUI/peakPantheR-App/server/server_import.R index 335301f..6116f56 100644 --- a/inst/shiny-GUI/peakPantheR-App/server/server_import.R +++ b/inst/shiny-GUI/peakPantheR-App/server/server_import.R @@ -134,7 +134,7 @@ output$showImportResult <- renderUI({ # import is successful } else if(importSuccess()=='yes') { # Capture the annotation shown and split by line into a list - tmp_text <- capture.output(show(values$annotation)) + tmp_text <- utils::capture.output(show(values$annotation)) tmp_text <- strsplit(tmp_text, '\n') # render the panel wellPanel( diff --git a/inst/shiny-GUI/peakPantheR-App/server/server_run.R b/inst/shiny-GUI/peakPantheR-App/server/server_run.R index fe106e3..e441a5e 100644 --- a/inst/shiny-GUI/peakPantheR-App/server/server_run.R +++ b/inst/shiny-GUI/peakPantheR-App/server/server_run.R @@ -60,9 +60,9 @@ output$alreadyAnnotatedUI <- renderUI({ output$useUROICheckbox <- renderUI({ # if uROI does not exist, strikethrough the label if (peakPantheR::uROIExist(values$annotation)) { - lbl <- p("use ", shiny::span(em("updated Regions of Interest"))) + lbl <- span("use ", shiny::span(em("updated Regions of Interest"))) } else { - lbl <- p(shiny::tags$s("use "), shiny::span(em(shiny::tags$s("updated Regions of Interest")))) + lbl <- span(shiny::tags$s("use "), shiny::span(em(shiny::tags$s("updated Regions of Interest")))) } # set the default value based on the annotation status tagList( @@ -78,7 +78,7 @@ output$useFIRCheckbox <- renderUI({ tagList( h5(HTML("FIR"), style="color:#3e648d;font-weight:bold"), checkboxInput("useFIR", - label = p("use ", shiny::span(em("Fallback Integration Regions"))), + label = span("use ", shiny::span(em("Fallback Integration Regions"))), value = peakPantheR::useFIR(values$annotation)) ) }) # TODO: CHECK FIR checkbox is activated correctly [cannot do the strikethrough] @@ -100,7 +100,7 @@ output$cpuSlider <- renderUI({ tagList( sliderInput("ncores", label = paste("Available cores: ",maxCores,sep=""), - min = 0, max = maxCores, value = maxCores, step=1 + min = 1, max = maxCores, value = maxCores, step=1 ) ) }) diff --git a/inst/shiny-GUI/peakPantheR-App/ui/ui_diagnostic.R b/inst/shiny-GUI/peakPantheR-App/ui/ui_diagnostic.R index f53d057..c5bf86d 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui/ui_diagnostic.R +++ b/inst/shiny-GUI/peakPantheR-App/ui/ui_diagnostic.R @@ -29,13 +29,15 @@ tabPanel("Diagnostic: plot & update", fluidRow( column(11, offset=1, h4('Fitting results across samples', style="color:#3e648d;font-weight:bold"), - helpText('Summary of peaks found and Fallback Integration Regions', shiny::span(em('(FIR, if applicable)')), 'for each targeted feature across all samples:', style="color:black"), + span('Summary of peaks found and Fallback Integration Regions', shiny::span(em('(FIR, if applicable)')), 'for each targeted feature across all samples:', style="color:black"), HTML("

Targeted features with a low ratio of peaks found, a large ppm error or a high RT deviation across samples, might benefit from a correction of the targeted rt and m/z used as uROI for example

"), ) # end column ) # end fluidRow ), # end wellPanel fluidRow( - uiOutput("annotationStatisticsTable") + column(12, + uiOutput("annotationStatisticsTable") + ) ) # end fluiRow (fit stat panel) ), # end tabPanel @@ -45,7 +47,7 @@ tabPanel("Diagnostic: plot & update", fluidRow( column(11, offset=1, h4('Update uROI and FIR', style="color:#3e648d;font-weight:bold"), - helpText('Based on the fit results, updated ROI', shiny::span(em('(uROI)')), 'and fallback integration region', shiny::span(em('(FIR)')), 'can be automatically determined:', style="color:black"), + span('Based on the fit results, updated ROI', shiny::span(em('(uROI)')), 'and fallback integration region', shiny::span(em('(FIR)')), 'can be automatically determined:', style="color:black"), HTML("
    "), HTML("
  • uROI are established as the min/max (rt and m/z) of the found peaks (+/- 5% in RT)
  • "), HTML("
  • FIR are established as the median of found rtMin, rtMax, mzMin, mzMax
  • "), @@ -56,7 +58,9 @@ tabPanel("Diagnostic: plot & update", ) # end fluidRow ), # end wellPanel fluidRow( - uiOutput("successUpdateDiagUI") # success message update uROI/FIR + column(12, + uiOutput("successUpdateDiagUI") # success message update uROI/FIR + ) ) # end fluiRow (success panel) ), # end tabPanel diff --git a/inst/shiny-GUI/peakPantheR-App/ui/ui_export.R b/inst/shiny-GUI/peakPantheR-App/ui/ui_export.R index 4f8aac8..3bff708 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui/ui_export.R +++ b/inst/shiny-GUI/peakPantheR-App/ui/ui_export.R @@ -23,7 +23,7 @@ tabPanel("Export results", column(4, wellPanel( h4("Save annotation as .rData:"), - helpText("Create a .RData file containing the annotation results as a peakPantheRAnnotation named ",em("annotationObject")," for future importation and analysis.", style="color:#666666"), + span("Create a .RData file containing the annotation results as a peakPantheRAnnotation named ",em("annotationObject")," for future importation and analysis.", style="color:#666666"), uiOutput("dlRData") ) # end wellPanel ), # end column @@ -32,7 +32,7 @@ tabPanel("Export results", fluidRow( column(5, h4("Save input parameters as .CSV:"), - helpText("Save the ", + span("Save the ", em("fit parameters")," defining the targeted features, the ", em("files to process")," defining file paths and spectra metadata, as well as the", em("targeted features metadata"), @@ -50,17 +50,17 @@ tabPanel("Export results", br(), h3("Export Annotation Results and Diagnostic Plots",style="color:#3e648d;font-weight:bold"), - helpText("Automated summarisation step (diagnostic and results), only possible if Shiny is running on a local machine.", style="color:#666666"), # See ",em("Code")," to run from the command line. + span("Automated summarisation step (diagnostic and results), only possible if Shiny is running on a local machine.", style="color:#666666"), # See ",em("Code")," to run from the command line. # Row export results fluidRow( column(6, h4("Save Diagnostic Plots:"), - helpText("Plots and save to disk a diagnotic plot for each targeted feature. Each spectra can be coloured based on one of the metadata column previously defined.", style="color:#666666") + span("Plots and save to disk a diagnotic plot for each targeted feature. Each spectra can be coloured based on one of the metadata column previously defined.", style="color:#666666") ), # end column column(6, h4("Save Annotation Values:"), - helpText("Saves the annotation results to disk in multiple ",em(".csv")," files containing the compound metadata, spectra metadata and a table for each annotation (fit) property", em("(samples as rows and compounds as columns)"), ".", style="color:#666666") + span("Saves the annotation results to disk in multiple ",em(".csv")," files containing the compound metadata, spectra metadata and a table for each annotation (fit) property", em("(samples as rows and compounds as columns)"), ".", style="color:#666666") ) # end column ), # end fluidRow Export results Text diff --git a/inst/shiny-GUI/peakPantheR-App/ui/ui_import.R b/inst/shiny-GUI/peakPantheR-App/ui/ui_import.R index 1b60223..40d3385 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui/ui_import.R +++ b/inst/shiny-GUI/peakPantheR-App/ui/ui_import.R @@ -12,35 +12,43 @@ tabPanel("Import Data", h4(HTML("Create a new peakPantheRAnnotation"), style="color:#3e648d;font-weight:bold"), wellPanel( fluidRow( - h5(HTML("Targeted features"), style="color:#3e648d;font-weight:bold"), - helpText("Select a .CSV file containing the ", shiny::span(strong("fit parameters")), shiny::span(em('with targeted features as rows and target windows as columns (at minimum: "cpdID", "cpdName", "rtMin", "rt", "rtMax", "mzMin", "mz", "mzMax")')),style="color:black"), - fileInput('CSVParamPath', 'Choose a .CSV File', - accept=c('text/csv','text/comma-separated-values,text/plain','.csv','.tsv')), - tags$hr() + column(12, + h5(HTML("Targeted features"), style="color:#3e648d;font-weight:bold")), + column(12, + span("Select a .CSV file containing the ", shiny::span(strong("fit parameters")), shiny::span(em('with targeted features as rows and target windows as columns (at minimum: "cpdID", "cpdName", "rtMin", "rt", "rtMax", "mzMin", "mz", "mzMax")')),style="color:black")), + column(12, + fileInput('CSVParamPath', 'Choose a .CSV File', + accept=c('text/csv','text/comma-separated-values,text/plain','.csv','.tsv'))), + tags$hr() ), # end fluidRow Fit params fluidRow( - h5(HTML("Files to process (choose one of two)"), style="color:#3e648d;font-weight:bold"), - column(width=6, - h6(HTML("File path only"), style="color:#3e648d;font-weight:bold"), - helpText("Select the ", shiny::span(strong("files to process")),style="color:black"), + column(12, + h5(HTML("Files to process (choose one of two)"), style="color:#3e648d;font-weight:bold") + ), #end title column + column(6, + h6(HTML("File path only"), style="color:#3e648d;font-weight:bold"), + span("Select the ", shiny::span(strong("files to process")),style="color:black"), fileInput('spectraPaths', 'Choose files to process', multiple=TRUE) ), # end left files selector column (only files) - column(width=6, - h6(HTML("File paths and metadata"), style="color:#3e648d;font-weight:bold"), - helpText(" Select a .CSV file containing the ", shiny::span(strong("file paths "), em("(column `filepath`)"), strong(" and metadata")), style="color:black"), + column(6, + h6(HTML("File paths and metadata"), style="color:#3e648d;font-weight:bold"), + span(" Select a .CSV file containing the ", shiny::span(strong("file paths "), em("(column `filepath`)"), strong(" and metadata")), style="color:black"), fileInput('spectraPathsWithMetadata', 'Choose a .CSV File', accept=c('text/csv','text/comma-separated-values,text/plain','.csv','.tsv')) - ) # end right file selector column (files + metadata) + ), # end right file selector column (files + metadata) + tags$hr() ), # end fluidRow File paths (either without or with metadata) fluidRow( - tags$hr(), - h5(HTML("Targeted features metadata (Optional)"), style="color:#3e648d;font-weight:bold"), - helpText("Select a .CSV file containing the ", shiny::span(strong("targeted features metadata")), style="color:black"), - fileInput('cpdMetadataPath', 'Choose a .CSV File', - accept=c('text/csv','text/comma-separated-values,text/plain','.csv','.tsv')) + column(12, + h5(HTML("Targeted features metadata (Optional)"), style="color:#3e648d;font-weight:bold")), + column(12, + span("Select a .CSV file containing the ", shiny::span(strong("targeted features metadata")), style="color:black")), + column(12, + fileInput('cpdMetadataPath', 'Choose a .CSV File', + accept=c('text/csv','text/comma-separated-values,text/plain','.csv','.tsv'))) ), # end FluidRow feature metadata fluidRow( @@ -57,7 +65,7 @@ tabPanel("Import Data", h4(HTML("Load a peakPantheRAnnotation"), style="color:#3e648d;font-weight:bold"), wellPanel( h5(HTML("Annotation"), style="color:#3e648d;font-weight:bold"), - helpText("Select a .RData file containing a ", shiny::span(strong("peakPantheRAnnotation")), " named", shiny::span(em("annotationObject")),style="color:black"), + span("Select a .RData file containing a ", shiny::span(strong("peakPantheRAnnotation")), " named", shiny::span(em("annotationObject")),style="color:black"), fluidRow( fileInput('pathAnnotation', 'Choose a .RData File', accept=c('application/octet-stream','.RData','.rdata')) diff --git a/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R b/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R index d55b01a..917cf6d 100644 --- a/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R +++ b/inst/shiny-GUI/peakPantheR-App/ui/ui_run.R @@ -34,7 +34,7 @@ tabPanel("Run annotation", # nCores cpuslider column(4, offset=1, checkboxInput("parallelisation", - label = p("Parallelisation", style="color:#3e648d;font-weight:bold"), + label = span("Parallelisation", style="color:#3e648d;font-weight:bold"), value = FALSE ), uiOutput("cpuSlider") @@ -54,7 +54,9 @@ tabPanel("Run annotation", # Success (green) / fail (red) row fluidRow( - uiOutput("successAnnotationUI") # error/success message + column(12, + uiOutput("successAnnotationUI") # error/success message + ) ) # end fluiRow (success panel) ) # end Main panel column ) # end fluidRow (sidebar + menu) From 80d31de01898d63fca8d49d471e15ac4ecb47353 Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Mon, 18 Apr 2022 23:37:08 +0200 Subject: [PATCH 15/16] correct failing example --- R/peakPantheR_ROIStatistics.R | 2 +- man/peakPantheR_ROIStatistics.Rd | 2 +- tests/testthat/test_peakPantheR_parallelAnnotation.R | 4 ++-- vignettes/parallel-annotation.Rmd | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/peakPantheR_ROIStatistics.R b/R/peakPantheR_ROIStatistics.R index d717eae..61aff75 100644 --- a/R/peakPantheR_ROIStatistics.R +++ b/R/peakPantheR_ROIStatistics.R @@ -56,7 +56,7 @@ #' # Calculate ROI statiscs #' peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, #' IS_ROI=input_IS_ROI, sampleColour=sampleColour, -#' nCores=0, saveISPlots=TRUE, verbose=TRUE) +#' nCores=1, saveISPlots=TRUE, verbose=TRUE) #' } peakPantheR_ROIStatistics <- function(referenceSpectraFiles, saveFolder, ROI = NULL, IS_ROI = NULL, diff --git a/man/peakPantheR_ROIStatistics.Rd b/man/peakPantheR_ROIStatistics.Rd index 2a23991..6d048de 100644 --- a/man/peakPantheR_ROIStatistics.Rd +++ b/man/peakPantheR_ROIStatistics.Rd @@ -86,6 +86,6 @@ saveFolder1 <- tempdir() # Calculate ROI statiscs peakPantheR_ROIStatistics(refSpecFiles, saveFolder1, ROI=input_ROI, IS_ROI=input_IS_ROI, sampleColour=sampleColour, - nCores=0, saveISPlots=TRUE, verbose=TRUE) + nCores=1, saveISPlots=TRUE, verbose=TRUE) } } diff --git a/tests/testthat/test_peakPantheR_parallelAnnotation.R b/tests/testthat/test_peakPantheR_parallelAnnotation.R index 1249a2e..ac4b410 100644 --- a/tests/testthat/test_peakPantheR_parallelAnnotation.R +++ b/tests/testthat/test_peakPantheR_parallelAnnotation.R @@ -558,7 +558,7 @@ test_that('catch file that doesnt exist, catch error processing, no file left', expected_message <- c("Processing 4 compounds in 2 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "Error file does not exist: aaa/bbb.cdf\n", "----- test_fakemzML -----\n", "-----\n", "Error processing file: test_fakemzML\n", "\n-----\n", "----------------\n", "No file left in the object!\n", "Annotation object reordered by sample acquisition date\n", "----------------\n", " 2 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -681,7 +681,7 @@ test_that('curveModel unknown: 3 failures', { expected_message <- character(0) # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, ncores=0, getAcquTime=FALSE, verbose=FALSE, curveModel='unknown_curveModel')) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE, curveModel='unknown_curveModel')) # Check results (all failures) expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) diff --git a/vignettes/parallel-annotation.Rmd b/vignettes/parallel-annotation.Rmd index c99abb5..62f4886 100644 --- a/vignettes/parallel-annotation.Rmd +++ b/vignettes/parallel-annotation.Rmd @@ -492,7 +492,7 @@ features: ```{r} # annotate files serially new_annotation_result <- peakPantheR_parallelAnnotation(new_annotation, - ncores=0, verbose=FALSE) + nCores=1, verbose=FALSE) # successful fit nbSamples(new_annotation_result$annotation) From a3700f1b9fc76b47769cf0b4af22b3b37ecfbafc Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Wed, 20 Apr 2022 01:03:29 +0200 Subject: [PATCH 16/16] updated unittests --- ...tation_outputAnnotationDiagnostic-method.R | 3 +- .../testthat/test_peakPantheR_ROIStatistics.R | 13 +- .../test_peakPantheR_parallelAnnotation.R | 169 +++++++++++------- 3 files changed, 117 insertions(+), 68 deletions(-) diff --git a/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R b/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R index 4862a99..ab72299 100644 --- a/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R +++ b/tests/testthat/test_peakPantheRAnnotation_outputAnnotationDiagnostic-method.R @@ -143,6 +143,7 @@ test_that('default output, with plots and colours, serial, verbose, no verbose', expect_equal(length(result_save2$messages), 0) }) +if (.Platform$OS.type != "windows") { test_that('default output, with plots and colours, parallel, verbose, no verbose', { # temporary file savePath3 <- tempdir() @@ -189,7 +190,7 @@ test_that('default output, with plots and colours, parallel, verbose, no verbose sampleColour=input_colour, verbose=FALSE, nCores=1, BPPARAM=BPParam) ) expect_equal(length(result_save4$messages), 0) -}) +}) } test_that('no plot saved, verbose', { # temporary file diff --git a/tests/testthat/test_peakPantheR_ROIStatistics.R b/tests/testthat/test_peakPantheR_ROIStatistics.R index 4de00fd..ef47bae 100644 --- a/tests/testthat/test_peakPantheR_ROIStatistics.R +++ b/tests/testthat/test_peakPantheR_ROIStatistics.R @@ -288,7 +288,9 @@ test_that('parallel give the same result: 3 files, no save EICs, mean IS RT, sav # results (output, warnings and messages) if (.Platform$OS.type == "windows") { BPParam <- BiocParallel::SnowParam(1) - } else {BPParam <- BiocParallel::MulticoreParam(1) } + } else { + BPParam <- BiocParallel::MulticoreParam(1) + } result_ROIstats_parallel <- evaluate_promise(peakPantheR_ROIStatistics(refSpecFiles, saveFolder6, ROI=NULL, IS_ROI=input_IS_ROI, sampleColour=sampleColour, nCores=1, BPPARAM=BPParam, saveISPlots=TRUE, verbose=TRUE)) @@ -298,13 +300,20 @@ test_that('parallel give the same result: 3 files, no save EICs, mean IS RT, sav expect_true(file.exists(expected_path_IS_plot2)) expect_true(file.exists(expected_path_IS_plot3)) expect_true(file.exists(expected_path_IS_plot4)) + # Check mean IS RT expect_true(file.exists(expected_path_CSV)) saved_CSV <- read.csv(expected_path_CSV, header=TRUE, sep=",", quote="\"", stringsAsFactors=FALSE) expect_equal(saved_CSV, expected_meanIS, tolerance=1e-4) + # Check messages (no filepaths) - expect_equal(length(result_ROIstats_parallel$messages), 20) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_ROIstats_parallel$messages), 21) + expect_equal(result_ROIstats_parallel$messages[c(1,2,4:8, 10,11, 13,20)], expected_message_parallel) + } else { + expect_equal(length(result_ROIstats_parallel$messages), 20) expect_equal(result_ROIstats_parallel$messages[c(1,2,4:10,12,19)], expected_message_parallel) + } }) test_that('raise errors', { diff --git a/tests/testthat/test_peakPantheR_parallelAnnotation.R b/tests/testthat/test_peakPantheR_parallelAnnotation.R index ac4b410..9281d98 100644 --- a/tests/testthat/test_peakPantheR_parallelAnnotation.R +++ b/tests/testthat/test_peakPantheR_parallelAnnotation.R @@ -110,6 +110,14 @@ ROIDataPoints3 <- extractSignalRawData(tmp_raw_data3, rt=input_targetFeatTabl expected_dataPoints <- list(ROIDataPoints1, ROIDataPoints2, ROIDataPoints3) +# Set parallel configuration (single core) based on OS, as otherwise nCores==1 triggers serial +if (.Platform$OS.type == 'windows') { + BPPARAM_parallel <- BiocParallel::SnowParam(workers = 1) +} else { + BPPARAM_parallel <- BiocParallel::MulticoreParam(workers = 1) +} + + if ((.Platform$OS.type != "windows") || (.Machine$sizeof.pointer == 8)) { test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { # Object fully initialised @@ -128,20 +136,24 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (No message returned in parallel on linux (MulticoreParam)) + expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) - # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 3) - expect_equal(result_parallelAnnotation$messages, expected_message) - }) } + # Check messages (centwave output)(Windows is more verbose) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } +}) } if ((.Platform$OS.type != "windows") || (.Machine$sizeof.pointer == 8)) { test_that('3 files (1 missing), 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { @@ -162,20 +174,24 @@ test_that('3 files (1 missing), 4 compounds, no uROI, no FIR, no getAcquTime, no tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (No message returned in parallel on linux (MulticoreParam)) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) expect_equal(result_parallelAnnotation$result$failures, expected_failures) - # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 2) - expect_equal(result_parallelAnnotation$messages, expected_message) - }) } + # Check messages (centwave output)(Windows is more verbose) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } +}) } test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, modify parameter with ... (cpd #3)', { # Cpd 3 is now found in 3rd file @@ -219,19 +235,23 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, mo tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (Windows only, no message in Linux MulticoreParam) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE, params=new_params)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE, params=new_params)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 3) - expect_equal(result_parallelAnnotation$messages, expected_message) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } }) test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, peaks not found and not replaced (cpd #3)', { @@ -270,19 +290,23 @@ test_that('3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose, pe tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (Windows only, no message in Linux MulticoreParam) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 3) - expect_equal(result_parallelAnnotation$messages, expected_message) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } }) test_that('3 files, 4 compounds, no uROI, FIR replace peaks not found (cpd #3), no getAcquTime, no verbose', { @@ -322,19 +346,23 @@ test_that('3 files, 4 compounds, no uROI, FIR replace peaks not found (cpd #3), tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (Windows only, no message in Linux MulticoreParam) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 3) - expect_equal(result_parallelAnnotation$messages, expected_message) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } }) if ((.Platform$OS.type != "windows") || (.Machine$sizeof.pointer == 8)) { @@ -355,20 +383,24 @@ test_that('3 files, 4 compounds, uROI, no FIR, no fitGauss, no getAcquTime, no v tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n") + # Expected message (Windows only, no message in Linux MulticoreParam) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=0, getAcquTime=FALSE, verbose=FALSE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) - # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 3) - expect_equal(result_parallelAnnotation$messages, expected_message) - }) } + # Check messages (centwave output)(Windows is more verbose) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } +}) } test_that('serial: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { # sample 2 is missing @@ -457,22 +489,24 @@ test_that('parallel: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks expected_message <- c("Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "----------------\n" , "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") - if (.Platform$OS.type == "windows") { - BPParam <- BiocParallel::SnowParam(1) - } else {BPParam <- BiocParallel::MulticoreParam(1) } # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=BPParam, getAcquTime=TRUE, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation,BPPARAM=BPPARAM_parallel, getAcquTime=TRUE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) expect_equal(result_parallelAnnotation$result$failures, expected_failures) - # Check messages (no timing) - expect_equal(length(result_parallelAnnotation$messages), 9) - expect_equal(result_parallelAnnotation$messages[c(1:7, 9)], expected_message) + # Check messages (no timing) (Windows is more verbose) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 10) + expect_equal(result_parallelAnnotation$messages[c(1:3, 5:8, 10)], expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 9) + expect_equal(result_parallelAnnotation$messages[c(1:7, 9)], expected_message) + } }) -test_that('serial and parallel give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { +test_that('serial and parallel give the same result: 3 files, (1 missing), 4 compounds, uROI, FIR replace peaks not found (cpd #3), getAcquTime, verbose', { # sample 2 is missing # Cpd #3 will not give results noMatch_uROI3 <- input_uROI @@ -484,11 +518,7 @@ test_that('serial and parallel give the same result: 3 files, (1 missing), 4 co # results result_serial <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=TRUE, verbose=TRUE)) - if (.Platform$OS.type == "windows") { - BPParam <- BiocParallel::SnowParam(1) - } else {BPParam <- BiocParallel::MulticoreParam(1) } - result_parallel <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, BPPARAM=BPParam, - getAcquTime=TRUE, verbose=TRUE)) + result_parallel <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=TRUE, verbose=TRUE)) # Check results expect_equal(result_serial$result, result_parallel$result, tolerance=1e-6) @@ -535,7 +565,7 @@ test_that('already annotated message in verbose', { expected_message <- c("!! Data was already annotated, results will be overwritten !!\n", "Processing 4 compounds in 3 samples:\n", " uROI:\tTRUE\n", " FIR:\tTRUE\n", "----- ko15 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Fit of ROI #3 is unsuccessful (try err)\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "Error file does not exist: aaa/bbb.cdf\n", "----- ko18 -----\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Check input, mzMLPath must be a .mzML\n", "Reading data from 4 windows\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #1\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #2\n", "Fit of ROI #3 is unsuccessful (try err)\n", "Warning: rtMin/rtMax outside of ROI; datapoints cannot be used for mzMin/mzMax calculation, approximate mz and returning ROI$mzMin and ROI$mzMax for ROI #4\n", "1 features to integrate with FIR\n", "Reading data from 1 windows\n", "----------------\n", "1 file(s) failed to process:\n file error\n1 aaa/bbb.cdf Error file does not exist: aaa/bbb.cdf\n", "Annotation object cannot be reordered by sample acquisition date\n", "----------------\n", " 1 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=TRUE, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores = 1, getAcquTime=TRUE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -554,11 +584,11 @@ test_that('catch file that doesnt exist, catch error processing, no file left', # Expected annotation expected_annotation <- initAnnotation[c(FALSE, FALSE),] expected_annotation@isAnnotated <- FALSE - # Expected message - expected_message <- c("Processing 4 compounds in 2 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "Error file does not exist: aaa/bbb.cdf\n", "----- test_fakemzML -----\n", "-----\n", "Error processing file: test_fakemzML\n", "\n-----\n", "----------------\n", "No file left in the object!\n", "Annotation object reordered by sample acquisition date\n", "----------------\n", " 2 failure(s)\n") + # Expected message (have to remove Error file does not exist as it now returns a path) + expected_message <- c("Processing 4 compounds in 2 samples:\n", " uROI:\tFALSE\n", " FIR:\tFALSE\n", "----------------\n", "No file left in the object!\n", "Annotation object reordered by sample acquisition date\n", "----------------\n", " 2 failure(s)\n") # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=TRUE)) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=TRUE)) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-6) @@ -566,9 +596,14 @@ test_that('catch file that doesnt exist, catch error processing, no file left', expect_equal(dim(result_parallelAnnotation$result$failures)[1], 2) expect_equal(dim(result_parallelAnnotation$result$failures)[2], 2) - # Check messages (remove timing and paths in error messages) - expect_equal(length(result_parallelAnnotation$messages), 16) - expect_equal(result_parallelAnnotation$messages[c(1:7, 9, 10, 12, 13, 14, 16)], expected_message) + # Check messages (no timing) (Windows is more verbose) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 11) + expect_equal(result_parallelAnnotation$messages[c(1:3, 5, 7:9, 11)], expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 10) + expect_equal(result_parallelAnnotation$messages[c(1:4, 6:8, 10)], expected_message) + } }) test_that('curveModel emgGaussian: 3 files, 4 compounds, no uROI, no FIR, no getAcquTime, no verbose', { @@ -643,20 +678,24 @@ test_that('curveModel emgGaussian: 3 files, 4 compounds, no uROI, no FIR, no get tmp_failures <- !is.na(tmp_status) names(tmp_failures) <- NULL expected_failures <- data.frame(matrix(c(names(tmp_status)[tmp_failures], tmp_status[tmp_failures]), ncol=2, byrow=FALSE, dimnames=list(c(), c('file', 'error'))), stringsAsFactors=FALSE) - # Expected message - expected_message <- c("Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\n", "Fit of ROI #3 is unsuccessful (cannot determine rtMin/rtMax)\n") + # Expected message (Windows only, no message in Linux MulticoreParam) + expected_message <- "Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nPolarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method.\nFit of ROI #3 is unsuccessful (cannot determine rtMin/rtMax)\n\n" # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE, curveModel='emgGaussian')) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE, curveModel='emgGaussian')) # Check results expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) expect_equal(result_parallelAnnotation$result$failures, expected_failures) # Check messages (centwave output) - expect_equal(length(result_parallelAnnotation$messages), 4) - expect_equal(result_parallelAnnotation$messages, expected_message) - }) + if (.Platform$OS.type == 'windows') { + expect_equal(length(result_parallelAnnotation$messages), 1) + expect_equal(result_parallelAnnotation$messages, expected_message) + } else { + expect_equal(length(result_parallelAnnotation$messages), 0) + } +}) test_that('curveModel unknown: 3 failures', { # Object fully initialised @@ -681,7 +720,7 @@ test_that('curveModel unknown: 3 failures', { expected_message <- character(0) # results (output, warnings and messages) - result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, nCores=1, getAcquTime=FALSE, verbose=FALSE, curveModel='unknown_curveModel')) + result_parallelAnnotation <- evaluate_promise(peakPantheR_parallelAnnotation(initAnnotation, BPPARAM=BPPARAM_parallel, getAcquTime=FALSE, verbose=FALSE, curveModel='unknown_curveModel')) # Check results (all failures) expect_equal(result_parallelAnnotation$result$annotation, expected_annotation, tolerance=1e-5) @@ -690,7 +729,7 @@ test_that('curveModel unknown: 3 failures', { # Check messages (no fit, so no message) expect_equal(length(result_parallelAnnotation$messages), 0) expect_equal(result_parallelAnnotation$messages, expected_message) - }) +}) test_that('raise errors', { # Object fails validation on input check @@ -704,7 +743,7 @@ test_that('raise errors', { msg2 <- "Check input, BPPARAM must be a BiocParallel Param object" expect_error(peakPantheR_parallelAnnotation(initAnnotation2, nCores=1, getAcquTime=FALSE, BPPARAM='not a BiocParallelParam object', verbose=FALSE), msg2, fixed=TRUE) - # nCores is < 0 + # nCores is < 1 initAnnotation3 <- peakPantheRAnnotation(spectraPaths=input_spectraPaths, targetFeatTable=input_targetFeatTable) msg3 <- "Check input, nCores must be a positive integer" expect_error(peakPantheR_parallelAnnotation(initAnnotation3, nCores=-10, getAcquTime=FALSE, verbose=FALSE), msg3, fixed=TRUE)