# -----------------------------------------------------------------------
# Last Updated: January 28, 2021
# Author: Kristen Yeh, Sophie Castel
# Title: subMALDI: Normalization Method - RMS
# -----------------------------------------------------------------------
# -------------------------
# METHOD: ROOT MEAN SQUARE
# -------------------------
.RMS <- function(y, n){
right <- 1 / (n - 1)
left <- sum(y^2)
prod <- prod(left, right)
sqrt(prod)
}
.norm_RMS <- function(y, RMS){
return(y/RMS) # single value
}
norm_RMS <- function(dat, mass_dat, spectra_cols){
# ---------------------
# LOGICAL CHECKS
# ---------------------
full_mz <- Intensity <- Spectrum <- NULL
stopifnot(
is.character(mass_dat),
is.character(spectra_cols),
mass_dat %in% colnames(dat),
all(spectra_cols %in% colnames(dat))
)
mz <- dat[[mass_dat]]
spectra <- lapply(spectra_cols, function(x){dat[x]})
i <- do.call(what = data.frame, args = c(spectra))
n <- nrow(dat)
if(length(spectra_cols) == 1){
rms <- .RMS(y = i, n = n)
} else{
rms <- apply(i, 2, FUN = function(x) { .RMS(y = x, n = n)})
}
i_rms <- t(t(i)*rms^-1) # i / rms matrix multiplication
dat <- data.frame(mz, i_rms)
colnames(dat) <- c("full_mz", spectra_cols)
return(dat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.