diff --git a/DESCRIPTION b/DESCRIPTION index 5436cae..231e8dc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: PSMatch Title: Handling and Managing Peptide Spectrum Matches -Version: 1.15.3 +Version: 1.17.1 Authors@R: c(person(given = "Laurent", family = "Gatto", email = "laurent.gatto@uclouvain.be", @@ -61,8 +61,9 @@ Suggests: License: Artistic-2.0 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.3 VignetteBuilder: knitr BugReports: https://github.com/RforMassSpectrometry/PSM/issues URL: https://github.com/RforMassSpectrometry/PSM biocViews: Infrastructure, Proteomics, MassSpectrometry +Config/roxygen2/version: 8.0.0 +RoxygenNote: 7.3.3 diff --git a/NAMESPACE b/NAMESPACE index 75bd568..f8ed5b6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ importFrom(ProtGenerics,adjacencyMatrix) importFrom(ProtGenerics,calculateFragments) importFrom(QFeatures,reduceDataFrame) importFrom(Spectra,peaksData) +importFrom(Spectra,precursorCharge) importFrom(Spectra,spectraData) importFrom(Spectra,spectraVariables) importFrom(grDevices,n2mfrow) diff --git a/NEWS.md b/NEWS.md index 5d22d9e..d685b32 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,16 @@ # PSMatch 1.15 +## PSMatch 1.17.1 + +- Added parameter `z` and `allCharges` in `plotSpectraPTM()` and + `labelFragments()` and set it to `1:precursorCharge(x)` by default when it used + to only display charge 1 before. See this + [PR](https://github.com/rformassspectrometry/PSMatch/pull/44). + +## PSMatch 1.17.0 + +- New Bioconductor devel. + ## PSMatch 1.15.3 - Adjusted documentation on `addCarbamidomethyl = TRUE` in @@ -166,4 +177,4 @@ ## Changes in 0.99.0 -- Prepare package for Bioconductor submission. +- Prepare package for Bioconductor submission. \ No newline at end of file diff --git a/R/fragments-label.R b/R/fragments-label.R index 427e397..f415661 100644 --- a/R/fragments-label.R +++ b/R/fragments-label.R @@ -19,7 +19,17 @@ ##' whether labels should be fragment ions, , or their m/z values. If the ##' latter, then the m/z values are named with the ion labels. ##' -##' @param ... additional parameters (except `verbose`) passed to +##' @param z `numeric()` vector of length equal to `length(x)` or `NULL`. Each +##' element specifies the charge state (or maximum charge state if +##' `allCharges = TRUE`) for the corresponding spectrum. If `NULL` +##' (default), uses `precursorCharge(x)` for each spectrum. +##' +##' @param allCharges `logical(1L)`. If `TRUE` (default), generates fragments +##' for all charge states from 1 up to the value specified (either from +##' `z` or `precursorCharge(x)`). If `FALSE`, generates fragments only +##' for the specified charge state. +##' +##' @param ... additional parameters (except `verbose` and `z`) passed to ##' [calculateFragments()] to calculate fragment m/z values to be ##' added to the spectra in `x`. ##' @@ -86,20 +96,60 @@ ##' ##' ## By default used in `plotSpectraPTM()`. ##' plotSpectraPTM(sp) +##' +##' ## Use custom charge states +##' sp2 <- c(sp, sp) +##' sp2$precursorCharge <- c(2L, 3L) +##' labelFragments(sp2, z = c(2, 3)) +##' +##' ## Use only the specified charge (no range) +##' labelFragments(sp2, z = c(1, 2), allCharges = FALSE) labelFragments <- function(x, tolerance = 0, ppm = 20, - what = c("ion", "mz"), ...) { + what = c("ion", "mz"), z = NULL, + allCharges = TRUE, ...) { stopifnot(requireNamespace("Spectra")) stopifnot(inherits(x, "Spectra")) what <- match.arg(what) + + ## Validate z parameter + if (!is.null(z)) { + if (!is.numeric(z) || length(z) != length(x)) { + stop("'z' must be NULL or a numeric vector of length ", + "equal to length(x)") + } + } + + ## Create z_list for each spectrum + z_list <- lapply(seq_along(x), function(i) { + if (!is.null(z)) { + z_val <- z[i] + } else { + pc <- x$precursorCharge[i] + z_val <- if (!is.na(pc) & pc != 0) pc else 1L + } + if (allCharges) { + seq_len(z_val) + } else { + z_val + } + }) + super_labels <- vector("list", length = length(x)) k <- integer() v <- peaksData(x) + dots <- list(...) for (j in seq_along(x)) { stopifnot("sequence" %in% Spectra::spectraVariables(x[j])) y <- Spectra::spectraData(x[j])[["sequence"]] x_data <- v[[j]] - y_data <- calculateFragments(y, verbose = FALSE, ...) + + ## Prepare arguments for calculateFragments + calc_args <- dots + calc_args$z <- z_list[[j]] + calc_args$sequence <- y + calc_args$verbose <- FALSE + y_data <- do.call(calculateFragments, calc_args) y_data <- split(y_data, y_data$peptide) diff --git a/R/plotSpectra-PTM.R b/R/plotSpectra-PTM.R index 225b655..16f3780 100644 --- a/R/plotSpectra-PTM.R +++ b/R/plotSpectra-PTM.R @@ -82,6 +82,17 @@ ##' details on this, see the appropriate vignette by running ##' `vignette("Fragments", package = "PSMatch") ##' +##' @param z `numeric()` vector of length equal to `length(x)` or `NULL`. Each +##' element specifies the charge state (or maximum charge state if +##' `allCharges = TRUE`) for the corresponding spectrum. If `NULL` +##' (default), uses `precursorCharge(x)` for each spectrum. Cannot be +##' used simultaneously with `variableModifications`. +##' +##' @param allCharges `logical(1L)`. If `TRUE` (default), generates fragments +##' for all charge states from 1 up to the value specified (either from +##' `z` or `precursorCharge(x)`). If `FALSE`, generates fragments only +##' for the specified charge state. +##' ##' @param ... additional parameters to be passed to the `labelFragments()` ##' and `calculateFragments()` functions. ##' @@ -89,7 +100,7 @@ ##' ##' @importFrom grDevices n2mfrow ##' -##' @importFrom Spectra spectraVariables +##' @importFrom Spectra spectraVariables precursorCharge ##' ##' @author Johannes Rainer, Sebastian Gibb, Guillaume Deflandre, Laurent Gatto ##' @@ -158,6 +169,17 @@ ##' ##' ## Color the peaks with different colors ##' plotSpectraPTM(sp, col = c(y = "red", b = "blue", acxy = "chartreuse3", other = "black")) +##' +##' ## Use only singly-charged fragments (allCharges = FALSE) +##' plotSpectraPTM(sp, allCharges = FALSE) +##' +##' ## Specify custom charge states for multiple spectra +##' sp2 <- c(sp, sp) +##' sp2$precursorCharge <- c(2L, 3L) +##' plotSpectraPTM(sp2, z = c(2, 3)) +##' +##' ## Use only the specified charge (no range) +##' plotSpectraPTM(sp2, z = c(1, 2), allCharges = FALSE) plotSpectraPTM <- function(x, deltaMz = TRUE, ppm = 20, xlab = "m/z", ylab = "intensity [%]", xlim = numeric(), ylim = numeric(), @@ -172,18 +194,35 @@ plotSpectraPTM <- function(x, deltaMz = TRUE, ppm = 20, fixedModifications = NULL, variableModifications = NULL, addCarbamidomethyl = TRUE, + z = NULL, + allCharges = TRUE, ...) { if (!("sequence" %in% Spectra::spectraVariables(x))) { stop("Missing 'sequence' in Spectra::spectraVariables(x)") } + ## Validate that z and variableModifications are not both provided + if (!is.null(z) && !is.null(variableModifications)) { + stop("Cannot use both 'z' and 'variableModifications' ", + "parameters simultaneously. Please set one to NULL.") + } + + ## Validate z parameter + if (!is.null(z)) { + if (!is.numeric(z) || length(z) != length(x)) { + stop("'z' must be NULL or a numeric vector of length ", + "equal to length(x)") + } + } + ## Apply fixed modifications to all sequences if provided if (!is.null(fixedModifications)) { x$sequence <- PTMods::addFixedModifications(x$sequence, fixedModifications = fixedModifications) } - ## Apply variable modifications, expanding spectra for each combination. + ## Apply variable modifications, expanding spectra for each + ## combination. if (!is.null(variableModifications)) { seqsIn <- x$sequence parts <- lapply(seq_along(x), function(i) { @@ -206,11 +245,13 @@ plotSpectraPTM <- function(x, deltaMz = TRUE, ppm = 20, if (length(main) != nsp) main <- rep(main[1], nsp) labels <- labelFragments(x, ppm = ppm, what = "ion", - addCarbamidomethyl = addCarbamidomethyl, ...) + addCarbamidomethyl = addCarbamidomethyl, z = z, + allCharges = allCharges, ...) if (deltaMz) { ## Generate deltaMzData labels for .plot_single_spectrum_PTM deltaMzData <- labelFragments(x, ppm = ppm, what = "mz", - addCarbamidomethyl = addCarbamidomethyl, ...) + addCarbamidomethyl = addCarbamidomethyl, z = z, + allCharges = allCharges, ...) layout_matrix <- .make_layout_matrix(length(labels)) layout(layout_matrix, heights = rep(c(5, 1), length.out = nrow(layout_matrix))) @@ -353,7 +394,7 @@ plotSpectraPTM <- function(x, deltaMz = TRUE, ppm = 20, .(basename(spectraData(x)[["dataOrigin"]])) * "/scan: " * .(spectraData(x)[["scanIndex"]]) * "/rt: " * .(round(spectraData(x)[["rtime"]], 2L)) * - "/charge: " * .(spectraData(x)[["charge"]]) * + "/charge: " * .(spectraData(x)[["precursorCharge"]]) * "/peptide: " * bold(.(peptide_sequence)) ) diff --git a/README.md b/README.md index 5d8871a..4eccf5b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Handling peptide-spectrum matches + + `PSMatch` is a simple package to load, process and analyse PSMs (Peptide-Spectrum Matches). The following references are a good way to get started with the package: diff --git a/man/ConnectedComponents.Rd b/man/ConnectedComponents.Rd index 0c63941..127a69a 100644 --- a/man/ConnectedComponents.Rd +++ b/man/ConnectedComponents.Rd @@ -143,7 +143,7 @@ prioritisation is based on a set of metrics computed from the component's adjacency matrix, including its dimensions, row and col sums maxima and minima, its sparsity and the number of communities and their modularity that quantifies how well the -communities separate (see \code{\link[igraph:modularity.igraph]{igraph::modularity()}}. Note that +communities separate (see \code{\link[igraph:modularity]{igraph::modularity()}}. Note that trivial components, i.e. those composed of a single peptide and protein are excluded from the prioritised results. This \code{data.frame} is ideally suited for a principal component diff --git a/man/PSM.Rd b/man/PSM.Rd index 4b01c7b..eaee23c 100644 --- a/man/PSM.Rd +++ b/man/PSM.Rd @@ -132,7 +132,7 @@ describes some apparent differences in their outputs. The constructor input is a character of one more multiple file names. \item \code{PSM} objects can also be created from a \code{data.frame} object (or any -variable that can be coerced into a \link[S4Vectors:DataFrame-class]{S4Vectors::DataFrame}. +variable that can be coerced into a \link[S4Vectors:DataFrame]{S4Vectors::DataFrame}. \item Finally, \code{\link[=PSM]{PSM()}} can also take a \code{PSM} object as input, which leaves the PSM data as is and is used to set/update the PSM variables. diff --git a/man/PSMatch.Rd b/man/PSMatch.Rd index 284df42..7f73f21 100644 --- a/man/PSMatch.Rd +++ b/man/PSMatch.Rd @@ -89,6 +89,7 @@ Useful links: Authors: \itemize{ + \item Laurent Gatto \email{laurent.gatto@uclouvain.be} (\href{https://orcid.org/0000-0002-1520-2268}{ORCID}) \item Johannes Rainer \email{Johannes.Rainer@eurac.edu} (\href{https://orcid.org/0000-0002-6977-7147}{ORCID}) \item Sebastian Gibb \email{mail@sebastiangibb.de} (\href{https://orcid.org/0000-0001-7406-4443}{ORCID}) } diff --git a/man/labelFragments.Rd b/man/labelFragments.Rd index dd24e88..212c53c 100644 --- a/man/labelFragments.Rd +++ b/man/labelFragments.Rd @@ -4,7 +4,15 @@ \alias{labelFragments} \title{labels MS2 Fragments} \usage{ -labelFragments(x, tolerance = 0, ppm = 20, what = c("ion", "mz"), ...) +labelFragments( + x, + tolerance = 0, + ppm = 20, + what = c("ion", "mz"), + z = NULL, + allCharges = TRUE, + ... +) } \arguments{ \item{x}{An instance of class \code{Spectra} of length 1, containing a @@ -12,16 +20,26 @@ spectra variable \code{"sequence"} with a \code{character(1)} representing a valid peptide sequence.} \item{tolerance}{absolute acceptable difference of m/z values for peaks to -be considered matching (see \code{\link[MsCoreUtils:matching]{MsCoreUtils::closest()}} for more details).} +be considered matching (see \code{\link[MsCoreUtils:closest]{MsCoreUtils::closest()}} for more details).} \item{ppm}{m/z relative acceptable difference (in ppm) for peaks to be -considered matching (see \code{\link[MsCoreUtils:matching]{MsCoreUtils::closest()}} for more details).} +considered matching (see \code{\link[MsCoreUtils:closest]{MsCoreUtils::closest()}} for more details).} \item{what}{\code{character(1)}, one of \code{"ion"} (default) or \code{"mz"}, defining whether labels should be fragment ions, , or their m/z values. If the latter, then the m/z values are named with the ion labels.} -\item{...}{additional parameters (except \code{verbose}) passed to +\item{z}{\code{numeric()} vector of length equal to \code{length(x)} or \code{NULL}. Each +element specifies the charge state (or maximum charge state if +\code{allCharges = TRUE}) for the corresponding spectrum. If \code{NULL} +(default), uses \code{precursorCharge(x)} for each spectrum.} + +\item{allCharges}{\code{logical(1L)}. If \code{TRUE} (default), generates fragments +for all charge states from 1 up to the value specified (either from +\code{z} or \code{precursorCharge(x)}). If \code{FALSE}, generates fragments only +for the specified charge state.} + +\item{...}{additional parameters (except \code{verbose} and \code{z}) passed to \code{\link[=calculateFragments]{calculateFragments()}} to calculate fragment m/z values to be added to the spectra in \code{x}.} } @@ -86,6 +104,14 @@ plotSpectra(sp, labels = labelFragments, labelPos = 3) ## By default used in `plotSpectraPTM()`. plotSpectraPTM(sp) + +## Use custom charge states +sp2 <- c(sp, sp) +sp2$precursorCharge <- c(2L, 3L) +labelFragments(sp2, z = c(2, 3)) + +## Use only the specified charge (no range) +labelFragments(sp2, z = c(1, 2), allCharges = FALSE) } \author{ Johannes Rainer, Guillaume Deflandre, Sebastian Gibb, Laurent Gatto diff --git a/man/plotSpectraPTM.Rd b/man/plotSpectraPTM.Rd index a257524..a3c26e1 100644 --- a/man/plotSpectraPTM.Rd +++ b/man/plotSpectraPTM.Rd @@ -25,6 +25,8 @@ plotSpectraPTM( fixedModifications = NULL, variableModifications = NULL, addCarbamidomethyl = TRUE, + z = NULL, + allCharges = TRUE, ... ) } @@ -98,6 +100,17 @@ set \code{addCarbamidomethylation = FALSE}. For more details on this, see the appropriate vignette by running `vignette("Fragments", package = "PSMatch")} +\item{z}{\code{numeric()} vector of length equal to \code{length(x)} or \code{NULL}. Each +element specifies the charge state (or maximum charge state if +\code{allCharges = TRUE}) for the corresponding spectrum. If \code{NULL} +(default), uses \code{precursorCharge(x)} for each spectrum. Cannot be +used simultaneously with \code{variableModifications}.} + +\item{allCharges}{\code{logical(1L)}. If \code{TRUE} (default), generates fragments +for all charge states from 1 up to the value specified (either from +\code{z} or \code{precursorCharge(x)}). If \code{FALSE}, generates fragments only +for the specified charge state.} + \item{...}{additional parameters to be passed to the \code{labelFragments()} and \code{calculateFragments()} functions.} } @@ -173,9 +186,20 @@ plotSpectraPTM(c(sp, sp)) ## Color the peaks with different colors plotSpectraPTM(sp, col = c(y = "red", b = "blue", acxy = "chartreuse3", other = "black")) + +## Use only singly-charged fragments (allCharges = FALSE) +plotSpectraPTM(sp, allCharges = FALSE) + +## Specify custom charge states for multiple spectra +sp2 <- c(sp, sp) +sp2$precursorCharge <- c(2L, 3L) +plotSpectraPTM(sp2, z = c(2, 3)) + +## Use only the specified charge (no range) +plotSpectraPTM(sp2, z = c(1, 2), allCharges = FALSE) } \seealso{ -\code{\link[Spectra:spectra-plotting]{Spectra::plotSpectra()}} +\code{\link[Spectra:plotSpectra]{Spectra::plotSpectra()}} } \author{ Johannes Rainer, Sebastian Gibb, Guillaume Deflandre, Laurent Gatto diff --git a/stickers/PSMatch.png b/stickers/PSMatch.png new file mode 100644 index 0000000..346e771 Binary files /dev/null and b/stickers/PSMatch.png differ diff --git a/tests/testthat/_snaps/plotSpectraPTM/deltamz-false.svg b/tests/testthat/_snaps/plotSpectraPTM/deltamz-false.svg index f40f4cc..43f489d 100644 --- a/tests/testthat/_snaps/plotSpectraPTM/deltamz-false.svg +++ b/tests/testthat/_snaps/plotSpectraPTM/deltamz-false.svg @@ -150,16 +150,16 @@ 100 intensity [%] m/z -mzspec/ -testfile.mzML -/scan: -1 -/rt: -2345 -/charge: -2 -/peptide: -HIGFEGDSIGR +mzspec/ +testfile.mzML +/scan: +1 +/rt: +2345 +/charge: +NA +/peptide: +HIGFEGDSIGR 1.96e+06 diff --git a/tests/testthat/_snaps/plotSpectraPTM/deltamz-true.svg b/tests/testthat/_snaps/plotSpectraPTM/deltamz-true.svg index c31b309..7821ef0 100644 --- a/tests/testthat/_snaps/plotSpectraPTM/deltamz-true.svg +++ b/tests/testthat/_snaps/plotSpectraPTM/deltamz-true.svg @@ -159,16 +159,16 @@ m/z -mzspec/ -testfile.mzML -/scan: -1 -/rt: -2345 -/charge: -2 -/peptide: -HIGFEGDSIGR +mzspec/ +testfile.mzML +/scan: +1 +/rt: +2345 +/charge: +NA +/peptide: +HIGFEGDSIGR 1.96e+06 diff --git a/tests/testthat/_snaps/plotSpectraPTM/diff-col.svg b/tests/testthat/_snaps/plotSpectraPTM/diff-col.svg index eec9230..150dd27 100644 --- a/tests/testthat/_snaps/plotSpectraPTM/diff-col.svg +++ b/tests/testthat/_snaps/plotSpectraPTM/diff-col.svg @@ -150,16 +150,16 @@ 100 intensity [%] m/z -mzspec/ -testfile.mzML -/scan: -1 -/rt: -2345 -/charge: -2 -/peptide: -HIGFEGDSIGR +mzspec/ +testfile.mzML +/scan: +1 +/rt: +2345 +/charge: +NA +/peptide: +HIGFEGDSIGR 1.96e+06 diff --git a/tests/testthat/test_labelFragments.R b/tests/testthat/test_labelFragments.R index 32a75f2..7cde05c 100644 --- a/tests/testthat/test_labelFragments.R +++ b/tests/testthat/test_labelFragments.R @@ -72,4 +72,45 @@ test_that("labelFragments() works with what = 'mz'", { expect_identical(frags[o,"mz"], ans_mz[[1]]) ans_ions <- labelFragments(sp, what = "ion") expect_identical(frags[o,"ion"], ans_ions[[1]]) +}) + +test_that("labelFragments() works with custom z values", { + seq <- c("PQR", "ACE") + ## Create fragments with different charge states + frags_pqr <- calculateFragments(seq[1], z = 1:2, + addCarbamidomethyl = FALSE) + frags_ace <- calculateFragments(seq[2], z = 1, + addCarbamidomethyl = FALSE) + ## Order fragments by mz + o_pqr <- order(frags_pqr$mz) + o_ace <- order(frags_ace$mz) + ## Create spectra + sp <- DataFrame(msLevel = c(2L, 2L), rtime = c(2345, 2346), + sequence = seq, precursorCharge = c(2L, 1L)) + sp$mz <- list(frags_pqr$mz[o_pqr][1:10], + frags_ace$mz[o_ace][1:5]) + sp$intensity <- list(rep(1, 10), rep(1, 5)) + sp <- Spectra(sp) + ## Test with custom z values (numeric vector) + ans <- labelFragments(sp, z = c(2, 1), allCharges = TRUE, + addCarbamidomethyl = FALSE) + expect_equal(length(ans), 2) + expect_equal(names(ans), seq) +}) + +test_that("labelFragments() works with allCharges = FALSE", { + seq <- "PQR" + ## Create fragments with charge 1 only + frags <- calculateFragments(seq, z = 1, + addCarbamidomethyl = FALSE) + o <- order(frags$mz) + sp <- DataFrame(msLevel = 2L, rtime = 2345, sequence = seq, + precursorCharge = 2L) + sp$mz <- list(frags$mz[o]) + sp$intensity <- list(rep(1, length(o))) + sp <- Spectra(sp) + ## Test with allCharges = FALSE (only charge 1) + ans <- labelFragments(sp, z = c(1), allCharges = FALSE, + addCarbamidomethyl = FALSE) + expect_equal(length(ans), 1) }) \ No newline at end of file diff --git a/tests/testthat/test_plotSpectraPTM.R b/tests/testthat/test_plotSpectraPTM.R index 294cb79..ceac2b7 100644 --- a/tests/testthat/test_plotSpectraPTM.R +++ b/tests/testthat/test_plotSpectraPTM.R @@ -2,6 +2,8 @@ #' # that could be called by `vdiffr::expect_doppelganger()` #' Run devtools::test_active_file(file = "tests/testthat/test_plotSpectraPTM.R") +library("Spectra") + sp <- DataFrame( msLevel = 2L, rtime = 2345, @@ -10,12 +12,16 @@ sp <- DataFrame( scanIndex = 1L, charge = 2L ) -sp$mz <- list(c(223.1583, 251.15432, 308.168017, 455.24801, 604.30949, - 641.30842, 667.2244, 778.30164, 813.34935, 923.350391, - 995.45281, 1017.43394, 1065.46197, 1112.5069, 1130.5874)) -sp$intensity <- list(c(83000, 65000, 190000, 379000, 281000, 112000, 39000, - 139000, 1015000, 63000, 58000, 1960000, 240000, - 1338000, 40700)) +sp$mz <- list(c( + 223.1583, 251.15432, 308.168017, 455.24801, 604.30949, + 641.30842, 667.2244, 778.30164, 813.34935, 923.350391, + 995.45281, 1017.43394, 1065.46197, 1112.5069, 1130.5874 +)) +sp$intensity <- list(c( + 83000, 65000, 190000, 379000, 281000, 112000, 39000, + 139000, 1015000, 63000, 58000, 1960000, 240000, + 1338000, 40700 +)) spectra <- Spectra(sp) test_that("plotSpectraPTM works with deltaMz = TRUE", { @@ -25,7 +31,8 @@ test_that("plotSpectraPTM works with deltaMz = TRUE", { plotSpectraPTM( spectra, type = c("a", "b", "c", "x", "y", "z"), - deltaMz = TRUE + deltaMz = TRUE, + z = 1 ) } ) @@ -38,7 +45,8 @@ test_that("plotSpectraPTM works with deltaMz = FALSE", { plotSpectraPTM( spectra, type = c("a", "b", "c", "x", "y", "z"), - deltaMz = FALSE + deltaMz = FALSE, + z = 1 ) } ) @@ -67,7 +75,8 @@ test_that("plotSpectraPTM works with different col", { spectra, col = c(y = "red", b = "blue", acxy = "orange", other = "violet"), type = c("a", "b", "c", "x", "y", "z"), - deltaMz = FALSE + deltaMz = FALSE, + z = 1 ) } ) @@ -80,8 +89,9 @@ test_that("plotSpectraPTM works with USI = FALSE", { plotSpectraPTM( spectra, type = c("a", "b", "c", "x", "y", "z"), - USI = FALSE + USI = FALSE, + z = 1 ) } ) -}) \ No newline at end of file +}) diff --git a/vignettes/Fragments.Rmd b/vignettes/Fragments.Rmd index 8993090..5ca671f 100644 --- a/vignettes/Fragments.Rmd +++ b/vignettes/Fragments.Rmd @@ -161,6 +161,28 @@ plotSpectraPTM(sp1158[2], As glycine has the same mass as carbamidomethylation, the b7 and b8 ions are overlapping in both spectra. +## Customising charge states + +By default, `plotSpectraPTM()` generates fragments for all charge states from +1 up to the precursor charge. You can customise this behaviour using the `z` +and `allCharges` parameters. + +The `z` parameter accepts a numeric vector with one value per spectrum, +specifying the charge state (or maximum charge state) to use. The `allCharges` +parameter controls whether to generate fragments for all charges from 1 up to +the specified value (`TRUE`, the default) or only for the exact charge +specified (`FALSE`). + +```{r, eval = FALSE} +## Use fragments with a custom charge state +plotSpectraPTM(sp1158[2], z = 2, allCharges = FALSE) + +## Use all charges from 1 to the precursor charge state or a custom charge +plotSpectraPTM(sp1158[2], z = 2, allCharges = TRUE) +``` + +Note that `z` cannot be used simultaneously with `variableModifications`. + The spectra displayed in this vignette might be overlapping due to the restricted windows. For a better visualisation, we suggest running the code locally.