diff --git a/R/AllGenerics.R b/R/AllGenerics.R index e4f0e9c31..c97e6b32b 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -24,7 +24,9 @@ setGeneric("addProcessHistory", function(object, ...) #' 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. +#' 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. diff --git a/R/XcmsExperiment.R b/R/XcmsExperiment.R index 32e8dd6fd..aef1c0be8 100644 --- a/R/XcmsExperiment.R +++ b/R/XcmsExperiment.R @@ -1353,10 +1353,12 @@ setMethod( function(object, param, msLevel = 1L, ...) { if (!inherits(object, "XcmsExperiment")) object <- as(object, "XcmsExperiment") - if (hasAdjustedRtime(object)) { - message("Removing previous alignment results") - object <- dropAdjustedRtime(object) - } + if (hasAdjustedRtime(object)) + stop("Alignment results already present. Please either remove ", + "them with 'dropAdjustedRtime' in order to perform an ", + "alternative, new, alignment, or use 'applyAdjustedRtime'", + " prior 'adjustRtime' to perform a second round of ", + "alignment.") if (any(msLevel != 1L)) stop("Alignment is currently only supported for MS level 1") if (!nrow(peakGroupsMatrix(param))) { @@ -1410,8 +1412,11 @@ setMethod("dropAdjustedRtime", "XcmsExperiment", function(object) { object@spectra, svs[svs != "rtime_adjusted"]) object@processHistory <- dropProcessHistoriesList( object@processHistory, type = .PROCSTEP.RTIME.CORRECTION, num = 1L) - if (hasFeatures(object) && idx_co > idx_al) + if (hasFeatures(object) && idx_co > idx_al) { + warning("Had to remove feature definitions along with the adjusted ", + "retention times because of the dependency between them.") object <- dropFeatureDefinitions(object) + } object }) diff --git a/man/adjustRtime.Rd b/man/adjustRtime.Rd index 3ed93450e..70b8182a0 100644 --- a/man/adjustRtime.Rd +++ b/man/adjustRtime.Rd @@ -353,7 +353,9 @@ 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. +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/tests/testthat/test_XcmsExperiment.R b/tests/testthat/test_XcmsExperiment.R index 458b754f7..09569ba84 100644 --- a/tests/testthat/test_XcmsExperiment.R +++ b/tests/testthat/test_XcmsExperiment.R @@ -464,6 +464,7 @@ test_that("adjustRtime,MsExperiment,PeakGroupsParam works", { expect_equal(unname(rtime(xod_xgr)), unname(rtime(res))) expect_true(length(res@processHistory) == 3L) expect_true(sum(rtime(res) != rtime(a)) > 1000) + expect_error(adjustRtime(res, param = pgp), "applyAdjustedRtime") ## Run with pre-defined anchor peak data p <- res@processHistory[[3]]@param