|
a |
|
b/R/getStdiz.R |
|
|
1 |
#' @name getStdiz |
|
|
2 |
#' @title Get standardized omics data |
|
|
3 |
#' @description This function prepare standardized data for generating heatmap. Omics data, especially for expression, should be centered or scaled or z-scored (both centered and scaled). Generally, DNA methylation beta matrix and somatic mutation (0 and 1 binary matrix) should not be normalized. This function also provides an argument of `halfwidth` for continuous omics data; such argument is used to truncate the 'extremum' after normalization; specifically, normalized values that exceed the halfwidth boundaries will be replaced by the halfwidth, which is vary useful to map colors in heatmap. |
|
|
4 |
#' @param data A list of data.frame or matrix storing raw multiple omics data with rows for features and columns for samples. |
|
|
5 |
#' @param halfwidth A numeric vector to assign marginal cutoff for truncating values in data; 1 by default. |
|
|
6 |
#' @param centerFlag A logical vector to indicate if each subdata should be centered; TRUE by default. |
|
|
7 |
#' @param scaleFlag A logical vector to indicate if each subdata should be scaled; TRUE by default. |
|
|
8 |
#' @export |
|
|
9 |
#' @return A standardized data.frame containing multi-omics data. |
|
|
10 |
#' @examples # There is no example and please refer to vignette. |
|
|
11 |
getStdiz <- function(data = NULL, |
|
|
12 |
halfwidth = rep(1, length(data)), |
|
|
13 |
centerFlag = rep(TRUE, length(data)), |
|
|
14 |
scaleFlag = rep(TRUE, length(data))) { |
|
|
15 |
|
|
|
16 |
# check data |
|
|
17 |
if(is.null(names(data))){ |
|
|
18 |
names(data) <- sprintf("dat%s", 1:length(data)) |
|
|
19 |
} |
|
|
20 |
|
|
|
21 |
n_dat <- length(data) |
|
|
22 |
if(n_dat > 6){ |
|
|
23 |
stop("current version of MOVICS can support up to 6 datasets.") |
|
|
24 |
} |
|
|
25 |
if(n_dat < 2){ |
|
|
26 |
stop('current verision of MOVICS needs at least 2 omics data.') |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
outdata <- list() |
|
|
30 |
for (i in 1:n_dat) { |
|
|
31 |
tmp <- t(scale(t(data[[i]]), center = centerFlag[i], scale = scaleFlag[i])) |
|
|
32 |
if (!is.na(halfwidth[i])) { |
|
|
33 |
tmp[tmp > halfwidth[i]] = halfwidth[i] |
|
|
34 |
tmp[tmp < (-halfwidth[i])] = -halfwidth[i] |
|
|
35 |
} |
|
|
36 |
outdata[[names(data)[i]]] <- tmp |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
return(outdata) |
|
|
40 |
} |