Skip to content

Commit

Permalink
refactor: calculate beta columns for gap filling of XcmsExperiment
Browse files Browse the repository at this point in the history
- Bump version.
- Calculate beta peak shape quality metrics also during gap filling for
  `XcmsExperiment` objects.
- Add related unit tests.
  • Loading branch information
jorainer committed Nov 28, 2023
1 parent fe214c9 commit 5c2d193
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: xcms
Version: 4.1.2
Version: 4.1.3
Title: LC-MS and GC-MS Data Analysis
Description: Framework for processing and visualization of chromatographically
separated and single-spectra mass spectral data. Imports from AIA/ANDI NetCDF,
Expand Down Expand Up @@ -30,7 +30,7 @@ Authors@R: c(
email = "[email protected]",
role = "ctb"),
person(given = "William", family = "Kumler",
email = "[email protected]", role = "ctb",
email = "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-5022-8009")),
person(given = "Philippine", family = "Louail",
email = "[email protected]",
Expand Down Expand Up @@ -70,7 +70,7 @@ Suggests:
faahKO,
msdata (>= 0.25.1),
ncdf4,
testthat,
testthat (>= 3.1.9),
pander,
rmarkdown,
MALDIquant,
Expand Down
3 changes: 3 additions & 0 deletions R/XcmsExperiment-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@
sum(mat[, 2L], na.rm = TRUE) *
((rtr[2L] - rtr[1L]) / max(1L, (length(keep) - 1L)))
)
if ("beta_cor" %in% cn)
res[i, c("beta_cor", "beta_snr")] <- .get_beta_values(
mat[, 2L], rts)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions R/functions-XCMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,10 @@ dropGenericProcessHistory <- function(x, fun) {
meanMz <- do.call(mzCenterFun, list(mtx[, 2], mtx[, 3]))
if (is.na(meanMz)) meanMz <- mtx[maxi[1], 2]
res[i, "mz"] <- meanMz

if("beta_cor"%in%cn){
res[i, c("beta_cor", "beta_snr")] <- .get_beta_values(mtx[,3])

if ("beta_cor" %in% cn) {
res[i, c("beta_cor", "beta_snr")] <- .get_beta_values(
mtx[, 3L], mtx[, 1L])
}
} else {
res[i, ] <- rep(NA_real_, ncols)
Expand Down
2 changes: 2 additions & 0 deletions R/methods-XCMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,8 @@ setMethod("smooth", "XCMSnExp", function(x, method = c("SavitzkyGolay",
setAs(from = "XCMSnExp", to = "xcmsSet", def = .XCMSnExp2xcmsSet)

#' @rdname XcmsExperiment
#'
#' @name XcmsExperiment
setAs(from = "XcmsExperiment", to = "xcmsSet", def = .XCMSnExp2xcmsSet)

#' @rdname XCMSnExp-peak-grouping-results
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes in version 4.1.3
----------------------

- Add parameter `verboseBetaColumns` to `CentWaveParam` to enable calculation
of additional peak quality metrics comparing the EIC to an idealized bell
curve.

Changes in version 4.1.2
----------------------

Expand Down
2 changes: 1 addition & 1 deletion man/XcmsExperiment.Rd

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

13 changes: 13 additions & 0 deletions tests/testthat/test_XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -1326,3 +1326,16 @@ test_that("storeResults,RDataParam works", {
expect_s4_class(object, "XcmsExperiment")
expect_equal(object, xmse)
})

test_that("fillChromPeaks,XcmsExperiment works with verboseBetaColumns", {
p <- CentWaveParam(noise = 10000, snthresh = 40, prefilter = c(3, 10000),
verboseBetaColumns = TRUE)
res <- findChromPeaks(mse, param = p)
expect_true(all(c("beta_cor", "beta_snr") %in% colnames(chromPeaks(res))))
p <- PeakDensityParam(sampleGroups = rep(1, 3))
res <- groupChromPeaks(res, param = p)
res <- fillChromPeaks(res, ChromPeakAreaParam())
pks_det <- chromPeaks(res)[!chromPeakData(res)$is_filled, ]
pks_fil <- chromPeaks(res)[chromPeakData(res)$is_filled, ]
expect_true(!any(is.na(pks_fil[, "beta_cor"])))
})

0 comments on commit 5c2d193

Please sign in to comment.