From da0f19b731a8f1071b08e134c6d26ec757bc5232 Mon Sep 17 00:00:00 2001 From: J Wokaty Date: Tue, 30 Apr 2024 11:40:07 -0400 Subject: [PATCH 1/5] bump x.y.z version to even y prior to creation of RELEASE_3_19 branch --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb17039..aa0094c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MetaboAnnotation Title: Utilities for Annotation of Metabolomics Data -Version: 1.7.5 +Version: 1.8.0 Description: High level functions to assist in annotation of (metabolomics) data sets. These include functions to perform simple tentative annotations based on From 0c8b461367ce67a044b77f38d534750ba0518dac Mon Sep 17 00:00:00 2001 From: J Wokaty Date: Tue, 30 Apr 2024 11:40:07 -0400 Subject: [PATCH 2/5] bump x.y.z version to odd y following creation of RELEASE_3_19 branch --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa0094c..48acb78 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MetaboAnnotation Title: Utilities for Annotation of Metabolomics Data -Version: 1.8.0 +Version: 1.9.0 Description: High level functions to assist in annotation of (metabolomics) data sets. These include functions to perform simple tentative annotations based on From 3d42907a50dc96a7f9f737abb91f2e17ee2259c5 Mon Sep 17 00:00:00 2001 From: jorainer Date: Wed, 15 May 2024 08:23:25 +0200 Subject: [PATCH 3/5] feat: add parameter scalePeaks to plotSpectraMirror - Add parameter `scalePeaks` to `plotSpectraMirror()` to allow scaling of the peak intensities before plotting. --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 7 +++++ R/MatchedSpectra.R | 44 ++++++++++++++++++---------- man/MatchedSpectra.Rd | 19 ++++++++++-- tests/testthat/test_MatchedSpectra.R | 6 ++++ 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb17039..84d2e5f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MetaboAnnotation Title: Utilities for Annotation of Metabolomics Data -Version: 1.7.5 +Version: 1.9.1 Description: High level functions to assist in annotation of (metabolomics) data sets. These include functions to perform simple tentative annotations based on diff --git a/NAMESPACE b/NAMESPACE index dd16d16..b9065f7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -84,6 +84,7 @@ importFrom(S4Vectors,endoapply) importFrom(Spectra,MsBackendDataFrame) importFrom(Spectra,Spectra) importFrom(Spectra,joinPeaks) +importFrom(grDevices,n2mfrow) importFrom(graphics,par) importFrom(methods,"slot<-") importFrom(methods,as) diff --git a/NEWS.md b/NEWS.md index dfe5c1f..f12d0e1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# MetaboAnnotation 1.9 + +## Changes in 1.9.1 + +- Add parameter `scalePeaks` to `plotSpectraMirror` to allow scaling peak + intensities before plotting. + # MetaboAnnotation 1.7 ## Changes in 1.7.5 diff --git a/R/MatchedSpectra.R b/R/MatchedSpectra.R index cd374cf..fa497e1 100644 --- a/R/MatchedSpectra.R +++ b/R/MatchedSpectra.R @@ -96,8 +96,10 @@ #' #' - `plotSpectraMirror`: creates a mirror plot between the query and each #' matching target spectrum. Can only be applied to a `MatchedSpectra` with a -#' single query spectrum. Additional plotting parameters can be passed through -#' `...`. +#' single query spectrum. Setting parameter `scalePeaks = TRUE` will scale +#' the peak intensities per spectrum to a total sum of one for a better +#' graphical visualization. Additional plotting parameters can be passed +#' through `...`. #' #' - `setBackend`: allows to change the *backend* of both the query and target #' [Spectra()] object. The function will return a `MatchedSpectra` object with @@ -123,6 +125,10 @@ #' #' @param object `MatchedSpectra` object. #' +#' @param scalePeaks for `plotSpectraMirror`: `logical(1)` if peak intensities +#' (per spectrum) should be scaled to a total sum of one (per spectrum) prior +#' to plotting. +#' #' @param spectraVariables for `addProcessing`: `character` with additional #' spectra variables that should be passed along to the function defined #' with `FUN`. See [Spectra()] for details. @@ -405,21 +411,27 @@ setMethod( #' #' @importFrom graphics par #' +#' @importFrom grDevices n2mfrow +#' #' @export -setMethod("plotSpectraMirror", "MatchedSpectra", function(x, xlab = "m/z", - ylab = "intensity", - main = "", ...) { - if (length(query(x)) != 1) - stop("Length of 'query(x)' has to be 1.") - y <- x@target[x@matches$target_idx] - if (!length(y)) - y <- Spectra(DataFrame(msLevel = 2L)) - nr <- sqrt(max(length(y), 1)) - par(mfrow = c(floor(nr), ceiling(nr))) - for (i in seq_along(y)) - plotSpectraMirror(x = query(x)[1L], y = y[i], - xlab = xlab, ylab = ylab, main = main, ...) -}) +setMethod( + "plotSpectraMirror", "MatchedSpectra", + function(x, xlab = "m/z", ylab = "intensity", main = "", + scalePeaks = FALSE, ...) { + if (length(query(x)) != 1) + stop("Length of 'query(x)' has to be 1.") + y <- x@target[x@matches$target_idx] + if (!length(y)) + y <- Spectra(DataFrame(msLevel = 2L)) + if (scalePeaks) { + x <- scalePeaks(query(x)[1L]) + y <- scalePeaks(y) + } else x <- query(x)[1L] + par(mfrow = n2mfrow(length(y))) + for (i in seq_along(y)) + plotSpectraMirror(x = x, y = y[i], + xlab = xlab, ylab = ylab, main = main, ...) + }) #' @importMethodsFrom ProtGenerics setBackend #' diff --git a/man/MatchedSpectra.Rd b/man/MatchedSpectra.Rd index 9645c5e..839acaa 100644 --- a/man/MatchedSpectra.Rd +++ b/man/MatchedSpectra.Rd @@ -37,7 +37,14 @@ MatchedSpectra( \S4method{addProcessing}{MatchedSpectra}(object, FUN, ..., spectraVariables = character()) -\S4method{plotSpectraMirror}{MatchedSpectra}(x, xlab = "m/z", ylab = "intensity", main = "", ...) +\S4method{plotSpectraMirror}{MatchedSpectra}( + x, + xlab = "m/z", + ylab = "intensity", + main = "", + scalePeaks = FALSE, + ... +) \S4method{setBackend}{MatchedSpectra,MsBackend}(object, backend, ...) } @@ -77,6 +84,10 @@ with \code{FUN}. See \code{\link[=Spectra]{Spectra()}} for details.} \item{main}{for \code{plotSpectraMirror}: an optional title for each plot.} +\item{scalePeaks}{for \code{plotSpectraMirror}: \code{logical(1)} if peak intensities +(per spectrum) should be scaled to a total sum of one (per spectrum) prior +to plotting.} + \item{backend}{for \code{setBackend}: instance of an object extending \link{MsBackend}. See help for \code{setBackend} in \code{\link[=Spectra]{Spectra()}} for more details.} } @@ -168,8 +179,10 @@ with \code{"target_"}). information. \item \code{plotSpectraMirror}: creates a mirror plot between the query and each matching target spectrum. Can only be applied to a \code{MatchedSpectra} with a -single query spectrum. Additional plotting parameters can be passed through -\code{...}. +single query spectrum. Setting parameter \code{scalePeaks = TRUE} will scale +the peak intensities per spectrum to a total sum of one for a better +graphical visualization. Additional plotting parameters can be passed +through \code{...}. \item \code{setBackend}: allows to change the \emph{backend} of both the query and target \code{\link[=Spectra]{Spectra()}} object. The function will return a \code{MatchedSpectra} object with the query and target \code{Spectra} changed to the specified \code{backend}, which diff --git a/tests/testthat/test_MatchedSpectra.R b/tests/testthat/test_MatchedSpectra.R index 77a3989..dcbd54d 100644 --- a/tests/testthat/test_MatchedSpectra.R +++ b/tests/testthat/test_MatchedSpectra.R @@ -220,6 +220,12 @@ test_that("pruneTarget,MatchedSpectra works", { test_that("plotSpectraMirror throws an error", { ms <- MatchedSpectra() expect_error(plotSpectraMirror(ms), "Length") + + ms <- MatchedSpectra(sp1, sp2, matches = data.frame(query_idx = integer(), + target_idx = integer(), + score = numeric())) + plotSpectraMirror(ms[1]) + plotSpectraMirror(ms[1], scalePeaks = TRUE) }) test_that("addProcessing works", { From 9c04ee0ae67e74bd0a2d8190765e3fbfcb215273 Mon Sep 17 00:00:00 2001 From: jorainer Date: Wed, 15 May 2024 08:34:23 +0200 Subject: [PATCH 4/5] ci: use Bioconductor 3.20 devel --- .github/workflows/check-bioc.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-bioc.yml b/.github/workflows/check-bioc.yml index 47a9979..43614b7 100644 --- a/.github/workflows/check-bioc.yml +++ b/.github/workflows/check-bioc.yml @@ -53,9 +53,9 @@ jobs: fail-fast: false matrix: config: - - { os: ubuntu-latest, r: 'devel', bioc: '3.19', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } - - { os: macOS-latest, r: 'devel', bioc: '3.19'} - - { os: windows-latest, r: 'devel', bioc: '3.19'} + - { os: ubuntu-latest, r: '4.4', bioc: '3.20', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + - { os: macOS-latest, r: '4.4', bioc: '3.20'} + - { os: windows-latest, r: '4.4', bioc: '3.20'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} From f31941e9eb06fcc464aa2e11e6a648f89e0c518f Mon Sep 17 00:00:00 2001 From: jorainer Date: Wed, 15 May 2024 09:21:22 +0200 Subject: [PATCH 5/5] fix: add missing import for scalePeaks() --- NAMESPACE | 1 + R/MatchedSpectra.R | 2 ++ 2 files changed, 3 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index b9065f7..508f604 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -84,6 +84,7 @@ importFrom(S4Vectors,endoapply) importFrom(Spectra,MsBackendDataFrame) importFrom(Spectra,Spectra) importFrom(Spectra,joinPeaks) +importFrom(Spectra,scalePeaks) importFrom(grDevices,n2mfrow) importFrom(graphics,par) importFrom(methods,"slot<-") diff --git a/R/MatchedSpectra.R b/R/MatchedSpectra.R index fa497e1..cf9a366 100644 --- a/R/MatchedSpectra.R +++ b/R/MatchedSpectra.R @@ -413,6 +413,8 @@ setMethod( #' #' @importFrom grDevices n2mfrow #' +#' @importFrom Spectra scalePeaks +#' #' @export setMethod( "plotSpectraMirror", "MatchedSpectra",