Normalization of 3 separate data files of clean, raw data
library(plyr)
library(ggplot2)
library(IlluminaHumanMethylation450k.db)
library(latticeExtra)
library(ggplot2)
load("probeDesign.Rdata")
load("All_3_sets.Rdata")
dataList <- list(ALL = ALL.dat, APL = APL.dat, CTRL = CTRL.dat)
data.raw.densities <- lapply(dataList, function(dat) {
ldply(dat, function(samp) {
na.ix <- which(is.na(samp))
t1dens <- density(samp[-na.ix][design[-na.ix] == 1])
t2dens <- density(samp[-na.ix][design[-na.ix] == 2])
cbind(t1x = t1dens$x, t1y = t1dens$y, t2x = t2dens$x, t2y = t2dens$y)
})
})
rm(ALL.dat, APL.dat, CTRL.dat, dataList)
For this plot, we skip the normalization process and skip right to loading normalized data. A list of 3 (one for each data set). Each element is a list for each of the samples. Each of these is in turn a list containing the normalization output and a vector containing the positions of the NA values, so they can be re-inserted after normalization. The normalization output is a list in itself, containing normalized values and types, as well as parameters from the normalization which consisted of fitting a mixture model. We also load in probe design (type I or II) specification for each probe.
load("normDat_rawList.Rdata")
data.t2norm.densities <- lapply(data.norm.noNAs, function(dat) {
ldply(dat, function(.list) with(density(.list$pnbeta$all[design[-.list$na.ix] ==
2]), cbind(x = x, y = y)))
})
data.t2norm.densities <- with(data.t2norm.densities, rbind(ALL, APL, CTRL))
data.raw.densities <- with(data.raw.densities, rbind(ALL, APL, CTRL))
# all(data.t2norm.densities$.id == data.raw.densities$.id)
data.norm.densities <- cbind(data.t2norm.densities, data.raw.densities[-1])
plotDat <- with(data.norm.densities, data.frame(Sample = .id, x = c(x, t1x,
t2x), y = c(y, t1y, t2y), Type = rep(c("T2-Norm", "T1", "T2"), each = nrow(data.norm.densities))))
colors <- brewer.pal(3, "Set1")
plot.settings <- list(superpose.line = list(col = colors))
xyplot(y ~ x | Sample, data = subset(plotDat, grepl("ALL", Sample)), groups = Type,
xlab = "Beta", main = "Density of beta-values", type = "l", par.settings = plot.settings,
auto.key = list(space = "top", columns = 3, lines = T, points = F))
xyplot(y ~ x | Sample, data = subset(plotDat, !grepl("ALL", Sample)), groups = Type,
xlab = "Beta", main = "Density of beta-values", type = "l", par.settings = plot.settings,
auto.key = list(space = "top", columns = 3, lines = T, points = F))