Skip to content

Commit

Permalink
refactor: throw error for adjustRtime with alignment results
Browse files Browse the repository at this point in the history
- Throw an error for `adjustRtime` if alignment results are already present.
  • Loading branch information
jorainer committed Dec 1, 2023
1 parent 66313e0 commit 6f8d802
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 10 additions & 5 deletions R/XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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
})

Expand Down
4 changes: 3 additions & 1 deletion man/adjustRtime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test_XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f8d802

Please sign in to comment.