Skip to content

Commit

Permalink
fix sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Nov 22, 2024
1 parent 5f8a4f2 commit 7340287
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
8 changes: 4 additions & 4 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ setGeneric("chromPeakData<-", function(object, value)
#' spectra for one chromatographic peak (or a `Spectra` of length 0 if no
#' spectrum was found for the respective chromatographic peak).
#'
#' Parameters `chromPeakColumns` allow the user to add specific metadata
#' Parameter `chromPeakColumns` allows the user to add specific metadata
#' columns from the chromatographic peaks (`chromPeaks`) to the returned
#' spectra object. This can be useful to retain information such as retention
#' time (`rt`), m/z (`mz`). The columns will be named as they is written in the
#' spectra object. This can be useful to keep information such as retention
#' time (`rt`), m/z (`mz`). The columns will be named as they are written in the
#' `chromPeaks` object with the prefix `"chrom_peak_"`. The *peak ID*
#' (i.e., the row name of the peak in the `chromPeaks` matrix) is always added
#' to the spectra object as a metadata column named `"chrom_peak_id"`.
Expand Down Expand Up @@ -811,7 +811,7 @@ setGeneric("featureDefinitions<-", function(object, value)
#'
#' The information from `featureDefinitions` for each feature can be included
#' in the returned [Spectra()] object using the `featureColumns` parameter.
#' This is useful for retaining details such as the median retention time (`rtmed`)
#' This is useful for keeping details such as the median retention time (`rtmed`)
#' or median m/z (`mzmed`). The columns will retain their names as specified
#' in the `featureDefinitions` object, prefixed by `"feature_"`
#' (e.g., `"feature_mzmed"`). Additionally, the *feature ID* (i.e., the row
Expand Down
8 changes: 6 additions & 2 deletions R/XcmsExperiment-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,12 @@
chromPeakColumns = c("rt", "mz"),
BPPARAM = bpparam()) {
method <- match.arg(method)
pks <- .chromPeaks(x)[, c("mz", "mzmin", "mzmax", "rt",
"rtmin", "rtmax", "maxo", "sample")]
if (!chromPeakColumns %in% colnames(.chromPeaks(x)))
stop("One or more of the columns in 'chromPeakColumns' are not ",
"available in the 'chromPeaks' data.")
pks <- .chromPeaks(x)[, union(c("mz", "mzmin", "mzmax", "rt",
"rtmin", "rtmax", "maxo", "sample"),
chromPeakColumns)]
if (ppm != 0)
expandMz <- expandMz + pks[, "mz"] * ppm / 1e6
if (expandMz[1L] != 0) {
Expand Down
3 changes: 3 additions & 0 deletions R/XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,9 @@ setMethod(
if (!hasFeatures(object))
stop("No feature definitions present. Please run ",
"'groupChromPeaks' first.")
if (!featureColumns %in% colnames(featureDefinitions(object)))
stop("One or more of the requested 'featureColumns' are not ",
"present in the feature definitions.")
if (hasAdjustedRtime(object))
object <- applyAdjustedRtime(object)
features_all <- rownames(featureDefinitions(object))
Expand Down
6 changes: 3 additions & 3 deletions man/chromPeakSpectra.Rd

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

2 changes: 1 addition & 1 deletion man/featureSpectra.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test_XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,9 @@ test_that("chromPeakSpectra works", {
expect_error(chromPeakSpectra(xmse, peaks = "other"), "out of bounds")

pks <- c("CP242", "CP007", "CP123")

expect_error(chromPeakSpectra(xmse, peaks = pks,
chromPeakColumns = "other"), "not available")
res <- chromPeakSpectra(xmse, peaks = pks)
expect_s4_class(res, "Spectra")
expect_equal(length(res), 0)
Expand Down Expand Up @@ -1081,6 +1084,8 @@ test_that("filterFeatureDefinitions works", {

test_that("featureSpectra works", {
expect_error(featureSpectra(xmse), "No feature definitions")
expect_error(featureSpectra(xmseg,
featureColumns = "other"), "not present")
res_all <- featureSpectra(xmseg, msLevel = 1L)
expect_s4_class(res_all, "Spectra")
expect_true(all(rownames(featureDefinitions(xmseg)) %in%
Expand Down

0 comments on commit 7340287

Please sign in to comment.