forked from vladpetyuk/vp.misc
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnorm_by_global.R
39 lines (36 loc) · 1.22 KB
/
norm_by_global.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' Basic Normalization Routines
#'
#' Normalizes data based on assumption that on average peptide deviation
#' is zero. The approach is typically used for global shotgun proteomics
#' data. Converts one MSnSet to another MSnSet.
#'
#' @param m ExpresionSet or MSnSet object
#' @param method character. "medpolish" - uses median polish algorithm.
#' "once" means just correct for median differences in the samples.
#' Note, doing it just "once" may de-center the features (rows).
#'
#' @importFrom stats complete.cases median medpolish
#' @importFrom Biobase exprs<-
#'
#' @export normalizeByGlob
#'
#' @examples
#' data(srm_msnset)
#' image_msnset(msnset)
#' msnset2 <- normalizeByGlob(msnset)
#' image_msnset(msnset2)
normalizeByGlob <- function(m, method=c("medpolish","once")){
#
method <- match.arg(method)
#
if(method == "once"){
mc <- m[complete.cases(exprs(m)),]
sample.bias <- apply(exprs(mc), 2, median, na.rm=T)
exprs(m) <- sweep(exprs(m), 2, sample.bias, '-')
}else if(method == "medpolish"){
out <- medpolish(exprs(m), eps = .Machine$double.eps,
maxiter = 100, na.rm = T, trace.iter=F)
exprs(m) <- out$residuals
}
return(m)
}