Issue with mz
Arthfael opened this issue · comments
I tried to run the mz function today and got an error for any peptide not including "C":
> mz("AGHTTKILC")
[1] 500.7658
> mz("AGHTTKIL")
Error in table(unlist(strsplit(X, "")))[["C"]] : subscript out of bounds
Assuming I have the latest version (I did exit R and re-installed from CRAN), I would suggest the following change to the function's code:
function (seq, charge = 2, label = "none", aaShift = NULL, cysteins = 57.021464) {
if (!is.numeric(charge) | length(charge) != 1) {
stop("Charge must be given as an integer (typically between 1-4).")
}
mass <- mw(seq = seq, label = label, aaShift = aaShift, monoisotopic = TRUE)
mass <- mass + nchar(gsub("[^C]", "", seq)) * cysteins #This is my suggested edit
if (charge >= 0) {
mass <- mass + charge * 1.007276
mass <- mass/charge
}
return(mass)
}
I have no idea whether this is the most optimal/fastest code, or whether it makes incorrect assumptions as to the type of input sequences acceptable (I assumed upper case, one letter amino acid code as character). At least it doesn't fail because it assumes there should be at least one C, which the current version appears to do.
Thank you very much for letting us know! I will check it out and submit a new version to CRAN.