Skip to content

Commit

Permalink
add prototype for .neutralLoss; see #47:3
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibb committed Feb 18, 2015
1 parent cb899a2 commit cbb8b23
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions R/functions-fragments.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,46 @@
return(df)
}

#' adds neutral loss to data.frame generated by .calculateFragments
#' @param df data.frame generated by. calculateFragments
#' @return data.frame neutral loss rows added
#' @noRd
.neutralLoss <- function(df) {
## see "Low energy peptide fragmentation pathways" by Hugh-G. Patterton, Ph.D.
## http://cbio.ufs.ac.za/fgap/download/fragmentation_review.pdf
## see also discussion #47: https://github.com/lgatto/MSnbase/issues/47

## constants
mass <- get.atomic.mass()

add <- c("_"=-(mass["H"]+2*mass["O"]), # - H2O
"*"=-(mass["N"]+3*mass["H"])) # - NH3

## water loss
## C-term COOH (all x, y, z fragments)
isXYZ <- which(df$type %in% c("x", "y", "z"))

## N-term D/E, internal S/T
isDEST <- grep("^[DE].|.[ST].", df$seq)
isDEST <- setdiff(isDEST, isXYZ)

## ammonia loss
## N-term/internal K/N/Q, internal R
isKNQR <- grep("^.*[KNQ].|.R.", df$seq)

n <- c(length(isXYZ), length(isDEST), length(isKNQR))

if (sum(n)) {
idx <- c(isXYZ, isDEST, isKNQR)
ion <- rep(c("_", "_", "*"), n)
mz <- rep(add[c(1, 1, 2)], n)

loss <- df[idx, ]
loss[, c("ion", "type")] <- paste0(c(loss$ion, loss$type), ion)
loss$mz <- loss$mz + mz
df <- rbind(df, loss)
rownames(df) <- NULL
}
df
}

0 comments on commit cbb8b23

Please sign in to comment.