From 25560f7fd0c5e8d6151fe33db8f2b05306f52eba Mon Sep 17 00:00:00 2001 From: Jack Miller Date: Sun, 11 Jun 2023 12:58:11 +0200 Subject: [PATCH 01/23] Added two helper functions: for ASICS quantification and for a library of NMR autophasing techniques. --- DESCRIPTION | 9 ++- NAMESPACE | 2 + NEWS.md | 3 + R/asics_helpers.R | 77 +++++++++++++++++++++ man/AlpsNMR-package.Rd | 1 + man/alps_asics.Rd | 27 ++++++++ man/nmr_dataset_autophase.Rd | 38 ++++++++++ tests/testthat/test-autophase.R | 6 ++ tests/testthat/test-for_asics.R | 8 +++ vignettes/Vig01-introduction-to-alpsnmr.Rmd | 12 ++++ 10 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 R/asics_helpers.R create mode 100644 man/alps_asics.Rd create mode 100644 man/nmr_dataset_autophase.Rd create mode 100644 tests/testthat/test-autophase.R create mode 100644 tests/testthat/test-for_asics.R diff --git a/DESCRIPTION b/DESCRIPTION index 350618b3..86050518 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,7 +39,12 @@ Authors@R: c( person(given = "Nestlé Institute of Health Sciences", role = "cph"), person(given = "Institute for Bioengineering of Catalonia", - role = "cph") + role = "cph"), + person(given = "Miller", + family = "Jack", + email = "jack.miller@physics.org", + role=c("ctb"), + comment = c(ORCID = "0000-0002-6258-1299")) ) Description: Reads Bruker NMR data directories both zipped and unzipped. It provides automated and efficient signal processing for untargeted @@ -87,6 +92,7 @@ Imports: vctrs (>= 0.3.0), BiocParallel Suggests: + ASICS, BiocStyle, ChemoSpec, cowplot, @@ -96,6 +102,7 @@ Suggests: ggrepel (>= 0.8.0), gridExtra, knitr, + NMRphasing, plotly (>= 4.7.1), progressr, SummarizedExperiment, diff --git a/NAMESPACE b/NAMESPACE index efd17220..cc3aef3e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,6 +31,7 @@ export("nmr_data<-") export(.DollarNames) export(SummarizedExperiment_to_nmr_data_1r) export(SummarizedExperiment_to_nmr_dataset_peak_table) +export(alps_asics) export(bp_VIP_analysis) export(bp_kfold_VIP_analysis) export(download_MTBLS242) @@ -63,6 +64,7 @@ export(nmr_build_peak_table) export(nmr_data) export(nmr_data_1r_to_SummarizedExperiment) export(nmr_data_analysis) +export(nmr_dataset_autophase) export(nmr_dataset_load) export(nmr_dataset_peak_table_to_SummarizedExperiment) export(nmr_dataset_save) diff --git a/NEWS.md b/NEWS.md index ef1298b1..0982ad52 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# AlpsNMR 4.1.6a (2024-01-19) +- Added two helper functions for autophasing via NMRphasing and export to ASICS + # AlpsNMR 4.1.6 (2023-02-16) - Download improvements: diff --git a/R/asics_helpers.R b/R/asics_helpers.R new file mode 100644 index 00000000..847259bd --- /dev/null +++ b/R/asics_helpers.R @@ -0,0 +1,77 @@ +#' @title Perform an automatic 1D NMR phasing +#' @description +#' It is quite often the case that (e.g. Bruker's) 1D autophase isn't quite right. +#' This uses `NMRphasing::NMRphasing` to automatically rephase data in the spectral domain. +#' A number of algorithms are available (see NMRphasing's documentation), +#' of which NLS, MPC_DANM and SPC_DANM are the most recent. +#' +#' Perhaps obviously, you are likely to get better results loading the complex data +#' than having real-only spectra (i.e. pass `all_components = T` to `nmr_read_samples`). +#' +#' Run this before spectral interpolation. +#' +#' @param samples An `nmr_dataset_family` 1D object +#' @param method The autophasing method -- see `NMRphasing::NMRphasing` for details. +#' @return A (hopefully better phased) `nmr_dataset_family` 1D object, with updated real and imaginary parts. +#' @examples +#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset) +#' dataset <- nmr_dataset_autophase(dataset,method="MPC_DANM") +#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +#' plot(dataset) +#' +#' @export +nmr_dataset_autophase <- function(samples, method= c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM")) { + + method <- match.arg(method) + BiocParallel::bplapply(seq_len(length(samples[["data_1r"]])), function(i) { + + data_to_phase <- if("data_1i" %in% objects(samples)) { + complex(real = samples[["data_1r"]][[i]], + imaginary = samples[["data_1i"]][[i]], + length.out = length(samples[["data_1r"]][[i]] + )) + } else { + samples[["data_1r"]][[i]] + } + + phased_data <- NMRphasing::NMRphasing(data_to_phase, method = method, + absorptionOnly = !"data_1i" %in% objects(samples)) + + if("data_1i" %in% objects(samples)) { + samples[["data_1r"]][[i]] <- Re(phased_data) + samples[["data_1i"]][[i]] <- Im(phased_data) + } else { + samples[["data_1r"]][[i]] <- phased_data + } + + }) + + return(samples) +} + +#' @title Export data for the spectral quantification library ASICS +#' @description +#' A simple helper function for mangling data in the right format for the +#' spectral quantification library ASICS. +#' +#' @param samples An `nmr_dataset_family` 1D object +#' @param ... Additional arguments are passed +#' directly to `ASICS::createSpectra`, which (in theory) provide an +#' opportunity to use distinct normalisation methods. +#' +#' @return An `ASICS::Spectra` object +#' @examples +#' # forAsics <- alps_asics(dataset) +#' # ASICS(forAsics) +#' +#' @export + +alps_asics <- function(samples, ...) { + forAsics <- t(nmr_data(samples)) + forAsics <- ASICS::createSpectra(forAsics, ...) + forAsics@sample.name <-samples$metadata$external$NMRExperiment + return(forAsics) +} + + diff --git a/man/AlpsNMR-package.Rd b/man/AlpsNMR-package.Rd index a3c6b7e1..0ca81026 100644 --- a/man/AlpsNMR-package.Rd +++ b/man/AlpsNMR-package.Rd @@ -60,6 +60,7 @@ Other contributors: \item Laura López Sánchez [contributor] \item Nestlé Institute of Health Sciences [copyright holder] \item Institute for Bioengineering of Catalonia [copyright holder] + \item Miller Jack \email{jack.miller@physics.org} (\href{https://orcid.org/0000-0002-6258-1299}{ORCID}) [contributor] } } diff --git a/man/alps_asics.Rd b/man/alps_asics.Rd new file mode 100644 index 00000000..4deda0a6 --- /dev/null +++ b/man/alps_asics.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/asics_helpers.R +\name{alps_asics} +\alias{alps_asics} +\title{Export data for the spectral quantification library ASICS} +\usage{ +alps_asics(samples, ...) +} +\arguments{ +\item{samples}{An \code{nmr_dataset_family} 1D object} + +\item{...}{Additional arguments are passed +directly to \code{ASICS::createSpectra}, which (in theory) provide an +opportunity to use distinct normalisation methods.} +} +\value{ +An \code{ASICS::Spectra} object +} +\description{ +A simple helper function for mangling data in the right format for the +spectral quantification library ASICS. +} +\examples{ +# forAsics <- alps_asics(dataset) +# ASICS(forAsics) + +} diff --git a/man/nmr_dataset_autophase.Rd b/man/nmr_dataset_autophase.Rd new file mode 100644 index 00000000..5c8cfa86 --- /dev/null +++ b/man/nmr_dataset_autophase.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/asics_helpers.R +\name{nmr_dataset_autophase} +\alias{nmr_dataset_autophase} +\title{Perform an automatic 1D NMR phasing} +\usage{ +nmr_dataset_autophase( + samples, + method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM") +) +} +\arguments{ +\item{samples}{An \code{nmr_dataset_family} 1D object} + +\item{method}{The autophasing method -- see \code{NMRphasing::NMRphasing} for details.} +} +\value{ +A (hopefully better phased) \code{nmr_dataset_family} 1D object, with updated real and imaginary parts. +} +\description{ +It is quite often the case that (e.g. Bruker's) 1D autophase isn't quite right. +This uses \code{NMRphasing::NMRphasing} to automatically rephase data in the spectral domain. +A number of algorithms are available (see NMRphasing's documentation), +of which NLS, MPC_DANM and SPC_DANM are the most recent. + +Perhaps obviously, you are likely to get better results loading the complex data +than having real-only spectra (i.e. pass \code{all_components = T} to \code{nmr_read_samples}). + +Run this before spectral interpolation. +} +\examples{ +dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +dataset <- nmr_read_samples_dir(dir_to_demo_dataset) +dataset <- nmr_dataset_autophase(dataset,method="MPC_DANM") +dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +plot(dataset) + +} diff --git a/tests/testthat/test-autophase.R b/tests/testthat/test-autophase.R new file mode 100644 index 00000000..0546fe25 --- /dev/null +++ b/tests/testthat/test-autophase.R @@ -0,0 +1,6 @@ +test_that("nmr_dataset_autophase works", { + skip_if_not_installed("NMRphasing") + dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") + dataset <- nmr_read_samples_dir(dir_to_demo_dataset) + nmr_dataset_autophase(dataset, method="NLS") +}) \ No newline at end of file diff --git a/tests/testthat/test-for_asics.R b/tests/testthat/test-for_asics.R new file mode 100644 index 00000000..42622a57 --- /dev/null +++ b/tests/testthat/test-for_asics.R @@ -0,0 +1,8 @@ +test_that("alps_asics works", { + skip_if_not_installed("ASICS") + dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") + dataset <- nmr_read_samples_dir(dir_to_demo_dataset) + dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) + spec_obj <- alps_asics(dataset) + expect_true(class(spec_obj)[1]=="Spectra") +}) \ No newline at end of file diff --git a/vignettes/Vig01-introduction-to-alpsnmr.Rmd b/vignettes/Vig01-introduction-to-alpsnmr.Rmd index 422f7d16..4f43db0d 100644 --- a/vignettes/Vig01-introduction-to-alpsnmr.Rmd +++ b/vignettes/Vig01-introduction-to-alpsnmr.Rmd @@ -143,6 +143,18 @@ If you want to learn more about sample metadata (including acquisition and FID processing parameters), as well as more complex ways of adding annotations, check out the `vignette("Vig02-handling-metadata-and-annotations", package = "AlpsNMR")`. +# Phasing + +It might be the case that automatically reconstructed metabolite NMR spectra have +a first-order phase error. A convenient wrapper function is provided to link to +the package `NMRphasing` that provides a variety of algorithms to try to estimate +and correct for phase errors, which arise on physical grounds. At present, this _also_ +performs a baseline correction, which may not be desired. + +```{r} +#dataset <- nmr_dataset_autophase(dataset, method="MPC_DANM") +``` + # Interpolation From 4e2c6958a1accdab1ba4f5ab73d9b1879cf55b66 Mon Sep 17 00:00:00 2001 From: Jack Miller Date: Fri, 19 Jan 2024 14:54:23 +0000 Subject: [PATCH 02/23] Adjusted documentation very very slightly in order to perhaps make issue #66's life easier --- R/nmr_detect_peaks_align.R | 3 ++- man/Pipelines.Rd | 3 ++- man/nmr_detect_peaks.Rd | 3 ++- man/nmr_detect_peaks_tune_snr.Rd | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/nmr_detect_peaks_align.R b/R/nmr_detect_peaks_align.R index 56911440..c03a5dbc 100644 --- a/R/nmr_detect_peaks_align.R +++ b/R/nmr_detect_peaks_align.R @@ -93,7 +93,8 @@ NULL #' @param baselineThresh All peaks with intensities below the thresholds are excluded. Either: #' - A numeric vector of length the number of samples. Each number is a threshold for that sample #' - A single number. All samples use this number as baseline threshold. -#' - `NULL`. If that's the case, a default function is used ([nmr_baseline_threshold()]) +#' - `NULL`. If that's the case, a default function is used ([nmr_baseline_threshold()]), which assumes +#' that there is no signal in the region 9.5-10 ppm. #' @inheritParams speaq::detectSpecPeaks #' @param range_without_peaks A numeric vector of length two with a region without peaks, only used when `baselineThresh = NULL` #' @param fit_lorentzians If `TRUE`, fit a lorentzian to each detected peak, to infer its inflection points. For now disabled for backwards compatibility. diff --git a/man/Pipelines.Rd b/man/Pipelines.Rd index 472bb44b..091a07f3 100644 --- a/man/Pipelines.Rd +++ b/man/Pipelines.Rd @@ -106,7 +106,8 @@ for peaks.} \itemize{ \item A numeric vector of length the number of samples. Each number is a threshold for that sample \item A single number. All samples use this number as baseline threshold. -\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}) +\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}), which assumes +that there is no signal in the region 9.5-10 ppm. }} \item{SNR.Th}{The parameter of peakDetectionCWT function of MassSpecWavelet package, look it up in the original function. If you set -1, the function will itself re-compute this value.} diff --git a/man/nmr_detect_peaks.Rd b/man/nmr_detect_peaks.Rd index 46df4349..14b29af3 100644 --- a/man/nmr_detect_peaks.Rd +++ b/man/nmr_detect_peaks.Rd @@ -27,7 +27,8 @@ for peaks.} \itemize{ \item A numeric vector of length the number of samples. Each number is a threshold for that sample \item A single number. All samples use this number as baseline threshold. -\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}) +\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}), which assumes +that there is no signal in the region 9.5-10 ppm. }} \item{SNR.Th}{The parameter of peakDetectionCWT function of MassSpecWavelet package, look it up in the original function. If you set -1, the function will itself re-compute this value.} diff --git a/man/nmr_detect_peaks_tune_snr.Rd b/man/nmr_detect_peaks_tune_snr.Rd index 19b36883..041d9681 100644 --- a/man/nmr_detect_peaks_tune_snr.Rd +++ b/man/nmr_detect_peaks_tune_snr.Rd @@ -28,7 +28,8 @@ for peaks.} \itemize{ \item A numeric vector of length the number of samples. Each number is a threshold for that sample \item A single number. All samples use this number as baseline threshold. -\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}) +\item \code{NULL}. If that's the case, a default function is used (\code{\link[=nmr_baseline_threshold]{nmr_baseline_threshold()}}), which assumes +that there is no signal in the region 9.5-10 ppm. }} \item{\code{range_without_peaks}}{A numeric vector of length two with a region without peaks, only used when \code{baselineThresh = NULL}} \item{\code{fit_lorentzians}}{If \code{TRUE}, fit a lorentzian to each detected peak, to infer its inflection points. For now disabled for backwards compatibility.} From ee257bebcd2737b6b35e046aa381bde110a5dcb3 Mon Sep 17 00:00:00 2001 From: NeutralKaon Date: Sun, 21 Jan 2024 12:31:50 +0000 Subject: [PATCH 03/23] Added a baseline correction parameter --- R/asics_helpers.R | 6 ++++-- man/nmr_dataset_autophase.Rd | 5 ++++- vignettes/Vig01-introduction-to-alpsnmr.Rmd | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/R/asics_helpers.R b/R/asics_helpers.R index 847259bd..7b17e909 100644 --- a/R/asics_helpers.R +++ b/R/asics_helpers.R @@ -12,6 +12,7 @@ #' #' @param samples An `nmr_dataset_family` 1D object #' @param method The autophasing method -- see `NMRphasing::NMRphasing` for details. +#' @param withBC `NMRphasing::NMRphasing` performs an integrated baseline correction -- this parameter enables or disables it. #' @return A (hopefully better phased) `nmr_dataset_family` 1D object, with updated real and imaginary parts. #' @examples #' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") @@ -21,7 +22,7 @@ #' plot(dataset) #' #' @export -nmr_dataset_autophase <- function(samples, method= c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM")) { +nmr_dataset_autophase <- function(samples, method= c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), withBC=F) { method <- match.arg(method) BiocParallel::bplapply(seq_len(length(samples[["data_1r"]])), function(i) { @@ -36,7 +37,8 @@ nmr_dataset_autophase <- function(samples, method= c("NLS", "MPC_DANM", "MPC_EMP } phased_data <- NMRphasing::NMRphasing(data_to_phase, method = method, - absorptionOnly = !"data_1i" %in% objects(samples)) + absorptionOnly = !"data_1i" %in% objects(samples), + withBC = F) if("data_1i" %in% objects(samples)) { samples[["data_1r"]][[i]] <- Re(phased_data) diff --git a/man/nmr_dataset_autophase.Rd b/man/nmr_dataset_autophase.Rd index 5c8cfa86..f317d99a 100644 --- a/man/nmr_dataset_autophase.Rd +++ b/man/nmr_dataset_autophase.Rd @@ -6,13 +6,16 @@ \usage{ nmr_dataset_autophase( samples, - method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM") + method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), + withBC = F ) } \arguments{ \item{samples}{An \code{nmr_dataset_family} 1D object} \item{method}{The autophasing method -- see \code{NMRphasing::NMRphasing} for details.} + +\item{withBC}{\code{NMRphasing::NMRphasing} performs an integrated baseline correction -- this parameter enables or disables it.} } \value{ A (hopefully better phased) \code{nmr_dataset_family} 1D object, with updated real and imaginary parts. diff --git a/vignettes/Vig01-introduction-to-alpsnmr.Rmd b/vignettes/Vig01-introduction-to-alpsnmr.Rmd index 4f43db0d..f32c8c48 100644 --- a/vignettes/Vig01-introduction-to-alpsnmr.Rmd +++ b/vignettes/Vig01-introduction-to-alpsnmr.Rmd @@ -148,11 +148,11 @@ check out the `vignette("Vig02-handling-metadata-and-annotations", package = "Al It might be the case that automatically reconstructed metabolite NMR spectra have a first-order phase error. A convenient wrapper function is provided to link to the package `NMRphasing` that provides a variety of algorithms to try to estimate -and correct for phase errors, which arise on physical grounds. At present, this _also_ -performs a baseline correction, which may not be desired. +and correct for phase errors, which arise on physical grounds. `NMRphasing` +performs an optional baseline correction, which here is disabled. ```{r} -#dataset <- nmr_dataset_autophase(dataset, method="MPC_DANM") +#dataset <- nmr_dataset_autophase(dataset, method="MPC_DANM", withBC=F) ``` From 147c19a8f503ac2075c48f2ebd8e3ef53284cc90 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:23:14 +0200 Subject: [PATCH 04/23] devtools::document() --- DESCRIPTION | 2 +- man/Pipelines.Rd | 14 +++++++------- man/filter.nmr_dataset_family.Rd | 2 +- man/format.nmr_dataset.Rd | 8 ++++---- man/format.nmr_dataset_1D.Rd | 12 ++++++------ man/format.nmr_dataset_peak_table.Rd | 10 +++++----- man/get_integration_with_metadata.Rd | 2 +- man/is.nmr_dataset_1D.Rd | 12 ++++++------ man/is.nmr_dataset_peak_table.Rd | 10 +++++----- man/new_nmr_dataset.Rd | 8 ++++---- man/new_nmr_dataset_1D.Rd | 10 +++++----- man/new_nmr_dataset_peak_table.Rd | 10 +++++----- man/nmr_baseline_threshold.Rd | 4 ++-- man/nmr_detect_peaks.Rd | 2 +- man/nmr_detect_peaks_plot.Rd | 4 ++-- man/nmr_detect_peaks_plot_overview.Rd | 2 +- man/nmr_detect_peaks_tune_snr.Rd | 4 ++-- man/nmr_identify_regions_blood.Rd | 4 ++-- man/nmr_identify_regions_cell.Rd | 4 ++-- man/nmr_identify_regions_urine.Rd | 4 ++-- man/nmr_integrate_peak_positions.Rd | 2 +- man/nmr_integrate_regions.Rd | 6 +++--- man/nmr_meta_add.Rd | 12 ++++++------ man/nmr_meta_export.Rd | 12 ++++++------ man/nmr_meta_groups.Rd | 4 ++-- man/nmr_pca_build_model.Rd | 2 +- man/nmr_pca_outliers_filter.Rd | 8 ++++---- man/nmr_pca_outliers_plot.Rd | 6 +++--- man/nmr_pca_outliers_robust.Rd | 6 +++--- man/nmr_pca_plots.Rd | 4 ++-- man/nmr_ppm_resolution.Rd | 2 +- man/print.nmr_dataset.Rd | 8 ++++---- man/print.nmr_dataset_1D.Rd | 12 ++++++------ man/print.nmr_dataset_peak_table.Rd | 10 +++++----- man/sub-.nmr_dataset_1D.Rd | 4 ++-- man/sub-.nmr_dataset_peak_table.Rd | 2 +- man/validate_nmr_dataset.Rd | 12 ++++++------ man/validate_nmr_dataset_family.Rd | 10 +++++----- man/validate_nmr_dataset_peak_table.Rd | 10 +++++----- 39 files changed, 130 insertions(+), 130 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 86050518..d3cc06ad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -112,6 +112,6 @@ Suggests: zip (>= 2.0.4) biocViews: Software, Preprocessing, Visualization, Classification, Cheminformatics, Metabolomics, DataImport -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr diff --git a/man/Pipelines.Rd b/man/Pipelines.Rd index 091a07f3..ab4e615a 100644 --- a/man/Pipelines.Rd +++ b/man/Pipelines.Rd @@ -222,30 +222,30 @@ Other import/export functions: Other metadata functions: \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_groups}()} Other outlier detection functions: +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, \code{\link{nmr_pca_outliers_plot}()}, -\code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()} +\code{\link{nmr_pca_outliers_robust}()} Other peak detection functions: \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, \code{\link{nmr_integrate_regions}()} Other alignment functions: -\code{\link{nmr_align_find_ref}()}, -\code{\link{nmr_align}()} +\code{\link{nmr_align}()}, +\code{\link{nmr_align_find_ref}()} Other peak integration functions: \code{\link{get_integration_with_metadata}()}, diff --git a/man/filter.nmr_dataset_family.Rd b/man/filter.nmr_dataset_family.Rd index a61aad09..a61e3923 100644 --- a/man/filter.nmr_dataset_family.Rd +++ b/man/filter.nmr_dataset_family.Rd @@ -30,9 +30,9 @@ sample_10 <- filter(dataset_1D, NMRExperiment == "10") } \seealso{ Other subsetting functions: +\code{\link{[.nmr_dataset}()}, \code{\link{[.nmr_dataset_1D}()}, \code{\link{[.nmr_dataset_peak_table}()}, -\code{\link{[.nmr_dataset}()}, \code{\link{nmr_pca_outliers_filter}()} } \concept{subsetting functions} diff --git a/man/format.nmr_dataset.Rd b/man/format.nmr_dataset.Rd index 02c926ac..2c2ca5af 100644 --- a/man/format.nmr_dataset.Rd +++ b/man/format.nmr_dataset.Rd @@ -29,14 +29,14 @@ Other class helper functions: \code{\link{format.nmr_dataset_peak_table}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/format.nmr_dataset_1D.Rd b/man/format.nmr_dataset_1D.Rd index bc65b1d4..00196111 100644 --- a/man/format.nmr_dataset_1D.Rd +++ b/man/format.nmr_dataset_1D.Rd @@ -25,19 +25,19 @@ format(dataset_1D) } \seealso{ Other class helper functions: -\code{\link{format.nmr_dataset_peak_table}()}, \code{\link{format.nmr_dataset}()}, +\code{\link{format.nmr_dataset_peak_table}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} Other nmr_dataset_1D functions: \code{\link{[.nmr_dataset_1D}()}, @@ -47,8 +47,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/format.nmr_dataset_peak_table.Rd b/man/format.nmr_dataset_peak_table.Rd index 571bc8a4..c1358267 100644 --- a/man/format.nmr_dataset_peak_table.Rd +++ b/man/format.nmr_dataset_peak_table.Rd @@ -31,18 +31,18 @@ format(new) } \seealso{ Other class helper functions: -\code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset}()}, +\code{\link{format.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/get_integration_with_metadata.Rd b/man/get_integration_with_metadata.Rd index 75193c00..a33f6bbc 100644 --- a/man/get_integration_with_metadata.Rd +++ b/man/get_integration_with_metadata.Rd @@ -45,8 +45,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/is.nmr_dataset_1D.Rd b/man/is.nmr_dataset_1D.Rd index 25ff06f1..e365a527 100644 --- a/man/is.nmr_dataset_1D.Rd +++ b/man/is.nmr_dataset_1D.Rd @@ -23,19 +23,19 @@ result <- is(dataset_1D) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} Other nmr_dataset_1D functions: \code{\link{[.nmr_dataset_1D}()}, @@ -45,8 +45,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/is.nmr_dataset_peak_table.Rd b/man/is.nmr_dataset_peak_table.Rd index f70d5faa..a7f85eee 100644 --- a/man/is.nmr_dataset_peak_table.Rd +++ b/man/is.nmr_dataset_peak_table.Rd @@ -30,18 +30,18 @@ is(new) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/new_nmr_dataset.Rd b/man/new_nmr_dataset.Rd index 39fefa02..8d186d28 100644 --- a/man/new_nmr_dataset.Rd +++ b/man/new_nmr_dataset.Rd @@ -43,18 +43,18 @@ my_2D_data <- new_nmr_dataset(metadata_2D, data_fields_2D, axis_2D) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/new_nmr_dataset_1D.Rd b/man/new_nmr_dataset_1D.Rd index d9d9918c..f3aa2194 100644 --- a/man/new_nmr_dataset_1D.Rd +++ b/man/new_nmr_dataset_1D.Rd @@ -38,18 +38,18 @@ dummy_nmr_dataset_1D <- new_nmr_dataset_1D( } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset_peak_table}()}, \code{\link{new_nmr_dataset}()}, +\code{\link{new_nmr_dataset_peak_table}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/new_nmr_dataset_peak_table.Rd b/man/new_nmr_dataset_peak_table.Rd index 97e3b028..849c70d0 100644 --- a/man/new_nmr_dataset_peak_table.Rd +++ b/man/new_nmr_dataset_peak_table.Rd @@ -31,18 +31,18 @@ new <- new_nmr_dataset_peak_table(peak_table, metadata) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset}()}, +\code{\link{new_nmr_dataset_1D}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/nmr_baseline_threshold.Rd b/man/nmr_baseline_threshold.Rd index 407e8904..1f68a93d 100644 --- a/man/nmr_baseline_threshold.Rd +++ b/man/nmr_baseline_threshold.Rd @@ -52,10 +52,10 @@ bl_threshold <- nmr_baseline_threshold(dataset_1D, range_without_peaks = c(9.5,1 \seealso{ Other peak detection functions: \code{\link{Pipelines}}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, diff --git a/man/nmr_detect_peaks.Rd b/man/nmr_detect_peaks.Rd index 14b29af3..5bebe8db 100644 --- a/man/nmr_detect_peaks.Rd +++ b/man/nmr_detect_peaks.Rd @@ -63,8 +63,8 @@ Peak_detection Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, diff --git a/man/nmr_detect_peaks_plot.Rd b/man/nmr_detect_peaks_plot.Rd index b3780cf1..65a4133e 100644 --- a/man/nmr_detect_peaks_plot.Rd +++ b/man/nmr_detect_peaks_plot.Rd @@ -38,9 +38,9 @@ Peak_detection nmr_detect_peaks Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, @@ -49,9 +49,9 @@ Other peak detection functions: Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, diff --git a/man/nmr_detect_peaks_plot_overview.Rd b/man/nmr_detect_peaks_plot_overview.Rd index 7212e5cd..d3ff5b95 100644 --- a/man/nmr_detect_peaks_plot_overview.Rd +++ b/man/nmr_detect_peaks_plot_overview.Rd @@ -36,9 +36,9 @@ Peak_detection Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, diff --git a/man/nmr_detect_peaks_tune_snr.Rd b/man/nmr_detect_peaks_tune_snr.Rd index 041d9681..5c3b05f1 100644 --- a/man/nmr_detect_peaks_tune_snr.Rd +++ b/man/nmr_detect_peaks_tune_snr.Rd @@ -59,9 +59,9 @@ nmr_detect_peaks Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, -\code{\link{nmr_detect_peaks_plot}()}, \code{\link{nmr_detect_peaks}()}, +\code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, diff --git a/man/nmr_identify_regions_blood.Rd b/man/nmr_identify_regions_blood.Rd index 06606ed9..f723dc92 100644 --- a/man/nmr_identify_regions_blood.Rd +++ b/man/nmr_identify_regions_blood.Rd @@ -36,10 +36,10 @@ identification <- nmr_identify_regions_blood(ppm_to_assign) Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()}, \code{\link{nmr_integrate_regions}()} diff --git a/man/nmr_identify_regions_cell.Rd b/man/nmr_identify_regions_cell.Rd index 69c7b04f..1f199be9 100644 --- a/man/nmr_identify_regions_cell.Rd +++ b/man/nmr_identify_regions_cell.Rd @@ -36,10 +36,10 @@ identification <- nmr_identify_regions_cell(ppm_to_assign, num_proposed_compound Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_urine}()}, \code{\link{nmr_integrate_regions}()} diff --git a/man/nmr_identify_regions_urine.Rd b/man/nmr_identify_regions_urine.Rd index 7151daaa..5f952f7a 100644 --- a/man/nmr_identify_regions_urine.Rd +++ b/man/nmr_identify_regions_urine.Rd @@ -37,10 +37,10 @@ identification <- nmr_identify_regions_urine(ppm_to_assign, num_proposed_compoun Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_integrate_regions}()} diff --git a/man/nmr_integrate_peak_positions.Rd b/man/nmr_integrate_peak_positions.Rd index 2d02efb4..be544bf2 100644 --- a/man/nmr_integrate_peak_positions.Rd +++ b/man/nmr_integrate_peak_positions.Rd @@ -50,8 +50,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/nmr_integrate_regions.Rd b/man/nmr_integrate_regions.Rd index 20b29dd2..5048d00d 100644 --- a/man/nmr_integrate_regions.Rd +++ b/man/nmr_integrate_regions.Rd @@ -87,10 +87,10 @@ peak_table_integration <- nmr_integrate_regions( Other peak detection functions: \code{\link{Pipelines}}, \code{\link{nmr_baseline_threshold}()}, -\code{\link{nmr_detect_peaks_plot_overview}()}, +\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_detect_peaks_plot}()}, +\code{\link{nmr_detect_peaks_plot_overview}()}, \code{\link{nmr_detect_peaks_tune_snr}()}, -\code{\link{nmr_detect_peaks}()}, \code{\link{nmr_identify_regions_blood}()}, \code{\link{nmr_identify_regions_cell}()}, \code{\link{nmr_identify_regions_urine}()} @@ -111,8 +111,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_peak_positions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/nmr_meta_add.Rd b/man/nmr_meta_add.Rd index a2879884..713b8266 100644 --- a/man/nmr_meta_add.Rd +++ b/man/nmr_meta_add.Rd @@ -78,14 +78,14 @@ nmr_meta_get(nmr_dataset, groups = "external") Other metadata functions: \code{\link{Pipelines}}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_groups}()} Other nmr_dataset functions: \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, -\code{\link{nmr_meta_get}()} +\code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()} Other nmr_dataset_1D functions: \code{\link{[.nmr_dataset_1D}()}, @@ -95,15 +95,15 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_peak_positions}()}, \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} Other nmr_dataset_peak_table functions: \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, -\code{\link{nmr_meta_get}()} +\code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()} } \concept{metadata functions} \concept{nmr_dataset functions} diff --git a/man/nmr_meta_export.Rd b/man/nmr_meta_export.Rd index 902ad018..fe6e2675 100644 --- a/man/nmr_meta_export.Rd +++ b/man/nmr_meta_export.Rd @@ -34,14 +34,14 @@ dataset <- nmr_read_samples_dir(dir_to_demo_dataset) Other metadata functions: \code{\link{Pipelines}}, \code{\link{nmr_meta_add}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_groups}()} Other nmr_dataset functions: \code{\link{nmr_meta_add}()}, -\code{\link{nmr_meta_get_column}()}, -\code{\link{nmr_meta_get}()} +\code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()} Other nmr_dataset_1D functions: \code{\link{[.nmr_dataset_1D}()}, @@ -51,15 +51,15 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_peak_positions}()}, \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} Other nmr_dataset_peak_table functions: \code{\link{nmr_meta_add}()}, -\code{\link{nmr_meta_get_column}()}, -\code{\link{nmr_meta_get}()} +\code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()} Other import/export functions: \code{\link{Pipelines}}, diff --git a/man/nmr_meta_groups.Rd b/man/nmr_meta_groups.Rd index 3c6d0483..5285d5dd 100644 --- a/man/nmr_meta_groups.Rd +++ b/man/nmr_meta_groups.Rd @@ -25,7 +25,7 @@ Other metadata functions: \code{\link{Pipelines}}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, -\code{\link{nmr_meta_get}()} +\code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()} } \concept{metadata functions} diff --git a/man/nmr_pca_build_model.Rd b/man/nmr_pca_build_model.Rd index 4cdc9a0e..1e5cbf7b 100644 --- a/man/nmr_pca_build_model.Rd +++ b/man/nmr_pca_build_model.Rd @@ -73,10 +73,10 @@ model <- nmr_pca_build_model(dataset_1D) } \seealso{ Other PCA related functions: +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, \code{\link{nmr_pca_outliers_plot}()}, \code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_plots}} } \concept{PCA related functions} diff --git a/man/nmr_pca_outliers_filter.Rd b/man/nmr_pca_outliers_filter.Rd index 470ca8ea..061476a6 100644 --- a/man/nmr_pca_outliers_filter.Rd +++ b/man/nmr_pca_outliers_filter.Rd @@ -29,21 +29,21 @@ dataset_whitout_outliers <- nmr_pca_outliers_filter(dataset_1D, outliers_info) \seealso{ Other PCA related functions: \code{\link{nmr_pca_build_model}()}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_plot}()}, \code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_plots}} Other outlier detection functions: \code{\link{Pipelines}}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_plot}()}, -\code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()} +\code{\link{nmr_pca_outliers_robust}()} Other subsetting functions: +\code{\link{[.nmr_dataset}()}, \code{\link{[.nmr_dataset_1D}()}, \code{\link{[.nmr_dataset_peak_table}()}, -\code{\link{[.nmr_dataset}()}, \code{\link{filter.nmr_dataset_family}()} } \concept{PCA related functions} diff --git a/man/nmr_pca_outliers_plot.Rd b/man/nmr_pca_outliers_plot.Rd index 195c8819..91628cd5 100644 --- a/man/nmr_pca_outliers_plot.Rd +++ b/man/nmr_pca_outliers_plot.Rd @@ -31,16 +31,16 @@ Plot for outlier detection diagnostic \seealso{ Other PCA related functions: \code{\link{nmr_pca_build_model}()}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, \code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_plots}} Other outlier detection functions: \code{\link{Pipelines}}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, -\code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()} +\code{\link{nmr_pca_outliers_robust}()} } \concept{PCA related functions} \concept{outlier detection functions} diff --git a/man/nmr_pca_outliers_robust.Rd b/man/nmr_pca_outliers_robust.Rd index 2627023e..9c71b92f 100644 --- a/man/nmr_pca_outliers_robust.Rd +++ b/man/nmr_pca_outliers_robust.Rd @@ -47,16 +47,16 @@ outliers_info <- nmr_pca_outliers_robust(dataset_1D) \seealso{ Other PCA related functions: \code{\link{nmr_pca_build_model}()}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, \code{\link{nmr_pca_outliers_plot}()}, -\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_plots}} Other outlier detection functions: \code{\link{Pipelines}}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, -\code{\link{nmr_pca_outliers_plot}()}, -\code{\link{nmr_pca_outliers}()} +\code{\link{nmr_pca_outliers_plot}()} } \concept{PCA related functions} \concept{outlier detection functions} diff --git a/man/nmr_pca_plots.Rd b/man/nmr_pca_plots.Rd index 2fc91bfd..39f468d8 100644 --- a/man/nmr_pca_plots.Rd +++ b/man/nmr_pca_plots.Rd @@ -39,9 +39,9 @@ nmr_pca_loadingplot(model, 1) \seealso{ Other PCA related functions: \code{\link{nmr_pca_build_model}()}, +\code{\link{nmr_pca_outliers}()}, \code{\link{nmr_pca_outliers_filter}()}, \code{\link{nmr_pca_outliers_plot}()}, -\code{\link{nmr_pca_outliers_robust}()}, -\code{\link{nmr_pca_outliers}()} +\code{\link{nmr_pca_outliers_robust}()} } \concept{PCA related functions} diff --git a/man/nmr_ppm_resolution.Rd b/man/nmr_ppm_resolution.Rd index fbc3f89a..6aca448c 100644 --- a/man/nmr_ppm_resolution.Rd +++ b/man/nmr_ppm_resolution.Rd @@ -45,8 +45,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{print.nmr_dataset_1D}()} } \concept{nmr_dataset_1D functions} diff --git a/man/print.nmr_dataset.Rd b/man/print.nmr_dataset.Rd index 419696e7..4615ce65 100644 --- a/man/print.nmr_dataset.Rd +++ b/man/print.nmr_dataset.Rd @@ -25,18 +25,18 @@ print(dataset) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/print.nmr_dataset_1D.Rd b/man/print.nmr_dataset_1D.Rd index 45fc36bd..31e344db 100644 --- a/man/print.nmr_dataset_1D.Rd +++ b/man/print.nmr_dataset_1D.Rd @@ -25,19 +25,19 @@ print(dataset_1D) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, -\code{\link{print.nmr_dataset_peak_table}()}, \code{\link{print.nmr_dataset}()}, +\code{\link{print.nmr_dataset_peak_table}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} Other nmr_dataset_1D functions: \code{\link{[.nmr_dataset_1D}()}, @@ -48,8 +48,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()} } \concept{class helper functions} diff --git a/man/print.nmr_dataset_peak_table.Rd b/man/print.nmr_dataset_peak_table.Rd index 253f1837..514353da 100644 --- a/man/print.nmr_dataset_peak_table.Rd +++ b/man/print.nmr_dataset_peak_table.Rd @@ -31,18 +31,18 @@ new } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, -\code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset}()}, +\code{\link{print.nmr_dataset_1D}()}, +\code{\link{validate_nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/sub-.nmr_dataset_1D.Rd b/man/sub-.nmr_dataset_1D.Rd index 77a4f90b..0cd33a19 100644 --- a/man/sub-.nmr_dataset_1D.Rd +++ b/man/sub-.nmr_dataset_1D.Rd @@ -25,8 +25,8 @@ dataset_1D[0] } \seealso{ Other subsetting functions: -\code{\link{[.nmr_dataset_peak_table}()}, \code{\link{[.nmr_dataset}()}, +\code{\link{[.nmr_dataset_peak_table}()}, \code{\link{filter.nmr_dataset_family}()}, \code{\link{nmr_pca_outliers_filter}()} @@ -38,8 +38,8 @@ Other nmr_dataset_1D functions: \code{\link{nmr_integrate_regions}()}, \code{\link{nmr_meta_add}()}, \code{\link{nmr_meta_export}()}, -\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_meta_get}()}, +\code{\link{nmr_meta_get_column}()}, \code{\link{nmr_ppm_resolution}()}, \code{\link{print.nmr_dataset_1D}()} } diff --git a/man/sub-.nmr_dataset_peak_table.Rd b/man/sub-.nmr_dataset_peak_table.Rd index 12d8e895..b49a6770 100644 --- a/man/sub-.nmr_dataset_peak_table.Rd +++ b/man/sub-.nmr_dataset_peak_table.Rd @@ -31,8 +31,8 @@ new[0] } \seealso{ Other subsetting functions: -\code{\link{[.nmr_dataset_1D}()}, \code{\link{[.nmr_dataset}()}, +\code{\link{[.nmr_dataset_1D}()}, \code{\link{filter.nmr_dataset_family}()}, \code{\link{nmr_pca_outliers_filter}()} } diff --git a/man/validate_nmr_dataset.Rd b/man/validate_nmr_dataset.Rd index 4a5ccece..77b760c4 100644 --- a/man/validate_nmr_dataset.Rd +++ b/man/validate_nmr_dataset.Rd @@ -39,32 +39,32 @@ dataset_1D_validated <- validate_nmr_dataset_1D(dataset_1D) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, \code{\link{validate_nmr_dataset_peak_table}()} Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, \code{\link{validate_nmr_dataset_family}()}, \code{\link{validate_nmr_dataset_peak_table}()} } diff --git a/man/validate_nmr_dataset_family.Rd b/man/validate_nmr_dataset_family.Rd index cbca37a2..b1684f77 100644 --- a/man/validate_nmr_dataset_family.Rd +++ b/man/validate_nmr_dataset_family.Rd @@ -25,18 +25,18 @@ validate_nmr_dataset_family(dataset_1D) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, -\code{\link{validate_nmr_dataset_peak_table}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset}()}, +\code{\link{validate_nmr_dataset_peak_table}()} } \concept{class helper functions} diff --git a/man/validate_nmr_dataset_peak_table.Rd b/man/validate_nmr_dataset_peak_table.Rd index a8150558..20bbfced 100644 --- a/man/validate_nmr_dataset_peak_table.Rd +++ b/man/validate_nmr_dataset_peak_table.Rd @@ -25,18 +25,18 @@ pt_validated <- validate_nmr_dataset_peak_table(pt) } \seealso{ Other class helper functions: +\code{\link{format.nmr_dataset}()}, \code{\link{format.nmr_dataset_1D}()}, \code{\link{format.nmr_dataset_peak_table}()}, -\code{\link{format.nmr_dataset}()}, \code{\link{is.nmr_dataset_1D}()}, \code{\link{is.nmr_dataset_peak_table}()}, +\code{\link{new_nmr_dataset}()}, \code{\link{new_nmr_dataset_1D}()}, \code{\link{new_nmr_dataset_peak_table}()}, -\code{\link{new_nmr_dataset}()}, +\code{\link{print.nmr_dataset}()}, \code{\link{print.nmr_dataset_1D}()}, \code{\link{print.nmr_dataset_peak_table}()}, -\code{\link{print.nmr_dataset}()}, -\code{\link{validate_nmr_dataset_family}()}, -\code{\link{validate_nmr_dataset}()} +\code{\link{validate_nmr_dataset}()}, +\code{\link{validate_nmr_dataset_family}()} } \concept{class helper functions} From 00f5a4295a93d095331ca75a776adfee5ed6a0b9 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:25:45 +0200 Subject: [PATCH 05/23] autophasing improvements - Avoid passing a whole copy of the dataset to the biocparallel workers - Documentation - rename nmr_dataset_autophase to nmr_autophase --- R/asics_helpers.R | 127 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 88 insertions(+), 39 deletions(-) diff --git a/R/asics_helpers.R b/R/asics_helpers.R index 7b17e909..6b88ac44 100644 --- a/R/asics_helpers.R +++ b/R/asics_helpers.R @@ -1,57 +1,106 @@ -#' @title Perform an automatic 1D NMR phasing +#' @title Rephase 1D NMR data #' @description -#' It is quite often the case that (e.g. Bruker's) 1D autophase isn't quite right. -#' This uses `NMRphasing::NMRphasing` to automatically rephase data in the spectral domain. -#' A number of algorithms are available (see NMRphasing's documentation), -#' of which NLS, MPC_DANM and SPC_DANM are the most recent. +#' Use phasing algorithms to rephase data in the spectral domain. #' -#' Perhaps obviously, you are likely to get better results loading the complex data -#' than having real-only spectra (i.e. pass `all_components = T` to `nmr_read_samples`). +#' This function may improve autophasing processing from instrument vendors. It +#' wraps the [NMRphasing::NMRphasing()] function, to automatically rephase spectra, +#' allowing you to choose from a number of algorithms +#' of which `NLS`, `MPC_DANM` and `SPC_DANM` are the most recent. #' -#' Run this before spectral interpolation. +#' Rephasing should happen before any spectra interpolation. #' -#' @param samples An `nmr_dataset_family` 1D object -#' @param method The autophasing method -- see `NMRphasing::NMRphasing` for details. -#' @param withBC `NMRphasing::NMRphasing` performs an integrated baseline correction -- this parameter enables or disables it. -#' @return A (hopefully better phased) `nmr_dataset_family` 1D object, with updated real and imaginary parts. +#' Please use the `all_components = TRUE` when calling [nmr_read_samples()] in order +#' to load the complex spectra and fix NMR phasing correctly. +#' +#' @param dataset An [nmr_dataset] object +#' @param method The autophasing method. See [NMRphasing::NMRphasing()] for details. +#' @param withBC `NMRphasing::NMRphasing` may perform a baseline correction using modified polynomial fitting. By default +#' AlpsNMR offers other baseline estimation methods and better visualization of its effect, so AlpsNMR by default +#' disables the baseline correction offered by NMRphasing. +#' @param ... Other parameters passed on to [NMRphasing::NMRphasing()]. +#' @return A (hopefully better phased) [nmr_dataset] object, with updated real and imaginary parts. #' @examples #' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset) -#' dataset <- nmr_dataset_autophase(dataset,method="MPC_DANM") +#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) +#' dataset <- nmr_autophase(dataset, method = "NLS") #' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) #' plot(dataset) #' #' @export -nmr_dataset_autophase <- function(samples, method= c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), withBC=F) { +nmr_autophase <- function(dataset, + method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), + withBC = FALSE, ...) { + if (!"data_1i" %in% names(c(dataset))) { + cli::cli_warn(c( + "!" = "nmr_autophase() performs better with access to the whole complex NMR spectra", + "i" = "Please read the dataset using {.code all_components=TRUE}.", + "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" + )) + } + + if (inherits(dataset, "nmr_dataset_1D")) { + cli::cli_abort(c( + "x" = "nmr_autophase() expects non-interpolated spectra", + "i" = "Please use nmr_autophase() before calling nmr_interpolate_1D()", + "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" + )) + } method <- match.arg(method) - BiocParallel::bplapply(seq_len(length(samples[["data_1r"]])), function(i) { - - data_to_phase <- if("data_1i" %in% objects(samples)) { - complex(real = samples[["data_1r"]][[i]], - imaginary = samples[["data_1i"]][[i]], - length.out = length(samples[["data_1r"]][[i]] - )) - } else { - samples[["data_1r"]][[i]] - } - - phased_data <- NMRphasing::NMRphasing(data_to_phase, method = method, - absorptionOnly = !"data_1i" %in% objects(samples), - withBC = F) - - if("data_1i" %in% objects(samples)) { - samples[["data_1r"]][[i]] <- Re(phased_data) - samples[["data_1i"]][[i]] <- Im(phased_data) - } else { - samples[["data_1r"]][[i]] <- phased_data - } - - }) - return(samples) + real_list_of_spectra <- dataset$data_1r + imag_list_of_spectra <- dataset$data_1i + absorptionOnly <- FALSE + if (is.null(imag_list_of_spectra)) { + imag_list_of_spectra <- vector(mode="list", length=dataset$num_samples) + } else { + any_imag_missing <- purrr::map_lgl(imag_list_of_spectra, is.null) + any_imag_missing <- any_imag_missing[any_imag_missing] + if (length(any_imag_missing) > 0) { + if (length(any_imag_missing < 7)) { + miss_sample_names <- paste0(names(any_imag_missing), collapse = ", ") + msg <- "Samples without imaginary component: {miss_sample_names}" + } else { + miss_sample_names <- paste0(names(head(any_imag_missing, n=5)), collapse = ", ") + msg <- "Samples without imaginary component: {miss_sample_names} and {length(any_imag_missing)-5} more" + } + cli::cli_warn(c( + "!" = "{length(any_imag_missing)}/{dataset$num_samples} samples have a missing imaginary spectrum", + "i" = msg, + "i" = "Estimating autophase using only the absorption" + )) + } + } + + real_imag_lists <- BiocParallel::bpmapply( + FUN = function(real, imag, ...) { + if (!is.null(imag)) { + absorptionOnly <- FALSE + to_phase <- complex( + real = real, + imaginary = imag + ) + } else { + absorptionOnly <- TRUE + to_phase <- real + } + phased <- NMRphasing::NMRphasing(to_phase, absorptionOnly = TRUE, ...) + list(real = Re(phased), imag = Im(phased)) + }, + real_list_of_spectra, imag_list_of_spectra, + MoreArgs = list(method = method, withBC = withBC, ...), + SIMPLIFY = FALSE + ) + dataset[["data_1r"]] <- purrr::map(real_imag_lists, "real") + if ("data_1i" %in% c(dataset)) { + dataset[["data_1i"]] <- purrr::map(real_imag_lists, "imag") + } + dataset } + + + #' @title Export data for the spectral quantification library ASICS #' @description #' A simple helper function for mangling data in the right format for the From cc28a14e82bbae45797b73421e7fc12c396a4e88 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:26:10 +0200 Subject: [PATCH 06/23] Specify contribution --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d3cc06ad..62437d71 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,11 +40,11 @@ Authors@R: c( role = "cph"), person(given = "Institute for Bioengineering of Catalonia", role = "cph"), - person(given = "Miller", - family = "Jack", + person(given = "Miller", + family = "Jack", email = "jack.miller@physics.org", role=c("ctb"), - comment = c(ORCID = "0000-0002-6258-1299")) + comment = c(ORCID = "0000-0002-6258-1299", "Autophase wrapper, ASICS export")) ) Description: Reads Bruker NMR data directories both zipped and unzipped. It provides automated and efficient signal processing for untargeted From ee2d431b67cf9bca012413799c0b83ea9e887f25 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:26:27 +0200 Subject: [PATCH 07/23] Devtools document --- NAMESPACE | 2 +- man/AlpsNMR-package.Rd | 2 +- man/nmr_autophase.Rd | 48 ++++++++++++++++++++++++++++++++++++ man/nmr_dataset_autophase.Rd | 41 ------------------------------ 4 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 man/nmr_autophase.Rd delete mode 100644 man/nmr_dataset_autophase.Rd diff --git a/NAMESPACE b/NAMESPACE index cc3aef3e..a1640fb6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,6 +50,7 @@ export(new_nmr_dataset_1D) export(new_nmr_dataset_peak_table) export(nmr_align) export(nmr_align_find_ref) +export(nmr_autophase) export(nmr_baseline_estimation) export(nmr_baseline_removal) export(nmr_baseline_threshold) @@ -64,7 +65,6 @@ export(nmr_build_peak_table) export(nmr_data) export(nmr_data_1r_to_SummarizedExperiment) export(nmr_data_analysis) -export(nmr_dataset_autophase) export(nmr_dataset_load) export(nmr_dataset_peak_table_to_SummarizedExperiment) export(nmr_dataset_save) diff --git a/man/AlpsNMR-package.Rd b/man/AlpsNMR-package.Rd index 0ca81026..ca9744ef 100644 --- a/man/AlpsNMR-package.Rd +++ b/man/AlpsNMR-package.Rd @@ -60,7 +60,7 @@ Other contributors: \item Laura López Sánchez [contributor] \item Nestlé Institute of Health Sciences [copyright holder] \item Institute for Bioengineering of Catalonia [copyright holder] - \item Miller Jack \email{jack.miller@physics.org} (\href{https://orcid.org/0000-0002-6258-1299}{ORCID}) [contributor] + \item Miller Jack \email{jack.miller@physics.org} (\href{https://orcid.org/0000-0002-6258-1299}{ORCID}) (Autophase wrapper, ASICS export) [contributor] } } diff --git a/man/nmr_autophase.Rd b/man/nmr_autophase.Rd new file mode 100644 index 00000000..b6bcc27a --- /dev/null +++ b/man/nmr_autophase.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/asics_helpers.R +\name{nmr_autophase} +\alias{nmr_autophase} +\title{Rephase 1D NMR data} +\usage{ +nmr_autophase( + dataset, + method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), + withBC = FALSE, + ... +) +} +\arguments{ +\item{dataset}{An \link{nmr_dataset} object} + +\item{method}{The autophasing method. See \code{\link[NMRphasing:NMRphasing]{NMRphasing::NMRphasing()}} for details.} + +\item{withBC}{\code{NMRphasing::NMRphasing} may perform a baseline correction using modified polynomial fitting. By default +AlpsNMR offers other baseline estimation methods and better visualization of its effect, so AlpsNMR by default +disables the baseline correction offered by NMRphasing.} + +\item{...}{Other parameters passed on to \code{\link[NMRphasing:NMRphasing]{NMRphasing::NMRphasing()}}.} +} +\value{ +A (hopefully better phased) \link{nmr_dataset} object, with updated real and imaginary parts. +} +\description{ +Use phasing algorithms to rephase data in the spectral domain. + +This function may improve autophasing processing from instrument vendors. It +wraps the \code{\link[NMRphasing:NMRphasing]{NMRphasing::NMRphasing()}} function, to automatically rephase spectra, +allowing you to choose from a number of algorithms +of which \code{NLS}, \code{MPC_DANM} and \code{SPC_DANM} are the most recent. + +Rephasing should happen before any spectra interpolation. + +Please use the \code{all_components = TRUE} when calling \code{\link[=nmr_read_samples]{nmr_read_samples()}} in order +to load the complex spectra and fix NMR phasing correctly. +} +\examples{ +dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) +dataset <- nmr_autophase(dataset, method = "NLS") +dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +plot(dataset) + +} diff --git a/man/nmr_dataset_autophase.Rd b/man/nmr_dataset_autophase.Rd deleted file mode 100644 index f317d99a..00000000 --- a/man/nmr_dataset_autophase.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/asics_helpers.R -\name{nmr_dataset_autophase} -\alias{nmr_dataset_autophase} -\title{Perform an automatic 1D NMR phasing} -\usage{ -nmr_dataset_autophase( - samples, - method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), - withBC = F -) -} -\arguments{ -\item{samples}{An \code{nmr_dataset_family} 1D object} - -\item{method}{The autophasing method -- see \code{NMRphasing::NMRphasing} for details.} - -\item{withBC}{\code{NMRphasing::NMRphasing} performs an integrated baseline correction -- this parameter enables or disables it.} -} -\value{ -A (hopefully better phased) \code{nmr_dataset_family} 1D object, with updated real and imaginary parts. -} -\description{ -It is quite often the case that (e.g. Bruker's) 1D autophase isn't quite right. -This uses \code{NMRphasing::NMRphasing} to automatically rephase data in the spectral domain. -A number of algorithms are available (see NMRphasing's documentation), -of which NLS, MPC_DANM and SPC_DANM are the most recent. - -Perhaps obviously, you are likely to get better results loading the complex data -than having real-only spectra (i.e. pass \code{all_components = T} to \code{nmr_read_samples}). - -Run this before spectral interpolation. -} -\examples{ -dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -dataset <- nmr_read_samples_dir(dir_to_demo_dataset) -dataset <- nmr_dataset_autophase(dataset,method="MPC_DANM") -dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -plot(dataset) - -} From acd4504e648818a9ba1b430b9cb69a8bf6e02c73 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:28:06 +0200 Subject: [PATCH 08/23] Move nmr_autophase to its own file --- R/asics_helpers.R | 103 ---------------------------------------------- R/nmr_autophase.R | 99 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 103 deletions(-) create mode 100644 R/nmr_autophase.R diff --git a/R/asics_helpers.R b/R/asics_helpers.R index 6b88ac44..160db863 100644 --- a/R/asics_helpers.R +++ b/R/asics_helpers.R @@ -1,106 +1,3 @@ -#' @title Rephase 1D NMR data -#' @description -#' Use phasing algorithms to rephase data in the spectral domain. -#' -#' This function may improve autophasing processing from instrument vendors. It -#' wraps the [NMRphasing::NMRphasing()] function, to automatically rephase spectra, -#' allowing you to choose from a number of algorithms -#' of which `NLS`, `MPC_DANM` and `SPC_DANM` are the most recent. -#' -#' Rephasing should happen before any spectra interpolation. -#' -#' Please use the `all_components = TRUE` when calling [nmr_read_samples()] in order -#' to load the complex spectra and fix NMR phasing correctly. -#' -#' @param dataset An [nmr_dataset] object -#' @param method The autophasing method. See [NMRphasing::NMRphasing()] for details. -#' @param withBC `NMRphasing::NMRphasing` may perform a baseline correction using modified polynomial fitting. By default -#' AlpsNMR offers other baseline estimation methods and better visualization of its effect, so AlpsNMR by default -#' disables the baseline correction offered by NMRphasing. -#' @param ... Other parameters passed on to [NMRphasing::NMRphasing()]. -#' @return A (hopefully better phased) [nmr_dataset] object, with updated real and imaginary parts. -#' @examples -#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) -#' dataset <- nmr_autophase(dataset, method = "NLS") -#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -#' plot(dataset) -#' -#' @export -nmr_autophase <- function(dataset, - method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), - withBC = FALSE, ...) { - if (!"data_1i" %in% names(c(dataset))) { - cli::cli_warn(c( - "!" = "nmr_autophase() performs better with access to the whole complex NMR spectra", - "i" = "Please read the dataset using {.code all_components=TRUE}.", - "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" - )) - } - - if (inherits(dataset, "nmr_dataset_1D")) { - cli::cli_abort(c( - "x" = "nmr_autophase() expects non-interpolated spectra", - "i" = "Please use nmr_autophase() before calling nmr_interpolate_1D()", - "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" - )) - } - - method <- match.arg(method) - - real_list_of_spectra <- dataset$data_1r - imag_list_of_spectra <- dataset$data_1i - absorptionOnly <- FALSE - if (is.null(imag_list_of_spectra)) { - imag_list_of_spectra <- vector(mode="list", length=dataset$num_samples) - } else { - any_imag_missing <- purrr::map_lgl(imag_list_of_spectra, is.null) - any_imag_missing <- any_imag_missing[any_imag_missing] - if (length(any_imag_missing) > 0) { - if (length(any_imag_missing < 7)) { - miss_sample_names <- paste0(names(any_imag_missing), collapse = ", ") - msg <- "Samples without imaginary component: {miss_sample_names}" - } else { - miss_sample_names <- paste0(names(head(any_imag_missing, n=5)), collapse = ", ") - msg <- "Samples without imaginary component: {miss_sample_names} and {length(any_imag_missing)-5} more" - } - cli::cli_warn(c( - "!" = "{length(any_imag_missing)}/{dataset$num_samples} samples have a missing imaginary spectrum", - "i" = msg, - "i" = "Estimating autophase using only the absorption" - )) - } - } - - real_imag_lists <- BiocParallel::bpmapply( - FUN = function(real, imag, ...) { - if (!is.null(imag)) { - absorptionOnly <- FALSE - to_phase <- complex( - real = real, - imaginary = imag - ) - } else { - absorptionOnly <- TRUE - to_phase <- real - } - phased <- NMRphasing::NMRphasing(to_phase, absorptionOnly = TRUE, ...) - list(real = Re(phased), imag = Im(phased)) - }, - real_list_of_spectra, imag_list_of_spectra, - MoreArgs = list(method = method, withBC = withBC, ...), - SIMPLIFY = FALSE - ) - dataset[["data_1r"]] <- purrr::map(real_imag_lists, "real") - if ("data_1i" %in% c(dataset)) { - dataset[["data_1i"]] <- purrr::map(real_imag_lists, "imag") - } - dataset -} - - - - #' @title Export data for the spectral quantification library ASICS #' @description #' A simple helper function for mangling data in the right format for the diff --git a/R/nmr_autophase.R b/R/nmr_autophase.R new file mode 100644 index 00000000..cffbd068 --- /dev/null +++ b/R/nmr_autophase.R @@ -0,0 +1,99 @@ +#' @title Rephase 1D NMR data +#' @description +#' Use phasing algorithms to rephase data in the spectral domain. +#' +#' This function may improve autophasing processing from instrument vendors. It +#' wraps the [NMRphasing::NMRphasing()] function, to automatically rephase spectra, +#' allowing you to choose from a number of algorithms +#' of which `NLS`, `MPC_DANM` and `SPC_DANM` are the most recent. +#' +#' Rephasing should happen before any spectra interpolation. +#' +#' Please use the `all_components = TRUE` when calling [nmr_read_samples()] in order +#' to load the complex spectra and fix NMR phasing correctly. +#' +#' @param dataset An [nmr_dataset] object +#' @param method The autophasing method. See [NMRphasing::NMRphasing()] for details. +#' @param withBC `NMRphasing::NMRphasing` may perform a baseline correction using modified polynomial fitting. By default +#' AlpsNMR offers other baseline estimation methods and better visualization of its effect, so AlpsNMR by default +#' disables the baseline correction offered by NMRphasing. +#' @param ... Other parameters passed on to [NMRphasing::NMRphasing()]. +#' @return A (hopefully better phased) [nmr_dataset] object, with updated real and imaginary parts. +#' @examples +#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) +#' dataset <- nmr_autophase(dataset, method = "NLS") +#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +#' plot(dataset) +#' +#' @export +nmr_autophase <- function(dataset, + method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), + withBC = FALSE, ...) { + if (!"data_1i" %in% names(c(dataset))) { + cli::cli_warn(c( + "!" = "nmr_autophase() performs better with access to the whole complex NMR spectra", + "i" = "Please read the dataset using {.code all_components=TRUE}.", + "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" + )) + } + + if (inherits(dataset, "nmr_dataset_1D")) { + cli::cli_abort(c( + "x" = "nmr_autophase() expects non-interpolated spectra", + "i" = "Please use nmr_autophase() before calling nmr_interpolate_1D()", + "i" = "See {.fun AlpsNMR::nmr_autophase} for a full example" + )) + } + + method <- match.arg(method) + + real_list_of_spectra <- dataset$data_1r + imag_list_of_spectra <- dataset$data_1i + absorptionOnly <- FALSE + if (is.null(imag_list_of_spectra)) { + imag_list_of_spectra <- vector(mode="list", length=dataset$num_samples) + } else { + any_imag_missing <- purrr::map_lgl(imag_list_of_spectra, is.null) + any_imag_missing <- any_imag_missing[any_imag_missing] + if (length(any_imag_missing) > 0) { + if (length(any_imag_missing < 7)) { + miss_sample_names <- paste0(names(any_imag_missing), collapse = ", ") + msg <- "Samples without imaginary component: {miss_sample_names}" + } else { + miss_sample_names <- paste0(names(head(any_imag_missing, n=5)), collapse = ", ") + msg <- "Samples without imaginary component: {miss_sample_names} and {length(any_imag_missing)-5} more" + } + cli::cli_warn(c( + "!" = "{length(any_imag_missing)}/{dataset$num_samples} samples have a missing imaginary spectrum", + "i" = msg, + "i" = "Estimating autophase using only the absorption" + )) + } + } + + real_imag_lists <- BiocParallel::bpmapply( + FUN = function(real, imag, ...) { + if (!is.null(imag)) { + absorptionOnly <- FALSE + to_phase <- complex( + real = real, + imaginary = imag + ) + } else { + absorptionOnly <- TRUE + to_phase <- real + } + phased <- NMRphasing::NMRphasing(to_phase, absorptionOnly = TRUE, ...) + list(real = Re(phased), imag = Im(phased)) + }, + real_list_of_spectra, imag_list_of_spectra, + MoreArgs = list(method = method, withBC = withBC, ...), + SIMPLIFY = FALSE + ) + dataset[["data_1r"]] <- purrr::map(real_imag_lists, "real") + if ("data_1i" %in% c(dataset)) { + dataset[["data_1i"]] <- purrr::map(real_imag_lists, "imag") + } + dataset +} From 5b73520c759999914cf333f306aeb9ce4e77a7d1 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:28:28 +0200 Subject: [PATCH 09/23] Ensure NMRphasing is installed --- R/nmr_autophase.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/nmr_autophase.R b/R/nmr_autophase.R index cffbd068..5056c076 100644 --- a/R/nmr_autophase.R +++ b/R/nmr_autophase.R @@ -30,6 +30,7 @@ nmr_autophase <- function(dataset, method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), withBC = FALSE, ...) { + require_pkgs("NMRphasing") if (!"data_1i" %in% names(c(dataset))) { cli::cli_warn(c( "!" = "nmr_autophase() performs better with access to the whole complex NMR spectra", From 1abc6e1d8bee02f1ae3825bc0354a9ee58b6171d Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 09:42:51 +0200 Subject: [PATCH 10/23] Move ASICS export to utils.R --- R/asics_helpers.R | 25 ------------------------- R/utils.R | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 R/asics_helpers.R diff --git a/R/asics_helpers.R b/R/asics_helpers.R deleted file mode 100644 index 160db863..00000000 --- a/R/asics_helpers.R +++ /dev/null @@ -1,25 +0,0 @@ -#' @title Export data for the spectral quantification library ASICS -#' @description -#' A simple helper function for mangling data in the right format for the -#' spectral quantification library ASICS. -#' -#' @param samples An `nmr_dataset_family` 1D object -#' @param ... Additional arguments are passed -#' directly to `ASICS::createSpectra`, which (in theory) provide an -#' opportunity to use distinct normalisation methods. -#' -#' @return An `ASICS::Spectra` object -#' @examples -#' # forAsics <- alps_asics(dataset) -#' # ASICS(forAsics) -#' -#' @export - -alps_asics <- function(samples, ...) { - forAsics <- t(nmr_data(samples)) - forAsics <- ASICS::createSpectra(forAsics, ...) - forAsics@sample.name <-samples$metadata$external$NMRExperiment - return(forAsics) -} - - diff --git a/R/utils.R b/R/utils.R index 98c056ba..b23f616a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -288,6 +288,31 @@ to_ChemoSpec <- function(nmr_dataset, desc = "A nmr_dataset", group = NULL) { return(Spectra) } +#' @title Export data for the spectral quantification library ASICS +#' @description +#' A simple helper function for mangling data in the right format for the +#' spectral quantification library ASICS. +#' +#' @param samples An `nmr_dataset_family` 1D object +#' @param ... Additional arguments are passed +#' directly to `ASICS::createSpectra`, which (in theory) provide an +#' opportunity to use distinct normalisation methods. +#' +#' @return An `ASICS::Spectra` object +#' @examples +#' # forAsics <- alps_asics(dataset) +#' # ASICS(forAsics) +#' +#' @export + +alps_asics <- function(samples, ...) { + forAsics <- t(nmr_data(samples)) + forAsics <- ASICS::createSpectra(forAsics, ...) + forAsics@sample.name <-samples$metadata$external$NMRExperiment + return(forAsics) +} + + abort_if_not <- function(condition, ...) { if (!condition) { From 00027e799e6b709b113d415f09e361fc8cdc2b9d Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:11:56 +0200 Subject: [PATCH 11/23] Rename alps_asics to to_ASICS For consistency to to_ChemoSpec Simplify function, require suggested ASICS pkg on use, improve documentation, make example runnable. --- R/utils.R | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/R/utils.R b/R/utils.R index b23f616a..4b7c3268 100644 --- a/R/utils.R +++ b/R/utils.R @@ -288,32 +288,29 @@ to_ChemoSpec <- function(nmr_dataset, desc = "A nmr_dataset", group = NULL) { return(Spectra) } -#' @title Export data for the spectral quantification library ASICS +#' @title Export data for the ASICS spectral quantification library #' @description -#' A simple helper function for mangling data in the right format for the -#' spectral quantification library ASICS. +#' Exports the spectra matrix, sample names and chemical shift axis into +#' an ASICS Spectra object. #' -#' @param samples An `nmr_dataset_family` 1D object -#' @param ... Additional arguments are passed -#' directly to `ASICS::createSpectra`, which (in theory) provide an -#' opportunity to use distinct normalisation methods. -#' -#' @return An `ASICS::Spectra` object +#' @param dataset An [nmr_dataset_1D] object +#' @inheritDotParams ASICS::createSpectra -spectra +#' @return An [ASICS::Spectra-class] object #' @examples -#' # forAsics <- alps_asics(dataset) -#' # ASICS(forAsics) -#' +#' library(ASICS) +#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset) +#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +#' forAsics <- to_ASICS(dataset) +#' ASICS(forAsics) #' @export - -alps_asics <- function(samples, ...) { - forAsics <- t(nmr_data(samples)) - forAsics <- ASICS::createSpectra(forAsics, ...) - forAsics@sample.name <-samples$metadata$external$NMRExperiment - return(forAsics) +to_ASICS <- function(dataset, ...) { + require_pkgs("ASICS") + spectra_matrix <- t(nmr_data(dataset)) + ASICS::createSpectra(spectra_matrix, ...) } - abort_if_not <- function(condition, ...) { if (!condition) { rlang::abort(...) From 1169e266d66bb84d2699af030f870b9d72d85a20 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:12:14 +0200 Subject: [PATCH 12/23] Update tests according to autophase and asics changes --- tests/testthat/test-autophase.R | 22 ++++++++++++++++++---- tests/testthat/test-for_asics.R | 23 +++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test-autophase.R b/tests/testthat/test-autophase.R index 0546fe25..0f07d62b 100644 --- a/tests/testthat/test-autophase.R +++ b/tests/testthat/test-autophase.R @@ -1,6 +1,20 @@ test_that("nmr_dataset_autophase works", { skip_if_not_installed("NMRphasing") - dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") - dataset <- nmr_read_samples_dir(dir_to_demo_dataset) - nmr_dataset_autophase(dataset, method="NLS") -}) \ No newline at end of file + lorentzian <- function(x, x0, gamma, A) { + A * (1 / (pi * gamma)) * ((gamma^2) / ((x - x0)^2 + gamma^2)) + } + + x <- seq(from=1, to=2, length.out = 300) + y <- lorentzian(x, 1.3, 0.01, 1) + lorentzian(x, 1.6, 0.01, 1) + dataset <- new_nmr_dataset( + metadata = list(external = data.frame(NMRExperiment = "10")), + data_fields = list( + data_1r = list(y) + ), + axis = list(list(x)) + ) + expect_warning( + nmr_autophase(dataset, method="NLS"), + "all_components=TRUE" + ) +}) diff --git a/tests/testthat/test-for_asics.R b/tests/testthat/test-for_asics.R index 42622a57..99d80da1 100644 --- a/tests/testthat/test-for_asics.R +++ b/tests/testthat/test-for_asics.R @@ -1,8 +1,19 @@ -test_that("alps_asics works", { +test_that("to_ASICS works", { skip_if_not_installed("ASICS") - dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") - dataset <- nmr_read_samples_dir(dir_to_demo_dataset) - dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) - spec_obj <- alps_asics(dataset) - expect_true(class(spec_obj)[1]=="Spectra") + # Create a random spectra matrix + nsamp <- 3 + npoints <- 300 + dummy_ppm_axis <- seq(from = 0.2, to = 10, length.out = npoints) + dummy_spectra_matrix <- matrix(runif(nsamp * npoints), nrow = nsamp, ncol = npoints) + metadata <- list(external = data.frame( + NMRExperiment = paste0("Sample", seq_len(nsamp)), + DummyClass = c("a", "b")[sample.int(2, nsamp, replace=TRUE)] + )) + dummy_nmr_dataset_1D <- new_nmr_dataset_1D( + ppm_axis = dummy_ppm_axis, + data_1r = dummy_spectra_matrix, + metadata = metadata + ) + spec_obj <- to_ASICS(dummy_nmr_dataset_1D) + expect_true(class(spec_obj)[1] == "Spectra") }) \ No newline at end of file From 4c8ecc58ee0d7d2633de172fc3c56a3eb481914e Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:12:28 +0200 Subject: [PATCH 13/23] devtools::document() --- NAMESPACE | 2 +- man/alps_asics.Rd | 27 --------------------------- man/nmr_autophase.Rd | 2 +- man/to_ASICS.Rd | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 29 deletions(-) delete mode 100644 man/alps_asics.Rd create mode 100644 man/to_ASICS.Rd diff --git a/NAMESPACE b/NAMESPACE index a1640fb6..5acd148b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,7 +31,6 @@ export("nmr_data<-") export(.DollarNames) export(SummarizedExperiment_to_nmr_data_1r) export(SummarizedExperiment_to_nmr_dataset_peak_table) -export(alps_asics) export(bp_VIP_analysis) export(bp_kfold_VIP_analysis) export(download_MTBLS242) @@ -132,6 +131,7 @@ export(rename) export(save_files_to_rDolphin) export(save_profiling_output) export(tidy) +export(to_ASICS) export(to_ChemoSpec) export(validate_nmr_dataset) export(validate_nmr_dataset_1D) diff --git a/man/alps_asics.Rd b/man/alps_asics.Rd deleted file mode 100644 index 4deda0a6..00000000 --- a/man/alps_asics.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/asics_helpers.R -\name{alps_asics} -\alias{alps_asics} -\title{Export data for the spectral quantification library ASICS} -\usage{ -alps_asics(samples, ...) -} -\arguments{ -\item{samples}{An \code{nmr_dataset_family} 1D object} - -\item{...}{Additional arguments are passed -directly to \code{ASICS::createSpectra}, which (in theory) provide an -opportunity to use distinct normalisation methods.} -} -\value{ -An \code{ASICS::Spectra} object -} -\description{ -A simple helper function for mangling data in the right format for the -spectral quantification library ASICS. -} -\examples{ -# forAsics <- alps_asics(dataset) -# ASICS(forAsics) - -} diff --git a/man/nmr_autophase.Rd b/man/nmr_autophase.Rd index b6bcc27a..86a3e755 100644 --- a/man/nmr_autophase.Rd +++ b/man/nmr_autophase.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/asics_helpers.R +% Please edit documentation in R/nmr_autophase.R \name{nmr_autophase} \alias{nmr_autophase} \title{Rephase 1D NMR data} diff --git a/man/to_ASICS.Rd b/man/to_ASICS.Rd new file mode 100644 index 00000000..8ab3df20 --- /dev/null +++ b/man/to_ASICS.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{to_ASICS} +\alias{to_ASICS} +\title{Export data for the ASICS spectral quantification library} +\usage{ +to_ASICS(dataset, ...) +} +\arguments{ +\item{dataset}{An \link{nmr_dataset_1D} object} + +\item{...}{ + Arguments passed on to \code{\link[ASICS:createSpectra]{ASICS::createSpectra}} + \describe{ + \item{\code{norm.method}}{Character specifying the normalisation method to use on +spectra ONLY if the \code{\link[ASICS]{importSpectra}} function was not used.} + \item{\code{norm.params}}{List containing normalisation parameteres (see +\code{\link[ASICS]{normaliseSpectra}} for details) ONLY if the +\code{\link[ASICS]{importSpectra}} function was not used.} + }} +} +\value{ +An \link[ASICS:Spectra-class]{ASICS::Spectra} object +} +\description{ +Exports the spectra matrix, sample names and chemical shift axis into +an ASICS Spectra object. +} +\examples{ +library(ASICS) +dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") +dataset <- nmr_read_samples_dir(dir_to_demo_dataset) +dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) +forAsics <- to_ASICS(dataset) +ASICS(forAsics) +} From 95a3f3d355f13577da126091a01404e40d026b27 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:13:59 +0200 Subject: [PATCH 14/23] Reword NEWS --- NEWS.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0982ad52..e1cfa714 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ -# AlpsNMR 4.1.6a (2024-01-19) -- Added two helper functions for autophasing via NMRphasing and export to ASICS +# AlpsNMR 4.7.1 (2024-06-02) + +- Added `nmr_autophase()` for automated phase correction using the NMRphasing package (#68). +- Added `to_ASICS` function to export dataset for ASICS quantification (#68). # AlpsNMR 4.1.6 (2023-02-16) From 753144e0e8708736be15da9d53983334171c9526 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:15:46 +0200 Subject: [PATCH 15/23] Bump version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 62437d71..7b4c5a40 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: AlpsNMR Type: Package Title: Automated spectraL Processing System for NMR -Version: 4.7.0 -Date: 2023-02-16 +Version: 4.7.1 +Date: 2024-06-02 Encoding: UTF-8 Authors@R: c( person(given = "Ivan", From 458d7a5b493b5096b4ccd6fc5aa9fcfe93fe776f Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:51:12 +0200 Subject: [PATCH 16/23] examples run iff suggested pkgs are installed --- R/nmr_autophase.R | 25 ++++++++++++++++++------- R/utils.R | 20 ++++++++++++++------ man/nmr_autophase.Rd | 23 +++++++++++++++++------ man/to_ASICS.Rd | 20 ++++++++++++++------ tests/testthat/test-for_asics.R | 9 +++------ 5 files changed, 66 insertions(+), 31 deletions(-) diff --git a/R/nmr_autophase.R b/R/nmr_autophase.R index 5056c076..52abf728 100644 --- a/R/nmr_autophase.R +++ b/R/nmr_autophase.R @@ -20,12 +20,23 @@ #' @param ... Other parameters passed on to [NMRphasing::NMRphasing()]. #' @return A (hopefully better phased) [nmr_dataset] object, with updated real and imaginary parts. #' @examples -#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) -#' dataset <- nmr_autophase(dataset, method = "NLS") -#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -#' plot(dataset) -#' +#' if (requireNamespace("NMRphasing", quietly=TRUE)) { +#' # Helpers to create a dataset: +#' lorentzian <- function(x, x0, gamma, A) { +#' A * (1 / (pi * gamma)) * ((gamma^2) / ((x - x0)^2 + gamma^2)) +#' } +#' x <- seq(from=1, to=2, length.out = 300) +#' y <- lorentzian(x, 1.3, 0.01, 1) + lorentzian(x, 1.6, 0.01, 1) +#' dataset <- new_nmr_dataset( +#' metadata = list(external = data.frame(NMRExperiment = "10")), +#' data_fields = list(data_1r = list(y)), +#' axis = list(list(x)) +#' ) +#' # Autophase, interpolate and plot: +#' dataset <- nmr_autophase(dataset, method = "NLS") +#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.01)) +#' plot(dataset) +#' } #' @export nmr_autophase <- function(dataset, method = c("NLS", "MPC_DANM", "MPC_EMP", "SPC_DANM", "SPC_EMP", "SPC_AAM", "SPC_DSM"), @@ -62,7 +73,7 @@ nmr_autophase <- function(dataset, miss_sample_names <- paste0(names(any_imag_missing), collapse = ", ") msg <- "Samples without imaginary component: {miss_sample_names}" } else { - miss_sample_names <- paste0(names(head(any_imag_missing, n=5)), collapse = ", ") + miss_sample_names <- paste0(names(utils::head(any_imag_missing, n=5)), collapse = ", ") msg <- "Samples without imaginary component: {miss_sample_names} and {length(any_imag_missing)-5} more" } cli::cli_warn(c( diff --git a/R/utils.R b/R/utils.R index 4b7c3268..1dba2f58 100644 --- a/R/utils.R +++ b/R/utils.R @@ -297,12 +297,20 @@ to_ChemoSpec <- function(nmr_dataset, desc = "A nmr_dataset", group = NULL) { #' @inheritDotParams ASICS::createSpectra -spectra #' @return An [ASICS::Spectra-class] object #' @examples -#' library(ASICS) -#' dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -#' dataset <- nmr_read_samples_dir(dir_to_demo_dataset) -#' dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -#' forAsics <- to_ASICS(dataset) -#' ASICS(forAsics) +#' if (requireNamespace("ASICS", quietly=TRUE)) { +#' nsamp <- 3 +#' npoints <- 300 +#' metadata <- list(external = data.frame( +#' NMRExperiment = paste0("Sample", seq_len(nsamp)) +#' )) +#' dataset <- new_nmr_dataset_1D( +#' ppm_axis = seq(from = 0.2, to = 10, length.out = npoints), +#' data_1r = matrix(runif(nsamp * npoints), nrow = nsamp, ncol = npoints), +#' metadata = metadata +#' ) +#' forAsics <- to_ASICS(dataset) +#' ASICS::ASICS(forAsics) +#' } #' @export to_ASICS <- function(dataset, ...) { require_pkgs("ASICS") diff --git a/man/nmr_autophase.Rd b/man/nmr_autophase.Rd index 86a3e755..45762200 100644 --- a/man/nmr_autophase.Rd +++ b/man/nmr_autophase.Rd @@ -39,10 +39,21 @@ Please use the \code{all_components = TRUE} when calling \code{\link[=nmr_read_s to load the complex spectra and fix NMR phasing correctly. } \examples{ -dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -dataset <- nmr_read_samples_dir(dir_to_demo_dataset, all_components=TRUE) -dataset <- nmr_autophase(dataset, method = "NLS") -dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -plot(dataset) - +if (requireNamespace("NMRphasing", quietly=TRUE)) { + # Helpers to create a dataset: + lorentzian <- function(x, x0, gamma, A) { + A * (1 / (pi * gamma)) * ((gamma^2) / ((x - x0)^2 + gamma^2)) + } + x <- seq(from=1, to=2, length.out = 300) + y <- lorentzian(x, 1.3, 0.01, 1) + lorentzian(x, 1.6, 0.01, 1) + dataset <- new_nmr_dataset( + metadata = list(external = data.frame(NMRExperiment = "10")), + data_fields = list(data_1r = list(y)), + axis = list(list(x)) + ) + # Autophase, interpolate and plot: + dataset <- nmr_autophase(dataset, method = "NLS") + dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.01)) + plot(dataset) +} } diff --git a/man/to_ASICS.Rd b/man/to_ASICS.Rd index 8ab3df20..b99ab181 100644 --- a/man/to_ASICS.Rd +++ b/man/to_ASICS.Rd @@ -27,10 +27,18 @@ Exports the spectra matrix, sample names and chemical shift axis into an ASICS Spectra object. } \examples{ -library(ASICS) -dir_to_demo_dataset <- system.file("dataset-demo", package = "AlpsNMR") -dataset <- nmr_read_samples_dir(dir_to_demo_dataset) -dataset <- nmr_interpolate_1D(dataset, axis = c(min = 1, max = 2, by = 0.002)) -forAsics <- to_ASICS(dataset) -ASICS(forAsics) +if (requireNamespace("ASICS", quietly=TRUE)) { + nsamp <- 3 + npoints <- 300 + metadata <- list(external = data.frame( + NMRExperiment = paste0("Sample", seq_len(nsamp)) + )) + dataset <- new_nmr_dataset_1D( + ppm_axis = seq(from = 0.2, to = 10, length.out = npoints), + data_1r = matrix(runif(nsamp * npoints), nrow = nsamp, ncol = npoints), + metadata = metadata + ) + forAsics <- to_ASICS(dataset) + ASICS::ASICS(forAsics) +} } diff --git a/tests/testthat/test-for_asics.R b/tests/testthat/test-for_asics.R index 99d80da1..23e7d5ce 100644 --- a/tests/testthat/test-for_asics.R +++ b/tests/testthat/test-for_asics.R @@ -3,15 +3,12 @@ test_that("to_ASICS works", { # Create a random spectra matrix nsamp <- 3 npoints <- 300 - dummy_ppm_axis <- seq(from = 0.2, to = 10, length.out = npoints) - dummy_spectra_matrix <- matrix(runif(nsamp * npoints), nrow = nsamp, ncol = npoints) metadata <- list(external = data.frame( - NMRExperiment = paste0("Sample", seq_len(nsamp)), - DummyClass = c("a", "b")[sample.int(2, nsamp, replace=TRUE)] + NMRExperiment = paste0("Sample", seq_len(nsamp)) )) dummy_nmr_dataset_1D <- new_nmr_dataset_1D( - ppm_axis = dummy_ppm_axis, - data_1r = dummy_spectra_matrix, + ppm_axis = seq(from = 0.2, to = 10, length.out = npoints), + data_1r = matrix(runif(nsamp * npoints), nrow = nsamp, ncol = npoints), metadata = metadata ) spec_obj <- to_ASICS(dummy_nmr_dataset_1D) From 29acde2a4b262edf999259e054a86de56ce12889 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:54:36 +0200 Subject: [PATCH 17/23] vignette wording style --- vignettes/Vig01-introduction-to-alpsnmr.Rmd | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/vignettes/Vig01-introduction-to-alpsnmr.Rmd b/vignettes/Vig01-introduction-to-alpsnmr.Rmd index f32c8c48..cac9a4f3 100644 --- a/vignettes/Vig01-introduction-to-alpsnmr.Rmd +++ b/vignettes/Vig01-introduction-to-alpsnmr.Rmd @@ -146,13 +146,12 @@ check out the `vignette("Vig02-handling-metadata-and-annotations", package = "Al # Phasing It might be the case that automatically reconstructed metabolite NMR spectra have -a first-order phase error. A convenient wrapper function is provided to link to -the package `NMRphasing` that provides a variety of algorithms to try to estimate -and correct for phase errors, which arise on physical grounds. `NMRphasing` -performs an optional baseline correction, which here is disabled. +a first-order phase error. AlpsNMR provides a convenient wrapper function +the `NMRphasing` package, offering a variety of algorithms to estimate +and correct for phase errors, which arise on physical grounds. ```{r} -#dataset <- nmr_dataset_autophase(dataset, method="MPC_DANM", withBC=F) +#dataset <- nmr_autophase(dataset, method="MPC_DANM") ``` From f24316624c971c5ce0acb7f95c21bebe0adf8b83 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:54:43 +0200 Subject: [PATCH 18/23] typo --- vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd b/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd index f3a2fe2a..5b7f3b56 100644 --- a/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd +++ b/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd @@ -443,7 +443,7 @@ dplyr::bind_rows( After applying any feature selection or machine learning, Alps allows the identification of features of interest through `nmr_identify_regions_blood`. -The function gives 3 posibilities sorted by the most probable metabolite +The function gives 3 possibilities sorted by the most probable metabolite (see `nmr_identify_regions_blood` for details). ```{r} From 7e2e6e207e22161862dfe39b959a55f2849a681a Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 10:56:46 +0200 Subject: [PATCH 19/23] Remove old warning from future->BiocParallel transition --- DESCRIPTION | 2 +- NAMESPACE | 1 - R/import_jdx.R | 1 - R/nmr_data_analysis.R | 1 - R/nmr_dataset.R | 1 - R/nmr_detect_peaks_align.R | 2 -- R/utils.R | 20 -------------------- 7 files changed, 1 insertion(+), 27 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7b4c5a40..bc17b25c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -59,7 +59,7 @@ License: MIT + file LICENSE URL: https://sipss.github.io/AlpsNMR/, https://github.com/sipss/AlpsNMR BugReports: https://github.com/sipss/AlpsNMR/issues LazyData: FALSE -Depends: R (>= 4.2), future (>= 1.10.0) +Depends: R (>= 4.2) Imports: utils, generics, diff --git a/NAMESPACE b/NAMESPACE index 5acd148b..408a9f39 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -139,7 +139,6 @@ export(validate_nmr_dataset_family) export(validate_nmr_dataset_peak_table) importFrom(dplyr,filter) importFrom(dplyr,rename) -importFrom(future,plan) importFrom(generics,tidy) importFrom(glue,glue) importFrom(glue,glue_collapse) diff --git a/R/import_jdx.R b/R/import_jdx.R index 8d8b5bd9..fb754a5b 100644 --- a/R/import_jdx.R +++ b/R/import_jdx.R @@ -250,7 +250,6 @@ process_block <- function(lines, metadata_only = FALSE) { #' @keywords internal #' @noRd read_jdx <- function(file_names, metadata_only = FALSE) { - warn_future_to_biocparallel() output <- BiocParallel::bplapply( X = file_names, FUN = function(file_name) { diff --git a/R/nmr_data_analysis.R b/R/nmr_data_analysis.R index 8bbb6bfb..ef6bca67 100644 --- a/R/nmr_data_analysis.R +++ b/R/nmr_data_analysis.R @@ -270,7 +270,6 @@ split_build_perform <- function(train_test_subset, do_cv <- function(dataset, y_column, identity_column, train_evaluate_model, train_test_subsets, train_evaluate_model_args_iter = NULL, ..., .enable_parallel = TRUE) { if (.enable_parallel) { - warn_future_to_biocparallel() fun <- mymapply } else { fun <- mapply diff --git a/R/nmr_dataset.R b/R/nmr_dataset.R index 3f314ff7..88132642 100644 --- a/R/nmr_dataset.R +++ b/R/nmr_dataset.R @@ -231,7 +231,6 @@ nmr_read_samples_bruker <- if (length(sample_names) == 0) { stop("No samples to load") } - warn_future_to_biocparallel() list_of_samples <- BiocParallel::bplapply( X = sample_names, FUN = function(sampl, pulse_sequence, metadata_only, ...) { diff --git a/R/nmr_detect_peaks_align.R b/R/nmr_detect_peaks_align.R index c03a5dbc..0e76180e 100644 --- a/R/nmr_detect_peaks_align.R +++ b/R/nmr_detect_peaks_align.R @@ -176,7 +176,6 @@ nmr_detect_peaks <- function(nmr_dataset, ) } - warn_future_to_biocparallel() peakList <- mymapply( FUN = callDetectSpecPeaks, X = data_matrix_to_list, @@ -494,7 +493,6 @@ nmr_detect_peaks_tune_snr <- function(ds, ds1 <- filter(ds, NMRExperiment == !!NMRExperiment) names(SNR_thresholds) <- SNR_thresholds - warn_future_to_biocparallel() peaks_detected_list <- BiocParallel::bplapply( X = SNR_thresholds, FUN = function(SNR.Th, nmr_dataset, ...) { diff --git a/R/utils.R b/R/utils.R index 1dba2f58..3f30cc67 100644 --- a/R/utils.R +++ b/R/utils.R @@ -228,26 +228,6 @@ progress_bar_end <- function(pb) { } } -#' @importFrom future plan -warn_future_to_biocparallel <- function() { - # REMOVE THIS WARNING >ONE YEAR AFTER IT'S BEEN RELEASED to BIOCONDUCTOR - current_plan <- future::plan() - if (inherits(current_plan, "sequential")) { - return() - } - rlang::warn( - message = c( - "AlpsNMR now uses BiocParallel instead of future for parallellization", - "i" = "If you used plan(multisession) or any other plan(), consider removing all plan() calls and use:\n library(BiocParallel)\n register(SnowParam(workers = 3), default = TRUE)", - "i" = "You just need to place that code once, typically at the beginning of your script" - ), - class = "AlpsNMR-future-to-biocparallel-warning", - .frequency = "once", - .frequency_id = "future-to-biocparallel" - ) - return() -} - #' Convert to ChemoSpec Spectra class #' @param nmr_dataset An [nmr_dataset_1D] object From 3d478d7c0a1e12df893d1938c5b627a520ac969d Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 11:03:47 +0200 Subject: [PATCH 20/23] Remove BiocParallel workarounds for - https://github.com/Bioconductor/BiocParallel/pull/227 - https://github.com/Bioconductor/BiocParallel/pull/228 Since they have been merged and released for long. --- DESCRIPTION | 2 +- R/nmr_data_analysis.R | 2 +- R/nmr_detect_peaks_align.R | 2 +- R/workaround-biocparallel-bug.R | 99 --------------------------------- 4 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 R/workaround-biocparallel-bug.R diff --git a/DESCRIPTION b/DESCRIPTION index bc17b25c..c7a12322 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -90,7 +90,7 @@ Imports: ggplot2 (>= 3.1.0), baseline (>= 1.2-1), vctrs (>= 0.3.0), - BiocParallel + BiocParallel (>= 1.34.0) Suggests: ASICS, BiocStyle, diff --git a/R/nmr_data_analysis.R b/R/nmr_data_analysis.R index ef6bca67..2706fa21 100644 --- a/R/nmr_data_analysis.R +++ b/R/nmr_data_analysis.R @@ -270,7 +270,7 @@ split_build_perform <- function(train_test_subset, do_cv <- function(dataset, y_column, identity_column, train_evaluate_model, train_test_subsets, train_evaluate_model_args_iter = NULL, ..., .enable_parallel = TRUE) { if (.enable_parallel) { - fun <- mymapply + fun <- BiocParallel::bpmapply } else { fun <- mapply } diff --git a/R/nmr_detect_peaks_align.R b/R/nmr_detect_peaks_align.R index 0e76180e..82f1abc5 100644 --- a/R/nmr_detect_peaks_align.R +++ b/R/nmr_detect_peaks_align.R @@ -176,7 +176,7 @@ nmr_detect_peaks <- function(nmr_dataset, ) } - peakList <- mymapply( + peakList <- BiocParallel::bpmapply( FUN = callDetectSpecPeaks, X = data_matrix_to_list, baselineThresh = baselineThresh, diff --git a/R/workaround-biocparallel-bug.R b/R/workaround-biocparallel-bug.R deleted file mode 100644 index 49aa0930..00000000 --- a/R/workaround-biocparallel-bug.R +++ /dev/null @@ -1,99 +0,0 @@ -# This whole file is a workaround for: -# - https://github.com/Bioconductor/BiocParallel/pull/227 -# (merged released on Bioconductor 3.16, BiocParallel 1.31.14) -# And a workaround for: -# - https://github.com/Bioconductor/BiocParallel/pull/228 -# (as of 2022-11-04 it is under review) -# -# Please once that's merged and released, ensure you have -# BiocParallel (>= 1.xx.xx?) -# in the DESCRIPTION file, replace all usages of mymapply() with -# BiocParallel::bpmapply() and delete this file. -# -# Most of these functions are copies from the BiocParallel package - -.getDotsForMapply <- function (...) -{ - ddd <- list(...) - if (!length(ddd)) - return(list(list())) - len <- vapply(ddd, length, integer(1L)) - if (!all(len == len[1L])) { - max.len <- max(len) - if (max.len && any(len == 0L)) - stop("zero-length and non-zero length inputs cannot be mixed") - if (any(max.len%%len)) - warning("longer argument not a multiple of length of vector") - ddd <- lapply(ddd, rep_len, length.out = max.len) - } - ddd -} - -.simplify <- function (results, SIMPLIFY = FALSE) -{ - if (SIMPLIFY && length(results)) - results <- simplify2array(results) - results -} - -# see test_utilities.R:test_transposeArgsWithIterations() for all -# USE.NAMES corner cases -.transposeArgsWithIterations <- function(nestedList, USE.NAMES) { - num_arguments <- length(nestedList) - if (num_arguments == 0L) { - return(list()) - } - - # nestedList[[1L]] has the values for the first argument in all iterations - num_iterations <- length(nestedList[[1L]]) - - # count the iterations, and name them if needed - iterations <- seq_len(num_iterations) - if (USE.NAMES) { - first_arg <- nestedList[[1L]] - if (is.character(first_arg) && is.null(names(first_arg))) { - names(iterations) <- first_arg - } else { - names(iterations) <- names(first_arg) - } - } - - # argnames: - argnames <- names(nestedList) - - # on iteration `i` we get the i-th element from each list. - # note that .getDotsForMapply() has taken care already of ensuring that - # nestedList elements are recycled properly - lapply(iterations, function(i) { - x <- lapply(nestedList, function(argi) { - unname(argi[i]) - }) - names(x) <- argnames - x - }) -} - -.wrapMapply <- function(dots, .FUN, .MoreArgs) { - .mapply(.FUN, dots, .MoreArgs)[[1L]] -} - -mymapply <- function(FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE, - BPREDO = list(), BPPARAM = BiocParallel::bpparam(), BPOPTIONS = BiocParallel::bpoptions()) { - ## re-package for lapply - ddd <- .getDotsForMapply(...) - if (!length(ddd)) - return(list()) - - ddd <- .transposeArgsWithIterations(ddd, USE.NAMES) - if (!length(ddd)) - return(ddd) - - FUN <- match.fun(FUN) - - res <- BiocParallel::bplapply(X=ddd, .wrapMapply, .FUN=FUN, - .MoreArgs=MoreArgs, BPREDO=BPREDO, - BPPARAM=BPPARAM, BPOPTIONS = BPOPTIONS) - .simplify(res, SIMPLIFY) -} - - From 257ce91893a7b217bc0b895a4e26e4d022e59e5f Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 11:04:02 +0200 Subject: [PATCH 21/23] Do not run ASICS on example, just convert --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 3f30cc67..d4c366a5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -289,7 +289,7 @@ to_ChemoSpec <- function(nmr_dataset, desc = "A nmr_dataset", group = NULL) { #' metadata = metadata #' ) #' forAsics <- to_ASICS(dataset) -#' ASICS::ASICS(forAsics) +#' #ASICS::ASICS(forAsics) #' } #' @export to_ASICS <- function(dataset, ...) { From 007f94fbd9e9f4c37899cd46d0d9dc04e6262b4a Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 11:04:26 +0200 Subject: [PATCH 22/23] Less parallellization by default in the vignette as suggested by R CMD check --- vignettes/Vig01-introduction-to-alpsnmr.Rmd | 2 +- vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/Vig01-introduction-to-alpsnmr.Rmd b/vignettes/Vig01-introduction-to-alpsnmr.Rmd index cac9a4f3..a3958e82 100644 --- a/vignettes/Vig01-introduction-to-alpsnmr.Rmd +++ b/vignettes/Vig01-introduction-to-alpsnmr.Rmd @@ -49,7 +49,7 @@ that can control the parallellization registering backends. Please check ```{r} #register(SerialParam(), default = TRUE) # disable parallellization -register(SnowParam(workers = 3, exportglobals = FALSE), default = TRUE) # enable parallellization with 3 workers +register(SnowParam(workers = 2, exportglobals = FALSE), default = TRUE) # enable parallellization with 2 workers ``` diff --git a/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd b/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd index 5b7f3b56..03108a7e 100644 --- a/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd +++ b/vignettes/Vig01b-introduction-to-alpsnmr-old-api.Rmd @@ -67,7 +67,7 @@ the `BiocParallel` introduction for further details ```{r} library(BiocParallel) #register(SerialParam(), default = TRUE) # disable parallellization -register(SnowParam(workers = 3, exportglobals = FALSE), default = TRUE) # enable parallellization with 4 workers +register(SnowParam(workers = 2, exportglobals = FALSE), default = TRUE) # enable parallellization with 2 workers ``` From 96e54fe430466d1dbf5a05396683ba14a1035838 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sun, 9 Jun 2024 11:04:54 +0200 Subject: [PATCH 23/23] devtools::document() --- man/to_ASICS.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/to_ASICS.Rd b/man/to_ASICS.Rd index b99ab181..1fc25f02 100644 --- a/man/to_ASICS.Rd +++ b/man/to_ASICS.Rd @@ -39,6 +39,6 @@ if (requireNamespace("ASICS", quietly=TRUE)) { metadata = metadata ) forAsics <- to_ASICS(dataset) - ASICS::ASICS(forAsics) + #ASICS::ASICS(forAsics) } }