Skip to content

Commit 5f8a4f2

Browse files
committed
jo comments
1 parent 8f6fa9a commit 5f8a4f2

6 files changed

+54
-102
lines changed

R/AllGenerics.R

+17-31
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,13 @@ setGeneric("chromPeakData<-", function(object, value)
417417
#' spectra for one chromatographic peak (or a `Spectra` of length 0 if no
418418
#' spectrum was found for the respective chromatographic peak).
419419
#'
420-
#' Parameters `addColumnsChromPeaks` allow the user to add specific metadata
420+
#' Parameters `chromPeakColumns` allow the user to add specific metadata
421421
#' columns from the chromatographic peaks (`chromPeaks`) to the returned
422422
#' spectra object. This can be useful to retain information such as retention
423423
#' time (`rt`), m/z (`mz`). The columns will be named as they is written in the
424-
#' `chromPeaks` object with a prefix that is defined by the parameter
425-
#' `addColumnsChromPeaksPrefix`. The *peak ID* (i.e., the row name of the
426-
#' peak in the `chromPeaks` matrix) is always added to the spectra object as
427-
#' metadata column `paste0(addColumnsChromPeaksPrefix,id)`, by default it will
428-
#' be `"chrom_peak_id"`.
424+
#' `chromPeaks` object with the prefix `"chrom_peak_"`. The *peak ID*
425+
#' (i.e., the row name of the peak in the `chromPeaks` matrix) is always added
426+
#' to the spectra object as a metadata column named `"chrom_peak_id"`.
429427
#'
430428
#' See also the *LC-MS/MS data analysis* vignette for more details and examples.
431429
#'
@@ -460,15 +458,10 @@ setGeneric("chromPeakData<-", function(object, value)
460458
#' @param return.type `character(1)` defining the type of result object that
461459
#' should be returned.
462460
#'
463-
#' @param addColumnsChromPeaks `character` vector with the names of the columns
461+
#' @param chromPeakColumns `character` vector with the names of the columns
464462
#' from `chromPeaks` that should be added to the returned spectra object.
465463
#' The columns will be named as they are written in the `chromPeaks` object
466-
#' with a prefix that is defined by the parameter
467-
#' `addColumnsChromPeaksPrefix`. Defaults to `c("mz", "rt")`.
468-
#'
469-
#' @param addColumnsChromPeaksPrefix `character(1)` defining the prefix that
470-
#' should be used for the columns from `chromPeaks` that are added to the
471-
#' returned spectra object. Defaults to `"chrom_peak_"`.
464+
#' with a prefix `"chrom_peak_"`. Defaults to `c("mz", "rt")`.
472465
#'
473466
#' @param BPPARAM parallel processing setup. Defaults to [bpparam()].
474467
#'
@@ -517,7 +510,7 @@ setGeneric("chromPeakData<-", function(object, value)
517510
#' ms2_sps <- chromPeakSpectra(dda)
518511
#' ms2_sps
519512
#'
520-
#' ## spectra variable *peak_id* contain the row names of the peaks in the
513+
#' ## spectra variable *chrom_peak_id* contain the row names of the peaks in the
521514
#' ## chromPeak matrix and allow thus to map chromatographic peaks to the
522515
#' ## returned MS2 spectra
523516
#' ms2_sps$chrom_peak_id
@@ -817,23 +810,20 @@ setGeneric("featureDefinitions<-", function(object, value)
817810
#' spectra per feature).
818811
#'
819812
#' The information from `featureDefinitions` for each feature can be included
820-
#' in the returned [Spectra()] object using the `addColumnsFeatures` parameter.
813+
#' in the returned [Spectra()] object using the `featureColumns` parameter.
821814
#' This is useful for retaining details such as the median retention time (`rtmed`)
822815
#' or median m/z (`mzmed`). The columns will retain their names as specified
823-
#' in the `featureDefinitions` object, prefixed by the value of the
824-
#' `addColumnsFeaturesPrefix` parameter. Additionally, the *feature ID*
825-
#' (i.e., the row name of the feature in the `featureDefinitions` data.frame)
826-
#' is always added as a metadata column with the name
827-
#' `paste0(addColumnsFeaturesPrefix, "id")`, which defaults to `"feature_id"`.
816+
#' in the `featureDefinitions` object, prefixed by `"feature_"`
817+
#' (e.g., `"feature_mzmed"`). Additionally, the *feature ID* (i.e., the row
818+
#' name of the feature in the `featureDefinitions` data.frame) is always added
819+
#' as a metadata column named `"feature_id"`.
828820
#'
829821
#' See also [chromPeakSpectra()], as it supports a similar parameter for
830822
#' including columns from the chromatographic peaks in the returned spectra object.
831823
#' These parameters can be used in combination to include information from both
832824
#' the chromatographic peaks and the features in the returned [Spectra()].
833825
#' The *peak ID* (i.e., the row name of the peak in the `chromPeaks` matrix)
834-
#' is added as a metadata column with the name
835-
#' `paste0(addColumnsChromPeaksPrefix, "id")`, which defaults to
836-
#' `"chrom_peak_id"`.
826+
#' is added as a metadata column named `"chrom_peak_id"`.
837827
#'
838828
#' @param object [XcmsExperiment] or [XCMSnExp] object with feature defitions.
839829
#'
@@ -846,15 +836,11 @@ setGeneric("featureDefinitions<-", function(object, value)
846836
#' `featureDefinitions(x)`). This parameter overrides `skipFilled` and is
847837
#' only supported for `return.type` being either `"Spectra"` or `"List"`.
848838
#'
849-
#' @param addColumnsFeatures `character` vector with the names of the columns
839+
#' @param featureColumns `character` vector with the names of the columns
850840
#' from `featureDefinitions` that should be added to the returned spectra
851841
#' object. The columns will be named as they are written in the
852-
#' `featureDefinitions` object with a prefix that is defined by the parameter
853-
#' `addColumnsFeaturesPrefix`. Defaults to `c("mzmed", "rtmed")`.
854-
#'
855-
#' @param addColumnsFeaturesPrefix `character(1)` defining the prefix that
856-
#' should be used for the columns from `featureDefinitions` that are added
857-
#' to the returned spectra object. Defaults to `"feature_"`.
842+
#' `featureDefinitions` object with the prefix `"feature_`.
843+
#' Defaults to `c("mzmed", "rtmed")`.
858844
#'
859845
#' @param ... additional arguments to be passed along to [chromPeakSpectra()],
860846
#' such as `method`.
@@ -866,7 +852,7 @@ setGeneric("featureDefinitions<-", function(object, value)
866852
#' the order and the length matches parameter `features` (or if no `features`
867853
#' is defined the order of the features in `featureDefinitions(object)`).
868854
#'
869-
#' Spectra variables `"peak_id"` and `"feature_id"` define to which
855+
#' Spectra variables `"chrom_peak_id"` and `"feature_id"` define to which
870856
#' chromatographic peak or feature each individual spectrum is associated
871857
#' with.
872858
#'

R/XcmsExperiment-functions.R

+5-10
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@
794794
msLevel = 2L, expandRt = 0, expandMz = 0,
795795
ppm = 0, skipFilled = FALSE,
796796
peaks = integer(),
797-
addColumnsChromPeaks = c("rt", "mz"),
798-
addColumnsChromPeaksPrefix = "chrom_peak_",
797+
chromPeakColumns = c("rt", "mz"),
799798
BPPARAM = bpparam()) {
800799
method <- match.arg(method)
801800
pks <- .chromPeaks(x)[, c("mz", "mzmin", "mzmax", "rt",
@@ -821,8 +820,7 @@
821820
res <- bpmapply(
822821
split.data.frame(pks, f),
823822
split(spectra(x), factor(fromFile(x), levels = levels(f))),
824-
FUN = function(pk, sp, msLevel, method, addColumnsChromPeaks,
825-
addColumnsChromPeaksPrefix) {
823+
FUN = function(pk, sp, msLevel, method, chromPeakColumns) {
826824
sp <- filterMsLevel(sp, msLevel)
827825
idx <- switch(
828826
method,
@@ -833,17 +831,14 @@
833831
largest_bpi = .spectra_index_list_largest_bpi(sp, pk, msLevel))
834832
ids <- rep(rownames(pk), lengths(idx))
835833
res <- sp[unlist(idx)]
836-
pk_data <- as.data.frame(pk[ids, addColumnsChromPeaks,
837-
drop = FALSE])
834+
pk_data <- as.data.frame(pk[ids, chromPeakColumns, drop = FALSE])
838835
pk_data$id <- ids
839-
colnames(pk_data) <- paste0(addColumnsChromPeaksPrefix,
840-
colnames(pk_data))
836+
colnames(pk_data) <- paste0("chrom_peak_", colnames(pk_data))
841837
res <- .add_spectra_data(res, pk_data)
842838
res
843839
},
844840
MoreArgs = list(msLevel = msLevel, method = method,
845-
addColumnsChromPeaks = addColumnsChromPeaks,
846-
addColumnsChromPeaksPrefix = addColumnsChromPeaksPrefix),
841+
chromPeakColumns = chromPeakColumns),
847842
BPPARAM = BPPARAM)
848843
Spectra:::.concatenate_spectra(res)
849844
}

R/XcmsExperiment.R

+12-20
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,7 @@ setMethod(
12291229
"largest_tic", "largest_bpi"),
12301230
msLevel = 2L, expandRt = 0, expandMz = 0, ppm = 0,
12311231
skipFilled = FALSE, peaks = character(),
1232-
addColumnsChromPeaks = c("rt", "mz"),
1233-
addColumnsChromPeaksPrefix = "chrom_peak_",
1232+
chromPeakColumns = c("rt", "mz"),
12341233
return.type = c("Spectra", "List"), BPPARAM = bpparam()) {
12351234
if (hasAdjustedRtime(object))
12361235
object <- applyAdjustedRtime(object)
@@ -1246,19 +1245,15 @@ setMethod(
12461245
else pkidx <- integer()
12471246
res <- .mse_spectra_for_peaks(object, method, msLevel, expandRt,
12481247
expandMz, ppm, skipFilled, pkidx,
1249-
addColumnsChromPeaks,
1250-
addColumnsChromPeaksPrefix,
1248+
chromPeakColumns,
12511249
BPPARAM)
12521250
if (!length(pkidx))
12531251
peaks <- rownames(.chromPeaks(object))
12541252
else peaks <- rownames(.chromPeaks(object))[pkidx]
1255-
if (return.type == "Spectra") {
1256-
col <- paste0(addColumnsChromPeaksPrefix, "id")
1257-
res <- res[as.matrix(findMatches(peaks, res[[col]]))[, 2L]]
1258-
} else {
1259-
col <- paste0(addColumnsChromPeaksPrefix, "id")
1260-
as(split(res, factor(res[[col]], levels = peaks)), "List")
1261-
}
1253+
if (return.type == "Spectra")
1254+
res <- res[as.matrix(findMatches(peaks, res$chrom_peak_id))[, 2L]]
1255+
else
1256+
as(split(res, factor(res$chrom_peak_id, levels = peaks)), "List")
12621257
})
12631258

12641259
#' @rdname reconstructChromPeakSpectra
@@ -1781,9 +1776,7 @@ setMethod(
17811776
function(object, msLevel = 2L, expandRt = 0, expandMz = 0, ppm = 0,
17821777
skipFilled = FALSE, return.type = c("Spectra", "List"),
17831778
features = character(),
1784-
addColumnsFeatures = c("rtmed", "mzmed"),
1785-
addColumnsFeaturesPrefix = "feature_",
1786-
addColumnsChromPeaksPrefix = "chrom_peak_",
1779+
featureColumns = c("rtmed", "mzmed"),
17871780
...) {
17881781
return.type <- match.arg(return.type)
17891782
if (!hasFeatures(object))
@@ -1803,17 +1796,16 @@ setMethod(
18031796
sps <- .mse_spectra_for_peaks(
18041797
object, msLevel = msLevel, expandRt = expandRt,
18051798
expandMz = expandMz, ppm = ppm, skipFilled = skipFilled,
1806-
peaks = unique(pindex),
1807-
addColumnsChromPeaksPrefix = addColumnsChromPeaksPrefix, ...)
1808-
col <- paste0(addColumnsChromPeaksPrefix, "id")
1799+
peaks = unique(pindex), ...)
18091800
mtch <- as.matrix(
1810-
findMatches(sps[[col]], rownames(.chromPeaks(object))[pindex]))
1801+
findMatches(sps$chrom_peak_id,
1802+
rownames(.chromPeaks(object))[pindex]))
18111803
sps <- sps[mtch[, 1L]]
18121804
fid <- rep(
18131805
ufeatures, lengths(featureDefinitions(object)$peakidx[findex]))
1814-
f_data <- featureDefinitions(object)[fid[mtch[, 2L]], addColumnsFeatures]
1806+
f_data <- featureDefinitions(object)[fid[mtch[, 2L]], featureColumns]
18151807
f_data$id <- fid[mtch[, 2L]]
1816-
colnames(f_data) <- paste0(addColumnsFeaturesPrefix, colnames(f_data))
1808+
colnames(f_data) <- paste0("feature_", colnames(f_data))
18171809
sps <- .add_spectra_data(sps, f_data)
18181810
if (return.type == "List") {
18191811
sps <- List(split(sps, f = factor(sps$feature_id,

man/chromPeakSpectra.Rd

+8-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/featureSpectra.Rd

+11-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/xcms-lcms-ms.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ dda_spectra$chrom_peak_id
206206
```
207207

208208
Some information about the chromatographic peak can also be added to the
209-
returned `Spectra` object using the `addChromPeaksColumns` parameter in
209+
returned `Spectra` object using the `chrompeakColumns` parameter in
210210
`chromPeakSpectra()`. By default, the m/z and retention time of the
211211
chromatographic peak are added to the spectra metadata.
212212

0 commit comments

Comments
 (0)