Skip to content

Commit

Permalink
add N/C-term modifications; closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibb committed Jun 21, 2015
1 parent 48655ee commit 62a3301
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------
Expand Down
21 changes: 20 additions & 1 deletion R/functions-fragments.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
if (neutralLoss) {
df <- .neutralLoss(df)
}
df
.terminalModifications(df, modifications=modifications)
}

#' adds neutral loss to data.frame generated by .calculateFragments
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion man/calculateFragments-methods.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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). }
Expand Down Expand Up @@ -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)

Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test_fragments.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 62a3301

Please sign in to comment.