diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 213219483..7e4f257cf 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -12,21 +12,21 @@ setGeneric("addParams<-", function(object, value) standardGeneric("addParams<-") setGeneric("addProcessHistory", function(object, ...) standardGeneric("addProcessHistory")) -#' @aliases adjustRtime ObiwarpParam-class PeakGroupsParam-class LamaParama-class +#' @aliases adjustRtime ObiwarpParam-class PeakGroupsParam-class #' #' @title Alignment: Retention time correction methods. #' #' @description #' #' The `adjustRtime` method(s) perform retention time correction (alignment) -#' between chromatograms of different samples/dataset. Alignment is performed by default -#' on MS level 1 data. Retention times of spectra from other MS levels, if -#' present, are subsequently adjusted based on the adjusted retention times -#' of the MS1 spectra. Note that calling `adjustRtime` on a *xcms* result object -#' will remove any eventually present previous alignment results as well as -#' any correspondence analysis results. To run a second round of alignment, -#' raw retention times need to be replaced with adjusted ones using the -#' [applyAdjustedRtime()] function. +#' between chromatograms of different samples/dataset. Alignment is performed +#' by default on MS level 1 data. Retention times of spectra from other MS +#' levels, if present, are subsequently adjusted based on the adjusted +#' retention times of the MS1 spectra. Note that calling `adjustRtime` on a +#' *xcms* result object will remove any eventually present previous alignment +#' results as well as any correspondence analysis results. To run a second +#' round of alignment, raw retention times need to be replaced with adjusted +#' ones using the [applyAdjustedRtime()] function. #' #' The alignment method can be specified (and configured) using a dedicated #' `param` argument. @@ -100,10 +100,6 @@ setGeneric("addProcessHistory", function(object, ...) #' @param BPPARAM parallel processing setup. Defaults to `BPPARAM = bpparam()`. #' See [bpparam()] for details. #' -#' @param bs For `LamaParama`: `character(1)` defining the GAM moothing method. -#' (defaults to thin plate; NB: B- and P-splines have been shown to produce -#' artefacts). -#' #' @param centerSample \code{integer(1)} defining the index of the center sample #' in the experiment. It defaults to #' \code{floor(median(1:length(fileNames(object))))}. Note that if @@ -164,16 +160,9 @@ setGeneric("addProcessHistory", function(object, ...) #' @param initPenalty For `ObiwarpParam`: `numeric(1)` defining the penalty for #' initiating an alignment (for local alignment only). #' -#' @param lamas For `LamaParama`: `matrix` or `data.frame` with the m/z and -#' retention times values of features (as first and second column) from the -#' external dataset on which the alignment will be based on. -#' #' @param localAlignment For `ObiwarpParam`: `logical(1)` whether a local #' alignment should be performed instead of the default global alignment. #' -#' @param method For `LamaParama`:`character(1)` with the type of warping. -#' Either `method = "gam"` or `method = "loess"` (default). -#' #' @param minFraction For `PeakGroupsParam`: `numeric(1)` between 0 and 1 #' defining the minimum required proportion of samples in which peaks for #' the peak group were identified. Peak groups passing this criteria will @@ -191,12 +180,6 @@ setGeneric("addProcessHistory", function(object, ...) #' @param object For `adjustRtime`: an [OnDiskMSnExp()], [XCMSnExp()], #' [MsExperiment()] or [XcmsExperiment()] object. #' -#' @param outlierTolerance For `LamaParama`: `numeric(1)` defining the settings -#' for outlier removal during the fitting. By default -#' (with `outlierTolerance = 3`), all data points with absolute residuals -#' larger than 3 times the mean absolute residual of all data points from -#' the first, initial fit, are removed from the final model fit. -#' #' @param param The parameter object defining the alignment method (and its #' setting). #' @@ -206,10 +189,6 @@ setGeneric("addProcessHistory", function(object, ...) #' feature/peak group. The `adjustRtimePeakGroups` method is used by #' default to determine this matrix on the provided `object`. #' -#' @param ppm For `LamaParama`: `numeric(1)` defining the m/z-relative maximal -#' allowed difference in m/z between `lamas` and chromatographic peaks. Used -#' for the mapping of identified chromatographic peaks and lamas. -#' #' @param response For `ObiwarpParam`: `numeric(1)` defining the #' *responsiveness* of warping with `response = 0` giving linear warping on #' start and end points and `response = 100` warping using all bijective @@ -219,9 +198,9 @@ setGeneric("addProcessHistory", function(object, ...) #' be used to interpolate corrected retention times for all peak groups. #' Can be either `"loess"` or `"linear"`. #' -#' @param span For `PeakGroupsParam` and `LamaParama`: `numeric(1)` defining -#' the degree of smoothing (if `smooth = "loess"` or `method = "loess"`). -#' This parameter is passed to the internal call to [loess()]. +#' @param span For `PeakGroupsParam`: `numeric(1)` defining +#' the degree of smoothing (if `smooth = "loess"`). This parameter is +#' passed to the internal call to [loess()]. #' #' @param subset For `ObiwarpParam` and `PeakGroupsParam`: `integer` with the #' indices of samples within the experiment on which the alignment models @@ -234,24 +213,10 @@ setGeneric("addProcessHistory", function(object, ...) #' Supported options are `"previous"` and `"average"` (default). #' See *Subset-based alignment* section for details. #' -#' @param tolerance For `LamaParama`: `numeric(1)` defining the absolute -#' acceptable difference in m/z between lamas and chromatographic peaks. -#' Used for the mapping of identified chromatographic peaks and `lamas`. -#' -#' @param toleranceRt For `LamaParama`: `numeric(1)` defining the absolute -#' acceptable difference in retention time between lamas and -#' chromatographic peaks. Used for the mapping of identified chromatographic -#' peaks and `lamas`. -#' #' @param value For all assignment methods: the value to set/replace. #' #' @param x An `ObiwarpParam`, `PeakGroupsParam` or `LamaParama` object. #' -#' @param zeroWeight For `LamaParama`: `numeric(1)`: defines the weight of the -#' first data point (i.e. retention times of the first lama-chromatographic -#' peak pair). Values larger than 1 reduce warping problems in the early RT -#' range. -#' #' @param ... ignored. #' #' @return diff --git a/R/XcmsExperiment.R b/R/XcmsExperiment.R index c769c3674..cad8a9c2b 100644 --- a/R/XcmsExperiment.R +++ b/R/XcmsExperiment.R @@ -1357,7 +1357,7 @@ setMethod( object }) -#'@rdname adjustRtime +#'@rdname LamaParama setMethod( "adjustRtime", signature(object = "XcmsExperiment", param = "LamaParama"), function(object, param, BPPARAM = bpparam(), ...) { diff --git a/R/do_adjustRtime-functions.R b/R/do_adjustRtime-functions.R index ffed94d6f..2d11ae2ed 100644 --- a/R/do_adjustRtime-functions.R +++ b/R/do_adjustRtime-functions.R @@ -622,8 +622,9 @@ adjustRtimeSubset <- function(rtraw, rtadj, subset, #' #' Other functions related to this method: #' -#' - `LamaParama()`: create the parameter object for alignment using -#' `adjustRtime()` function. Is also the input for functions listed below. +#' - `LamaParama()`: return the respective the parameter object for alignment +#' using `adjustRtime()` function. Is also the input for functions listed +#' below. #' #' - `matchLamasChromPeaks()`: quickly matches each file's ChromPeaks #' to Lamas, allowing the user to evaluate the matches for each file. @@ -634,18 +635,71 @@ adjustRtimeSubset <- function(rtraw, rtadj, subset, #' - `matchedRtimes()`: Access the list of `data.frame` saved in the #' `LamaParama` object, generated by the `matchLamasChromPeaks()` function. #' +#' - `plot()`:plot the chromatographic peaks versus the reference lamas as +#' well as the fitting line for the chosen model type. The user can decide +#' what file to inspect by specifying the assay number with the parameter +#' `assay` +#' #' #' @param BPPARAM For `matchLamasChromPeaks()`: parallel processing setup. #' Defaults to `BPPARAM = bpparam()`. See [bpparam()] for more information. #' +#' @param bs For `LamaParama()`: `character(1)` defining the GAM smoothing method. +#' (defaults to thin plate, `bs = "tp"`) +#' +#' @param colPoints For `plot()`: color for the plotting of the datapoint. +#' +#' @param colFit For `plot()`: color of the fitting line. +#' +#' @param index For `plot()`: `numeric(1)` index of the file that should be +#' plotted. +#' +#' @param lamas For `LamaParama`: `matrix` or `data.frame` with the m/z and +#' retention times values of features (as first and second column) from the +#' external dataset on which the alignment will be based on. +#' +#' +#' @param method For `LamaParama`:`character(1)` with the type of warping. +#' Either `method = "gam"` or `method = "loess"` (default). +#' #' @param object An object of class `XcmsExperiment` with defined ChromPeaks. #' +#' @param outlierTolerance For `LamaParama`: `numeric(1)` defining the settings +#' for outlier removal during the fitting. By default +#' (with `outlierTolerance = 3`), all data points with absolute residuals +#' larger than 3 times the mean absolute residual of all data points from +#' the first, initial fit, are removed from the final model fit. +#' #' @param param An object of class `LamaParama` that will later be used for #' adjustment using the `[adjustRtime()]` function. #' -#' @param LamaParama same object that will be passed to the `adjustRtime()` -#' function. To run this function the `matchLamasChromPeaks()` need to be run -#' on this first. +#' @param ppm For `LamaParama`: `numeric(1)` defining the m/z-relative maximal +#' allowed difference in m/z between `lamas` and chromatographic peaks. Used +#' for the mapping of identified chromatographic peaks and lamas. +#' +#' @param span For `LamaParama`: `numeric(1)` defining +#' the degree of smoothing (`method = "loess"`). This parameter is passed +#' to the internal call to [loess()]. +#' +#' @param tolerance For `LamaParama`: `numeric(1)` defining the absolute +#' acceptable difference in m/z between lamas and chromatographic peaks. +#' Used for the mapping of identified chromatographic peaks and `lamas`. +#' +#' @param toleranceRt For `LamaParama`: `numeric(1)` defining the absolute +#' acceptable difference in retention time between lamas and +#' chromatographic peaks. Used for the mapping of identified chromatographic +#' peaks and `lamas`. +#' +#' @param x For `plot()`: object of class `LamaParama` to be plotted. +#' +#' @param xlab,ylab For `plot()`: x- and y-axis labels. +#' +#' @param zeroWeight For `LamaParama`: `numeric(1)`: defines the weight of the +#' first data point (i.e. retention times of the first lama-chromatographic +#' peak pair). Values larger than 1 reduce warping problems in the early RT +#' range. +#' +#' @param ... For `plot()`: extra parameters to be passed to the function. #' #' @return #' For `matchLamasChromPeaks()`: A `LamaParama` object with new slot `rtMap` @@ -671,6 +725,7 @@ adjustRtimeSubset <- function(rtraw, rtadj, subset, #' tst <- loadXcmsData("faahko_sub2") #' #' ## create lamas input from the reference dataset +#' library(MsExperiment) #' f <- sampleData(ref)$sample_type #' f[f == "QC"] <- NA #' ref <- filterFeatures(ref, PercentMissingFilter(threshold = 0, f = f)) @@ -861,7 +916,7 @@ matchLamasChromPeaks <- function(object, param, BPPARAM = bpparam()){ if (!hasChromPeaks(object)) stop("'object' needs to have detected ChromPeaks. ", "Run 'findChromPeaks()' first.") - f <- as.factor(chromPeaks(object)[, "sample"], levels = seq_along(object)) + f <- factor(chromPeaks(object)[, "sample"], levels = seq_along(object)) cp_raw <- split.data.frame(chromPeaks(object)[, c("mz", "rt")], f) param@nChromPeaks <- vapply(cp_raw, nrow, numeric(1)) param@rtMap <- bplapply(cp_raw, FUN = function(x) { @@ -894,13 +949,7 @@ summarizeLamaMatch <- function(param){ res } -#' @title Perform linear interpolation for unsorted retention time. -#' -#' @description -#' This function performs linear interpolation on the non-sorted parts of an -#' input vector of retention time. To see more details on the interpolation, -#' see [approx()] -#' + #' @param rtime `numeric` vector with the retention times for one file/sample. #' #' @return vector with sorted retention time. diff --git a/R/functions-Params.R b/R/functions-Params.R index be73a3427..104702ecd 100644 --- a/R/functions-Params.R +++ b/R/functions-Params.R @@ -274,7 +274,7 @@ PeakGroupsParam <- function(minFraction = 0.9, extraPeaks = 1, subset = as.integer(subset), subsetAdjust = subsetAdjust) } -#' @rdname adjustRtime +#' @rdname LamaParama LamaParama <- function(lamas = matrix(ncol = 2, nrow = 0, dimnames = list(NULL, c("mz", "rt"))), method = c("loess", "gam"), @@ -284,9 +284,7 @@ LamaParama <- function(lamas = matrix(ncol = 2, nrow = 0, ppm = 20, tolerance = 0, toleranceRt = 5, - bs = "tp", - rtMap = list(), - nChromPeaks = numeric()) { + bs = "tp") { method <- match.arg(method) if (method == "gam") .check_gam_library() @@ -304,9 +302,7 @@ LamaParama <- function(lamas = matrix(ncol = 2, nrow = 0, ppm = ppm, tolerance = tolerance, toleranceRt = toleranceRt, - bs = bs, - rtMap = rtMap, - nChromPeaks = nChromPeaks) + bs = bs) } #' @rdname adjustRtime diff --git a/R/methods-Params.R b/R/methods-Params.R index a358450c7..0843298c8 100644 --- a/R/methods-Params.R +++ b/R/methods-Params.R @@ -1252,35 +1252,21 @@ setReplaceMethod("subsetAdjust", "PeakGroupsParam", function(object, value) { ############################################################ ## LamaParama -#' @title Plot summary of information of matching lamas to chromPeaks -#' -#' @description -#' the `plot()` function for `LamaParama` object allows to plot the obs -#' chromatographic peaks versus the reference lamas as well as the fitting -#' line for the chosen model type. The user can decide what file to inspect by -#' specifying the assay number with the parameter `assay` -#' -#' @param assay `numeric(1)`, assay that should be plotted. -#' -#' @return A plot -#' -#' @export -#' -#' @noRd -setMethod("plot", "LamaParama", function(x, index = 1L, colPoints = "#00000060", - colFit = "#00000080", - xlab = "Matched Chromatographic peaks", - ylab = "Lamas", - main = NULL,...){ - model <- xcms:::.rt_model(method = param@method, - rt_map= x@rtMap[[index]], span = param@span, - resid_ratio = param@outlierTolerance, - zero_weight = param@zeroWeight, - bs = param@bs) - x <- x@rtMap[[index]] - plot(x, type = "p", xlab = xlab, ylab = ylab, col = "blue", - main = main) - points(model, type = "l", col = "black") +#' @rdname LamaParama +setMethod("plot", signature(x = "LamaParama"), + function(x, index = 1L, + colPoints = "#00000060", + colFit = "#00000080", + xlab = "Matched Chromatographic peaks", + ylab = "Lamas",...){ + model <- .rt_model(method = x@method, + rt_map= x@rtMap[[index]], span = x@span, + resid_ratio = x@outlierTolerance, + zero_weight = x@zeroWeight, + bs = x@bs) + datap <- x@rtMap[[index]] + plot(datap, type = "p", xlab = xlab, ylab = ylab, col = colPoints, ...) + points(model, type = "l", col = colFit) }) diff --git a/man/LamaParama.Rd b/man/LamaParama.Rd index e2d79f7b3..34c397ac2 100644 --- a/man/LamaParama.Rd +++ b/man/LamaParama.Rd @@ -1,19 +1,46 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/do_adjustRtime-functions.R -\name{LamaParama} +% Please edit documentation in R/XcmsExperiment.R, R/do_adjustRtime-functions.R, +% R/functions-Params.R, R/methods-Params.R +\name{adjustRtime,XcmsExperiment,LamaParama-method} +\alias{adjustRtime,XcmsExperiment,LamaParama-method} \alias{LamaParama} \alias{LamaParama-class} \alias{matchLamasChromPeaks} \alias{summarizeLamaMatch} \alias{matchedRtimes} +\alias{plot,LamaParama,ANY-method} \title{Landmark-based alignment: aligning a dataset against an external reference} \usage{ +\S4method{adjustRtime}{XcmsExperiment,LamaParama}(object, param, BPPARAM = bpparam(), ...) + matchLamasChromPeaks(object, param, BPPARAM = bpparam()) summarizeLamaMatch(param) matchedRtimes(param) + +LamaParama( + lamas = matrix(ncol = 2, nrow = 0, dimnames = list(NULL, c("mz", "rt"))), + method = c("loess", "gam"), + span = 0.5, + outlierTolerance = 3, + zeroWeight = 10, + ppm = 20, + tolerance = 0, + toleranceRt = 5, + bs = "tp" +) + +\S4method{plot}{LamaParama,ANY}( + x, + index = 1L, + colPoints = "#00000060", + colFit = "#00000080", + xlab = "Matched Chromatographic peaks", + ylab = "Lamas", + ... +) } \arguments{ \item{object}{An object of class `XcmsExperiment` with defined ChromPeaks.} @@ -24,9 +51,56 @@ adjustment using the `[adjustRtime()]` function.} \item{BPPARAM}{For `matchLamasChromPeaks()`: parallel processing setup. Defaults to `BPPARAM = bpparam()`. See [bpparam()] for more information.} -\item{LamaParama}{same object that will be passed to the `adjustRtime()` -function. To run this function the `matchLamasChromPeaks()` need to be run -on this first.} +\item{...}{For `plot()`: extra parameters to be passed to the function.} + +\item{lamas}{For `LamaParama`: `matrix` or `data.frame` with the m/z and +retention times values of features (as first and second column) from the +external dataset on which the alignment will be based on.} + +\item{method}{For `LamaParama`:`character(1)` with the type of warping. +Either `method = "gam"` or `method = "loess"` (default).} + +\item{span}{For `LamaParama`: `numeric(1)` defining +the degree of smoothing (`method = "loess"`). This parameter is passed +to the internal call to [loess()].} + +\item{outlierTolerance}{For `LamaParama`: `numeric(1)` defining the settings +for outlier removal during the fitting. By default +(with `outlierTolerance = 3`), all data points with absolute residuals +larger than 3 times the mean absolute residual of all data points from +the first, initial fit, are removed from the final model fit.} + +\item{zeroWeight}{For `LamaParama`: `numeric(1)`: defines the weight of the +first data point (i.e. retention times of the first lama-chromatographic +peak pair). Values larger than 1 reduce warping problems in the early RT +range.} + +\item{ppm}{For `LamaParama`: `numeric(1)` defining the m/z-relative maximal +allowed difference in m/z between `lamas` and chromatographic peaks. Used +for the mapping of identified chromatographic peaks and lamas.} + +\item{tolerance}{For `LamaParama`: `numeric(1)` defining the absolute +acceptable difference in m/z between lamas and chromatographic peaks. +Used for the mapping of identified chromatographic peaks and `lamas`.} + +\item{toleranceRt}{For `LamaParama`: `numeric(1)` defining the absolute +acceptable difference in retention time between lamas and +chromatographic peaks. Used for the mapping of identified chromatographic +peaks and `lamas`.} + +\item{bs}{For `LamaParama()`: `character(1)` defining the GAM smoothing method. +(defaults to thin plate, `bs = "tp"`)} + +\item{x}{For `plot()`: object of class `LamaParama` to be plotted.} + +\item{index}{For `plot()`: `numeric(1)` index of the file that should be +plotted.} + +\item{colPoints}{For `plot()`: color for the plotting of the datapoint.} + +\item{colFit}{For `plot()`: color of the fitting line.} + +\item{xlab, ylab}{For `plot()`: x- and y-axis labels.} } \value{ For `matchLamasChromPeaks()`: A `LamaParama` object with new slot `rtMap` @@ -77,8 +151,9 @@ a single file. Other functions related to this method: - - `LamaParama()`: create the parameter object for alignment using - `adjustRtime()` function. Is also the input for functions listed below. + - `LamaParama()`: return the respective the parameter object for alignment + using `adjustRtime()` function. Is also the input for functions listed + below. - `matchLamasChromPeaks()`: quickly matches each file's ChromPeaks to Lamas, allowing the user to evaluate the matches for each file. @@ -88,6 +163,11 @@ Other functions related to this method: - `matchedRtimes()`: Access the list of `data.frame` saved in the `LamaParama` object, generated by the `matchLamasChromPeaks()` function. + + - `plot()`:plot the chromatographic peaks versus the reference lamas as + well as the fitting line for the chosen model type. The user can decide + what file to inspect by specifying the assay number with the parameter + `assay` } \note{ If there are no matches when using `matchLamasChromPeaks()`, the file @@ -103,6 +183,7 @@ ref <- loadXcmsData("xmse") tst <- loadXcmsData("faahko_sub2") ## create lamas input from the reference dataset +library(MsExperiment) f <- sampleData(ref)$sample_type f[f == "QC"] <- NA ref <- filterFeatures(ref, PercentMissingFilter(threshold = 0, f = f)) diff --git a/man/adjustRtime.Rd b/man/adjustRtime.Rd index f6904aaf0..884a3778a 100644 --- a/man/adjustRtime.Rd +++ b/man/adjustRtime.Rd @@ -6,12 +6,9 @@ \alias{adjustRtime} \alias{ObiwarpParam-class} \alias{PeakGroupsParam-class} -\alias{LamaParama-class} \alias{adjustRtime,MsExperiment,ObiwarpParam-method} \alias{adjustRtime,MsExperiment,PeakGroupsParam-method} -\alias{adjustRtime,XcmsExperiment,LamaParama-method} \alias{PeakGroupsParam} -\alias{LamaParama} \alias{ObiwarpParam} \alias{adjustRtimePeakGroups} \alias{adjustRtime,OnDiskMSnExp,ObiwarpParam-method} @@ -97,8 +94,6 @@ adjustRtime(object, param, ...) \S4method{adjustRtime}{MsExperiment,PeakGroupsParam}(object, param, msLevel = 1L, ...) -\S4method{adjustRtime}{XcmsExperiment,LamaParama}(object, param, BPPARAM = bpparam(), ...) - PeakGroupsParam( minFraction = 0.9, extraPeaks = 1, @@ -110,20 +105,6 @@ PeakGroupsParam( subsetAdjust = c("average", "previous") ) -LamaParama( - lamas = matrix(ncol = 2, nrow = 0, dimnames = list(NULL, c("mz", "rt"))), - method = c("loess", "gam"), - span = 0.5, - outlierTolerance = 3, - zeroWeight = 10, - ppm = 20, - tolerance = 0, - toleranceRt = 5, - bs = "tp", - rtMap = list(), - nChromPeaks = numeric() -) - ObiwarpParam( binSize = 1, centerSample = integer(), @@ -278,9 +259,9 @@ sample that are assigned to the group.} be used to interpolate corrected retention times for all peak groups. Can be either \code{"loess"} or \code{"linear"}.} -\item{span}{For \code{PeakGroupsParam} and \code{LamaParama}: \code{numeric(1)} defining -the degree of smoothing (if \code{smooth = "loess"} or \code{method = "loess"}). -This parameter is passed to the internal call to \code{\link[=loess]{loess()}}.} +\item{span}{For \code{PeakGroupsParam}: \code{numeric(1)} defining +the degree of smoothing (if \code{smooth = "loess"}). This parameter is +passed to the internal call to \code{\link[=loess]{loess()}}.} \item{family}{For \code{PeakGroupsParam}: \code{character(1)} defining the method for loess smoothing. Allowed values are \code{"gaussian"} and \code{"symmetric"}. See @@ -303,41 +284,6 @@ specifying the method with which non-subset samples should be adjusted. Supported options are \code{"previous"} and \code{"average"} (default). See \emph{Subset-based alignment} section for details.} -\item{lamas}{For \code{LamaParama}: \code{matrix} or \code{data.frame} with the m/z and -retention times values of features (as first and second column) from the -external dataset on which the alignment will be based on.} - -\item{method}{For \code{LamaParama}:\code{character(1)} with the type of warping. -Either \code{method = "gam"} or \code{method = "loess"} (default).} - -\item{outlierTolerance}{For \code{LamaParama}: \code{numeric(1)} defining the settings -for outlier removal during the fitting. By default -(with \code{outlierTolerance = 3}), all data points with absolute residuals -larger than 3 times the mean absolute residual of all data points from -the first, initial fit, are removed from the final model fit.} - -\item{zeroWeight}{For \code{LamaParama}: \code{numeric(1)}: defines the weight of the -first data point (i.e. retention times of the first lama-chromatographic -peak pair). Values larger than 1 reduce warping problems in the early RT -range.} - -\item{ppm}{For \code{LamaParama}: \code{numeric(1)} defining the m/z-relative maximal -allowed difference in m/z between \code{lamas} and chromatographic peaks. Used -for the mapping of identified chromatographic peaks and lamas.} - -\item{tolerance}{For \code{LamaParama}: \code{numeric(1)} defining the absolute -acceptable difference in m/z between lamas and chromatographic peaks. -Used for the mapping of identified chromatographic peaks and \code{lamas}.} - -\item{toleranceRt}{For \code{LamaParama}: \code{numeric(1)} defining the absolute -acceptable difference in retention time between lamas and -chromatographic peaks. Used for the mapping of identified chromatographic -peaks and \code{lamas}.} - -\item{bs}{For \code{LamaParama}: \code{character(1)} defining the GAM moothing method. -(defaults to thin plate; NB: B- and P-splines have been shown to produce -artefacts).} - \item{binSize}{\code{numeric(1)} defining the bin size (in mz dimension) to be used for the \emph{profile matrix} generation. See \code{step} parameter in \code{\link{profile-matrix}} documentation for more details.} @@ -403,14 +349,14 @@ features in each sample (each row one feature, each row one sample). } \description{ The \code{adjustRtime} method(s) perform retention time correction (alignment) -between chromatograms of different samples/dataset. Alignment is performed by default -on MS level 1 data. Retention times of spectra from other MS levels, if -present, are subsequently adjusted based on the adjusted retention times -of the MS1 spectra. Note that calling \code{adjustRtime} on a \emph{xcms} result object -will remove any eventually present previous alignment results as well as -any correspondence analysis results. To run a second round of alignment, -raw retention times need to be replaced with adjusted ones using the -\code{\link[=applyAdjustedRtime]{applyAdjustedRtime()}} function. +between chromatograms of different samples/dataset. Alignment is performed +by default on MS level 1 data. Retention times of spectra from other MS +levels, if present, are subsequently adjusted based on the adjusted +retention times of the MS1 spectra. Note that calling \code{adjustRtime} on a +\emph{xcms} result object will remove any eventually present previous alignment +results as well as any correspondence analysis results. To run a second +round of alignment, raw retention times need to be replaced with adjusted +ones using the \code{\link[=applyAdjustedRtime]{applyAdjustedRtime()}} function. The alignment method can be specified (and configured) using a dedicated \code{param} argument. diff --git a/man/do_adjustRtime_peakGroups.Rd b/man/do_adjustRtime_peakGroups.Rd index 996e42553..4d0d898ea 100644 --- a/man/do_adjustRtime_peakGroups.Rd +++ b/man/do_adjustRtime_peakGroups.Rd @@ -52,9 +52,9 @@ sample that are assigned to the group.} be used to interpolate corrected retention times for all peak groups. Can be either \code{"loess"} or \code{"linear"}.} -\item{span}{For \code{PeakGroupsParam} and \code{LamaParama}: \code{numeric(1)} defining -the degree of smoothing (if \code{smooth = "loess"} or \code{method = "loess"}). -This parameter is passed to the internal call to \code{\link[=loess]{loess()}}.} +\item{span}{For \code{PeakGroupsParam}: \code{numeric(1)} defining +the degree of smoothing (if \code{smooth = "loess"}). This parameter is +passed to the internal call to \code{\link[=loess]{loess()}}.} \item{family}{For \code{PeakGroupsParam}: \code{character(1)} defining the method for loess smoothing. Allowed values are \code{"gaussian"} and \code{"symmetric"}. See diff --git a/tests/testthat/test_do_adjustRtime-functions.R b/tests/testthat/test_do_adjustRtime-functions.R index ef8545469..7c2cb2110 100644 --- a/tests/testthat/test_do_adjustRtime-functions.R +++ b/tests/testthat/test_do_adjustRtime-functions.R @@ -353,7 +353,7 @@ test_that(".adjust_rt_model works", { expect_true(mean(abs(rt_adj - rt_ref)) < mean(abs(rt_raw - rt_ref))) }) -test_that("linear_interpolate_vec interpolates correctly", { +test_that("force_sorted interpolates correctly", { vec <- c(NA, NA, NA, 1.2, 1.1, 1.14, 1.2, 1.3, 1.1, 1.04, 1.4, 1.6, NA, NA) # Expected result after interpolation sorted <- c(NA, NA, NA, 1.2, 1.225, 1.25, 1.275, 1.3, 1.333, 1.367, @@ -379,8 +379,8 @@ test_that("matchLamasChromPeaks works", { expect_equal(param@rtMap, list()) param <- matchLamasChromPeaks(tst, param) expect_true(inherits(param, "LamaParama")) - expect_equal(length(param@rtMap), length(object)) - expect_equal(length(param@nChromPeaks), length(object)) + expect_equal(length(param@rtMap), length(tst)) + expect_equal(length(param@nChromPeaks), length(tst)) }) test_that("summarizeLamaMatch works", { @@ -396,7 +396,7 @@ test_that("summarizeLamaMatch works", { test_that("Accessing rtMap from LamaParama object works", { param <- LamaParama(lamas = ref_mz_rt, toleranceRt = 10) param <- matchLamasChromPeaks(tst, param) - expect_error(rtMap(ObiwarpParam()), "class") - rtMap <- rtMap(param) - expect_equal(length(rtMap), length(param@rtMap)) + expect_error(matchedRtimes(ObiwarpParam()), "class") + mtch <- matchedRtimes(param) + expect_equal(length(mtch), length(param@rtMap)) }) diff --git a/vignettes/xcms.Rmd b/vignettes/xcms.Rmd index 2ab5b6694..e420bd564 100644 --- a/vignettes/xcms.Rmd +++ b/vignettes/xcms.Rmd @@ -1409,7 +1409,7 @@ summary$Matched_peaks / summary$Total_peaks * 100 summary$model_summary[[1]] # Plot obs vs. ref with fitting line -plot(param, index = 1L, main = "ChromPeaks versur lamas for the first file") +plot(param, index = 1L, main = "ChromPeaks versur Lamas for the first file") ``` # Additional details and notes