library(GenomicFeatures) path <- "/virdir/Scratch/RP3_data/450k" load(file.path(path, "methData_BIOS_02042015.RData")) ##functional normalized methylaid qceed methData ##SummarizedExperiment
data <- assays(methData)$beta dim(data) ##[1] 485512 4030 b data[1:5, 1:5]
keep <- apply(data, 1, function(x) all(!is.na(x))) table(keep)
data <- data[keep, ] dim(data) ##[1] 125629 4030
cellPercentages <- as.data.frame(colData(methData)[, c("Neut_Perc", "Lymph_Perc", "Mono_Perc", "Eos_Perc", "Baso_Perc")]) cellPercentages <- apply(cellPercentages, 2, as.numeric) cellPercentages
covariates <- as.data.frame(colData(methData)) covariates <- covariates[, c("DNA_BloodSampling_Age", "Sex", "Sentrix_Position")] colnames(covariates) <- c("Age", "Gender", "Sentrix_Position") covariates[,3] <- as.integer(as.factor(covariates[,3])) covariates <- apply(covariates, 2, as.numeric) covariates
rownames(covariates) <- rownames(cellPercentages) <- colnames(data) <- colData(methData)$uuid head(covariates) head(cellPercentages) data[1:6, 1:6]
nas <- apply(cellPercentages, 1, function(x) any(is.na(x))) table(nas)
complete <- which(!nas) cellPercentages[complete,]
trainId <- sample(complete, 2*length(complete)/3) testId <- complete[!(complete %in% trainId)]
dataTrain <- data[,trainId] covarTrain <- covariates[trainId,] cellPerTrain <- cellPercentages[trainId,]
gc() ##try to release
plotting <- function(measured, predicted, xlab="predicted", ylab="measured") { op <- par(mfcol=c(3,2), mar=c(4, 4, 3, 1)) for(k in 1:ncol(measured)) { type <- colnames(measured)[k] cme <- cor(predicted[,k], measured[,k]) plot(predicted[,k], measured[,k], main=paste(type, " (correlation: ", round(cme, 4), ")", sep=""), bty="n", pty="s") abline(lm(measured[,k]~0+predicted[,k]), col=2, lty=1, lwd=2) abline(0, 1, col="grey", lty=1, lwd=2) grid() } par(op) }
dataTest <- data[,testId] covarTest <- covariates[testId,] cellPerTest <- cellPercentages[testId,]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.