Skip to content

Commit

Permalink
fix: coercion from XcmsExperiment to XCMSnExp
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Aug 5, 2024
1 parent 1bd6d3d commit b4ed18b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R/XcmsExperiment-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,9 @@ XcmsExperiment <- function() {
files = fileNames(from),
smoothed = NA)
n@phenoData <- new("NAnnotatedDataFrame", as.data.frame(sampleData(from)))
fd <- as.data.frame(MsExperiment::spectra(from)@backend@spectraData)
fd$fileIdx <- match(fd$dataStorage, unique(fd$dataStorage))
fd <- as.data.frame(from@spectra@backend@spectraData)
fnames <- unique(fd$dataStorage)
fd$fileIdx <- match(fd$dataStorage, fnames)
fd <- fd[, !colnames(fd) %in% c("dataStorage", "dataOrigin")]
colnames(fd) <- sub("scanIndex", "spIdx", colnames(fd))
colnames(fd) <- sub("rtime", "retentionTime", colnames(fd))
Expand All @@ -1180,13 +1181,18 @@ XcmsExperiment <- function() {
fd$fileIdx, fd$spIdx,
max(fd$fileIdx), max(fd$spIdx))
n@featureData <- new("AnnotatedDataFrame", fd)
nf <- length(fileNames(from))
nf <- length(fnames)
n@experimentData <- new("MIAPE",
instrumentManufacturer = rep(NA_character_, nf),
instrumentModel = rep(NA_character_, nf),
ionSource = rep(NA_character_, nf),
analyser = rep(NA_character_, nf),
detectorType = rep(NA_character_, nf))
n@processingData <- new("MSnProcess",
processing = paste0("Coercion from ",
class(from)[1L],
" [", date(), "]"),
files = fnames)
## -> XCMSnExp
if (hasChromPeaks(from)) {
chromPeaks(m) <- chromPeaks(from)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_XcmsExperiment-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ test_that(".features_ms_region works", {
})

test_that(".xcms_experiment_to_xcms_n_exp works", {
library(MsExperiment)
a <- XcmsExperiment()
res <- xcms:::.xcms_experiment_to_xcms_n_exp(a)
expect_s4_class(res, "XCMSnExp")
Expand Down

0 comments on commit b4ed18b

Please sign in to comment.