Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to BiocParallel #32

Open
wants to merge 21 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a40cf78
- BiocParallel implementation - no resetWorkers arg
Gscorreia89 Mar 31, 2022
c1136af
- BiocParallel implementation - no resetWorkers arg
Gscorreia89 Mar 31, 2022
b0f2540
- BiocParallel implementation: unittest changes
Gscorreia89 Apr 5, 2022
bb4647f
- BiocParallel implementation: unittest changes
Gscorreia89 Apr 6, 2022
53e3c97
- BiocParallel implementation: update to continuum parallel annotatio…
Gscorreia89 Apr 6, 2022
c692d28
- BiocParallel implementation: update to continuum parallel annotatio…
Gscorreia89 Apr 6, 2022
a76f38c
- BiocParallel implementation: import and argument fixes in doc comments
Gscorreia89 Apr 7, 2022
f760a64
- BiocParallel implementation: import and argument fixes in doc comments
Gscorreia89 Apr 7, 2022
3786866
update GUI to bslib instead of shinythemes
adwolfer Apr 9, 2022
688ef0c
BiocChecks
adwolfer Apr 11, 2022
e9964f7
BiocChecks
adwolfer Apr 11, 2022
9d2b6e4
updated news
adwolfer Apr 11, 2022
246fba8
GUI chooser
adwolfer Apr 11, 2022
c1ef76e
Merge remote-tracking branch 'origin/develop' into feature/BiocParallel
adwolfer Apr 18, 2022
81a2332
fix UI
adwolfer Apr 18, 2022
80d31de
correct failing example
adwolfer Apr 18, 2022
a3700f1
updated unittests
adwolfer Apr 19, 2022
cb852f3
Merge branch 'develop' into feature/BiocParallel
adwolfer Apr 19, 2022
e96bf65
Merge branch 'develop' into feature/BiocParallel
adwolfer May 1, 2022
919af8b
Merge branch 'devel' into feature/BiocParallel
adwolfer Mar 28, 2023
e967398
Merge branch 'devel' of https://github.com/phenomecentre/peakPantheR …
Gscorreia89 Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.rulers": [
80, 120
]
}
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Description: An automated pipeline for the detection, integration and reporting
Depends:
R (>= 4.2)
Imports:
foreach (>= 1.4.4),
doParallel (>= 1.0.11),
ggplot2 (>= 3.5.0),
gridExtra (>= 2.3),
MSnbase (>= 2.4.0),
Expand All @@ -28,6 +26,7 @@ Imports:
shinycssloaders (>= 1.0.0),
DT (>= 0.15),
pracma (>= 2.2.3),
BiocParallel (>= 1.28.3),
utils,
lubridate,
svglite (>= 2.1.1)
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ exportMethods(uROI)
exportMethods(uROIExist)
exportMethods(useFIR)
exportMethods(useUROI)
import(BiocParallel)
import(XML)
import(doParallel)
import(foreach)
import(methods)
import(mzR)
import(scales)
Expand Down
68 changes: 44 additions & 24 deletions R/methods_peakPantheRAnnotation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, svgPlot = FALSE, ...)
verbose = TRUE, nCores = 1, BPPARAM=NULL, svgPlot = FALSE, ...)
standardGeneric("outputAnnotationDiagnostic"))
#' @title Save to disk the annotation parameters as CSV and a diagnostic plot
#' per fitted compound
Expand All @@ -1612,7 +1612,9 @@ 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 svgPlot (bool) If TRUE save plots as 'svg', otherwise as 'png'
#' @param ... Additional parameters for plotting i.e. \code{sampling} for the
#' number of points to employ when plotting fittedCurve
Expand Down Expand Up @@ -1647,7 +1649,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
Expand All @@ -1656,8 +1658,8 @@ setGeneric("outputAnnotationDiagnostic",
#' verbose=TRUE)
#' }
setMethod("outputAnnotationDiagnostic", "peakPantheRAnnotation",
function(object, saveFolder, savePlots, sampleColour, verbose, ncores,
svgPlot,...) {
function(object, saveFolder, savePlots, sampleColour, verbose, nCores,
BPPARAM, svgPlot, ...) {
# Save standardised csv
outputAnnotationParamsCSV(object, saveFolder = saveFolder,verbose = verbose)

Expand All @@ -1668,23 +1670,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, svgPlot = svgPlot, ...)
# Close
parallel::stopCluster(cl)
if (verbose) { message("All plots saved") }
nCores <- as.integer(nCores)
if (nCores < 0) {
stop("Check input, nCores must be a positive integer")
}
# Handle default BPParam
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, svgPlot = svgPlot, ...)
# Close parallel interface
BiocParallel::bpstop(BPPARAM)
if (verbose) { message("All plots saved") }

# run serial
} else {
Expand Down Expand Up @@ -1794,7 +1814,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
Expand Down Expand Up @@ -2437,7 +2457,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
Expand Down
3 changes: 1 addition & 2 deletions R/peakPantheR.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
#' @docType package
#' @name peakPantheR
#'
#' @import foreach
#' @import doParallel
#' @import BiocParallel
#'
"_PACKAGE"
#> [1] "_PACKAGE"
Expand Down
19 changes: 11 additions & 8 deletions R/peakPantheR_ROIStatistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#' (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
Expand Down Expand Up @@ -54,12 +56,13 @@
#' # 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,
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)
Expand All @@ -77,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)
IS_ROI, saveISPlots, nCores, sampleColour, verbose, BPPARAM)
}
}

Expand Down Expand Up @@ -239,23 +242,23 @@ 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 --")
}
IS_annotation <- peakPantheRAnnotation(
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
if (saveISPlots) {
outputAnnotationDiagnostic(IS_annotation,
saveFolder = file.path(saveFolder, "IS_search"),
savePlots = TRUE, sampleColour=sampleColour, verbose = verbose,
ncores = ncores)
nCores = nCores)
}

# calculate statistics
Expand Down
Loading
Loading