From 357448607781d15311fa2d261309e0b2fb35ba2b Mon Sep 17 00:00:00 2001 From: jorainer Date: Fri, 7 Jun 2024 09:32:15 +0200 Subject: [PATCH] fix: add fix for plot,MsExperiment for LC-MS/MS data - Add the fix merged with PR #741 into the devel branch also to the release branch. - The fix addresses the error generated when `plot,MsExperiment` is called on a `MsExperiment` with MS1 and MS2 spectra (issue #734). --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ R/XcmsExperiment-plotting.R | 5 +++-- tests/testthat/test_XcmsExperiment-plotting.R | 6 ++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f435def08..6c0175a5c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: xcms -Version: 4.2.1 +Version: 4.2.2 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, diff --git a/NEWS.md b/NEWS.md index b8090dde3..60764371d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # xcms 4.2 +## Changes in version 4.2.2 + +- Fix for issue #734: `plot,MsExperiment` is now working with `MsExperiment` + that have also MS2 Data. + + ## Changes in version 4.2.1 - Fix in `dropFeatureDefinitions()` that was not correctly removing additional diff --git a/R/XcmsExperiment-plotting.R b/R/XcmsExperiment-plotting.R index 2771c6c4b..e657f7519 100644 --- a/R/XcmsExperiment-plotting.R +++ b/R/XcmsExperiment-plotting.R @@ -380,12 +380,13 @@ setMethod( fns <- basename(fileNames(x)) for (i in seq_along(x)) { z <- x[i] - lst <- as(filterMsLevel(spectra(z), msLevel = msLevel), "list") + flt <- filterMsLevel(spectra(z), msLevel = msLevel) + lst <- as(flt, "list") lns <- lengths(lst) / 2 lst <- do.call(rbind, lst) if (!length(lst)) next - df <- data.frame(rt = rep(rtime(z), lns), lst) + df <- data.frame(rt = rep(rtime(flt), lns), lst) colnames(df)[colnames(df) == "intensity"] <- "i" do.call(MSnbase:::.plotXIC, c(list(x = df, main = fns[i], layout = NULL), dots)) diff --git a/tests/testthat/test_XcmsExperiment-plotting.R b/tests/testthat/test_XcmsExperiment-plotting.R index b28679f81..76c858033 100644 --- a/tests/testthat/test_XcmsExperiment-plotting.R +++ b/tests/testthat/test_XcmsExperiment-plotting.R @@ -4,6 +4,7 @@ df <- data.frame(mzML_file = basename(fls), dataOrigin = fls, sample = c("ko15", "ko16", "ko18")) mse <- readMsExperiment(spectraFiles = fls, sampleData = df) +mse_ms2 <- readMsExperiment(msdata::proteomics(full.names=TRUE)[4]) p <- CentWaveParam(noise = 10000, snthresh = 40, prefilter = c(3, 10000)) xmse <- findChromPeaks(mse, param = p) pdp <- PeakDensityParam(sampleGroups = rep(1, 3)) @@ -51,3 +52,8 @@ test_that("plot,XcmsExperiment and .xmse_plot_xic works", { tmp <- filterMz(filterRt(xmse, rt = c(2550, 2800)), mz = c(342.5, 344.5)) plot(tmp) }) + +test_that(".xmse_plot_xic works with ms2 data", { + tmp <- filterMz(filterRt(mse_ms2, rt= c(2160, 2190)), mz = c(990,1000)) + plot(tmp) +})