diff --git a/NEWS b/NEWS index 0145992b8..851fdaf02 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ CHANGES IN VERSION 1.17.6 o Change the meaning of calculateFragments' "modifications" argument. Now the modification is added to the mass of the amino acid/peptide. Before it was replaced. <2015-06-21 Sun> + o calculateFragments gains the feature to handle N-/C-terminal modifications, + see #47. <2015-06-21 Sun> CHANGES IN VERSION 1.17.5 ------------------------- diff --git a/R/functions-fragments.R b/R/functions-fragments.R index 02a889c7c..f2902f2ac 100644 --- a/R/functions-fragments.R +++ b/R/functions-fragments.R @@ -113,7 +113,7 @@ if (neutralLoss) { df <- .neutralLoss(df) } - df + .terminalModifications(df, modifications=modifications) } #' adds neutral loss to data.frame generated by .calculateFragments @@ -159,3 +159,22 @@ df } +#' adds nterm/cterm modifications to data.frame generated by .calculateFragments +#' should be used after .neutralLoss +#' @param df data.frame generated by. calculateFragments +#' @return modified data.frame +#' @noRd +.terminalModifications <- function(df, modifications) { + affected <- c(Nterm="^[abc]_?$", Cterm="^[xyz]\\*?$") + + for (term in c("Nterm", "Cterm")) { + if (term %in% names(modifications)) { + isAffected <- grep(affected[term], df$type) + if (length(isAffected)) { + df$mz[isAffected] <- df$mz[isAffected] + modifications[term] + } + } + } + + df +} diff --git a/man/calculateFragments-methods.Rd b/man/calculateFragments-methods.Rd index 50a9228ec..62e3d7100 100644 --- a/man/calculateFragments-methods.Rd +++ b/man/calculateFragments-methods.Rd @@ -28,7 +28,9 @@ name must correspond to the one-letter-code of the modified amino acid and the \code{numeric} value must represent the mass that should be added to the original amino accid mass, default: - Carbamidomethyl \code{modifications=c(C=57.02146)}. } + Carbamidomethyl \code{modifications=c(C=57.02146)}. Use \code{Nterm} or + \code{Cterm} as names for modifications that should be added to the amino + respectively carboxyl-terminus.} \item{neutralLoss}{ \code{logical} if \code{TRUE} (default) neutral loss is also calculated. Currently water and ammonia loss (shown with an \code{_} respectively a \code{*} in the results). } @@ -83,6 +85,9 @@ msexp <- pickPeaks(msexp) ## calculate fragments for ACE with default modification calculateFragments("ACE", modifications=c(C=57.02146)) +## calculate fragments for ACE with an addition N-terminal modification +calculateFragments("ACE", modifications=c(C=57.02146, Nterm=229.1629)) + ## calculate fragments for ACE without any modifications calculateFragments("ACE", modifications=NULL) diff --git a/tests/testthat/test_fragments.R b/tests/testthat/test_fragments.R index bc20e200e..5a2716b66 100644 --- a/tests/testthat/test_fragments.R +++ b/tests/testthat/test_fragments.R @@ -63,6 +63,23 @@ test_that("calculateFragments", { calculateFragments("PQR", verbose=FALSE), check.attributes=FALSE, tolerance=1e-5) + ## neutral loss + nterm mod, rownames always differ + tpqr <- pqr[c(4:6, 13:15, 19:24),] + tpqr$mz[1:3] <- tpqr$mz[1:3]+229 + expect_equal(tpqr, + calculateFragments("PQR", modifications=c(C=57.02146, Nterm=229), + verbose=FALSE), + check.attributes=FALSE, tolerance=1e-5) + + ## neutral loss + nterm + cterm mod, rownames always differ + tpqr$mz[c(4:6, 11:12)] <- tpqr$mz[c(4:6, 11:12)]-100 + expect_equal(tpqr, + calculateFragments("PQR", modifications=c(C=57.02146, + Nterm=229, + Cterm=-100), + verbose=FALSE), + check.attributes=FALSE, tolerance=1e-5) + expect_equal(ace, calculateFragments("ACE", type=c("a", "b", "c", "x", "y", "z"), z=2, neutralLoss=FALSE, verbose=FALSE),