Getting publicly available data

We will use the dataset from Field et al. (2015), which consists of eight DNA samples from the same DNA source treated with oxBS-BS and hybridized to the Infinium 450K array.

The steps shown in this section follows the vignette from minfi package.

We start with the steps to get the raw data from the GEO repository. The dataset from Field et al. (2015) is available at GEO accession GSE63179.

The sample was divided into four BS and four oxBS replicates.

Platform used: GPL16304 Illumina HumanMethylation450 BeadChip [UBC enhanced annotation v1.0]

Samples:

This example has the following dependencies:

library(minfi)
library(GEOquery)

Use the following commands to install these packages in R:

source("http://www.bioconductor.org/biocLite.R")
biocLite(c("minfi", "GEOquery"))
if(! file.exists("GSE63179/GSE63179_RAW.tar"))
{
getGEOSuppFiles("GSE63179")
untar("GSE63179/GSE63179_RAW.tar", exdir = "GSE63179/idat")
head(list.files("GSE63179/idat", pattern = "idat"))
}
getGEOSuppFiles("GSE63179")
untar("GSE63179/GSE63179_RAW.tar", exdir = "GSE63179/idat")
head(list.files("GSE63179/idat", pattern = "idat"))

Decompress the compressed IDAT files:

idatFiles <- list.files("GSE63179/idat", pattern = "idat.gz$", full = TRUE)
sapply(idatFiles, gunzip, overwrite = TRUE)

Now we read the IDAT files in the directory:

rgSet <- read.metharray.exp("GSE63179/idat")
rgSet
pData(rgSet)
sampleNames(rgSet)

The file names consists of a GEO identifier (the GSM part) followed by a standard IDAT naming convention with a 10 digit number which is an array identifier followed by an identifier of the form R01C01. This is because each array actually allows for the hybridization of 12 samples in a 6x2 arrangement. The 9373551079_R01C01 means row 1 and column 1 on chip 9373551079.

We need to identify the samples from different methods: BS-conversion, oxBS-conversion.

if (!file.exists("pD.rds"))
{
geoMat <- getGEO("GSE63179")
pD.all <- pData(geoMat[[1]])
pD <- pD.all[, c("title", "geo_accession", "characteristics_ch1.1", "characteristics_ch1.2","characteristics_ch1.3")]
save(pD,file="pD.rds")
}
geoMat <- getGEO("GSE63179")
pD.all <- pData(geoMat[[1]])
pD <- pD.all[, c("title", "geo_accession", "characteristics_ch1.1", "characteristics_ch1.2","characteristics_ch1.3")]
pD
load("pD.rds")
pD
names(pD)[c(3,4,5)] <- c("gender", "age","method")
pD$gender <- sub("^gender: ", "", pD$gender)
pD$age <- sub("^age: ", "", pD$age)
pD$method <- sub("^bisulfite_proc: ","",pD$method)

We now need to merge this pheno data into the methylation data. The following are commands to make sure we have the same row identifier in both datasets before merging.

sampleNames(rgSet) <- sapply(sampleNames(rgSet),function(x) strsplit(x,"_")[[1]][1])
rownames(pD) <- pD$geo_accession
pD <- pD[sampleNames(rgSet),]
pData(rgSet) <- as(pD,"DataFrame")
rgSet

Preprocessing

We refer the reader to the minfi package tutorials for more preprocessing options.

We need to install the required package bellow:

source("https://bioconductor.org/biocLite.R")
biocLite("IlluminaHumanMethylation450kmanifest")

First, we removed probes with detection p-value <0.01 in any of the 8 arrays. The function detectionP identifies failed positions defined as both the methylated and unmethylated channel reporting background signal levels.

detP <- detectionP(rgSet)
failed <- detP >0.01
## Keep probes which failed in at most maxFail arrays (0 = the probe passed in all arrays)
maxFail<- 0
keep_probes <- rowSums(failed) <= maxFail

We kept $r round(mean(keep_probes)*100,0)\%$ of the probes according to this criterion.

The rgSet object is a class called RGChannelSet which represents two color data with a green and a red channel. We will use, as input in the MLML funcion, a MethylSet, which contains the methylated and unmethylated signals. The most basic way to construct a MethylSet is to using the function preprocessRaw which uses the array design to match up the different probes and color channels to construct the methylated and unmethylated signals. Here we will use the preprocessNoob function, which does the preprocessing and returns a MethylSet.

Arrays were then normalized using the Noob/ssNoob preprocessing method for Infinium methylation microarrays.

From a MethylSet it is easy to compute Beta values, defined as:

Beta = Meth / (Meth + Unmeth + c)

The c constant is chosen to avoid dividing with small values. Illumina uses a default of c=100. The function getBeta from minfi package can be used to obtain the Beta values.

MSet.noob<- preprocessNoob(rgSet[keep_probes,])

Prepare de input data:

MethylatedBS <- getMeth(MSet.noob)[,c(1,3,5,6)]
UnMethylatedBS <- getUnmeth(MSet.noob)[,c(1,3,5,6)]

MethylatedOxBS <- getMeth(MSet.noob)[,c(7,8,2,4)]
UnMethylatedOxBS <- getUnmeth(MSet.noob)[,c(7,8,2,4)]
# not used in the package
# Only a small sample of CpGs and 2 replicates will be used in the example data.

set.seed(112017)

a <- sample(1:dim(MethylatedBS)[1],100,replace=FALSE)

MethylatedBS <- MethylatedBS[a,1:2]
UnMethylatedBS <- UnMethylatedBS[a,1:2]
MethylatedOxBS <- MethylatedOxBS[a,1:2]
UnMethylatedOxBS <- UnMethylatedOxBS[a,1:2]

colnames(MethylatedBS) <- c("sample1","sample2")
colnames(UnMethylatedBS) <- c("sample1","sample2")
colnames(MethylatedOxBS) <- c("sample1","sample2")
colnames(UnMethylatedOxBS) <- c("sample1","sample2")

save(MethylatedBS,file="MethylatedBS.rda")
save(UnMethylatedBS,file="UnMethylatedBS.rda")
save(MethylatedOxBS,file="MethylatedOxBS.rda")
save(UnMethylatedOxBS,file="UnMethylatedOxBS.rda")

This was included in the package as example:

set.seed(112017)

a <- sample(1:dim(MethylatedBS)[1],100,replace=FALSE)

MethylatedBS <- MethylatedBS[a,1:2]
UnMethylatedBS <- UnMethylatedBS[a,1:2]
MethylatedOxBS <- MethylatedOxBS[a,1:2]
UnMethylatedOxBS <- UnMethylatedOxBS[a,1:2]

colnames(MethylatedBS) <- c("sample1","sample2")
colnames(UnMethylatedBS) <- c("sample1","sample2")
colnames(MethylatedOxBS) <- c("sample1","sample2")
colnames(UnMethylatedOxBS) <- c("sample1","sample2")

N_BS <- round(MethylatedBS+UnMethylatedBS)

N_OxBS <- round(MethylatedOxBS+UnMethylatedOxBS)

N_TAB <- pmax(N_BS,N_OxBS)

p_m=.3
p_h=0.2
p_u=.5

true_parameters_sim <- data.frame(p_m=.3,p_h=.2,p_u=.5)
save(true_parameters_sim,file="true_parameters_sim.rda")

set.seed(2017)
MethylatedBS_sim <- apply(N_BS, c(1,2), function(x) rbinom(n=1, size=x, prob=(p_m+p_h)))

UnMethylatedBS_sim <- N_BS - MethylatedBS_sim

MethylatedOxBS_sim <- apply(N_OxBS, c(1,2), function(x) rbinom(n=1, size=x, prob=p_m))

UnMethylatedOxBS_sim <- N_OxBS - MethylatedOxBS_sim

MethylatedTAB_sim <- apply(N_TAB, c(1,2), function(x) rbinom(n=1, size=x, prob=p_h))

UnMethylatedTAB_sim <- N_TAB - MethylatedTAB_sim


save(MethylatedBS_sim,file="MethylatedBS_sim.rda")
save(UnMethylatedBS_sim,file="UnMethylatedBS_sim.rda")
save(MethylatedOxBS_sim,file="MethylatedOxBS_sim.rda")
save(UnMethylatedOxBS_sim,file="UnMethylatedOxBS_sim.rda")
save(MethylatedTAB_sim,file="MethylatedTAB_sim.rda")
save(UnMethylatedTAB_sim,file="UnMethylatedTAB_sim.rda")

Second Example Dataset

MethylatedBS <- getMeth(MSet.noob)[,c(1,3,5,6)]
UnMethylatedBS <- getUnmeth(MSet.noob)[,c(1,3,5,6)]

MethylatedOxBS <- getMeth(MSet.noob)[,c(7,8,2,4)]
UnMethylatedOxBS <- getUnmeth(MSet.noob)[,c(7,8,2,4)]

colnames(MethylatedBS) <- c("sample1","sample2","sample3","sample4")
colnames(UnMethylatedBS) <- c("sample1","sample2","sample3","sample4")
colnames(MethylatedOxBS) <- c("sample1","sample2","sample3","sample4")
colnames(UnMethylatedOxBS) <- c("sample1","sample2","sample3","sample4")

CpG <- rownames(MethylatedBS)

N_BS <- round(MethylatedBS+UnMethylatedBS)

N_OxBS <- round(MethylatedOxBS+UnMethylatedOxBS)

N_TAB <- pmax(N_BS,N_OxBS)

# Use estimates from dataset as base for the true parameters in the simulation
library(MLML2R)
results_exact <- MLML(T = MethylatedBS , U = UnMethylatedBS, L = UnMethylatedOxBS, M = MethylatedOxBS)


set.seed(2017)

temp1 <- data.frame(n=as.vector(N_BS),p_m=c(results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1]),p_h=c(results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1]))

MethylatedBS_temp <- c()
for (i in 1:dim(temp1)[1])
{
  MethylatedBS_temp[i] <- rbinom(n=1, size=temp1$n[i], prob=(temp1$p_m[i]+temp1$p_h[i]))
}

UnMethylatedBS_sim2 <- matrix(N_BS - MethylatedBS_temp,ncol=4)
MethylatedBS_sim2 <- matrix(MethylatedBS_temp,ncol=4)

temp1 <- data.frame(n=as.vector(N_OxBS),p_m=c(results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1]),p_h=c(results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1]))

MethylatedOxBS_temp <- c()
for (i in 1:dim(temp1)[1])
{
  MethylatedOxBS_temp[i] <- rbinom(n=1, size=temp1$n[i], prob=temp1$p_m[i])
}

UnMethylatedOxBS_sim2 <- matrix(N_OxBS - MethylatedOxBS_temp,ncol=4)
MethylatedOxBS_sim2 <- matrix(MethylatedOxBS_temp,ncol=4)


temp1 <- data.frame(n=as.vector(N_TAB),p_m=c(results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1],results_exact$mC[,1]),p_h=c(results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1],results_exact$hmC[,1]))

MethylatedTAB_temp <- c()
for (i in 1:dim(temp1)[1])
{
  MethylatedTAB_temp[i] <- rbinom(n=1, size=temp1$n[i], prob=temp1$p_h[i])
}


UnMethylatedTAB_sim2 <- matrix(N_TAB - MethylatedTAB_temp,ncol=4)
MethylatedTAB_sim2 <- matrix(MethylatedTAB_temp,ncol=4)


set.seed(112017)

a <- sample(1:dim(MethylatedBS)[1],1000,replace=FALSE)

MethylatedBS_sim2 <- MethylatedBS_sim2[a,]
UnMethylatedBS_sim2 <- UnMethylatedBS_sim2[a,]
MethylatedOxBS_sim2 <- MethylatedOxBS_sim2[a,]
UnMethylatedOxBS_sim2 <- UnMethylatedOxBS_sim2[a,]
MethylatedTAB_sim2 <- MethylatedTAB_sim2[a,]
UnMethylatedTAB_sim2 <- UnMethylatedTAB_sim2[a,]

colnames(MethylatedBS_sim2) <- c("sample1","sample2","sample3","sample4")
colnames(UnMethylatedBS_sim2) <- c("sample1","sample2","sample3","sample4")
colnames(MethylatedOxBS_sim2) <- c("sample1","sample2","sample3","sample4")
colnames(UnMethylatedOxBS_sim2) <- c("sample1","sample2","sample3","sample4")

rownames(MethylatedBS_sim2) <- CpG[a]
rownames(UnMethylatedBS_sim2) <- CpG[a]
rownames(MethylatedOxBS_sim2) <- CpG[a]
rownames(UnMethylatedOxBS_sim2) <- CpG[a]
rownames(MethylatedTAB_sim2) <- CpG[a]
rownames(UnMethylatedTAB_sim2) <- CpG[a]


save(MethylatedBS_sim2,file="MethylatedBS_sim2.rda")
save(UnMethylatedBS_sim2,file="UnMethylatedBS_sim2.rda")
save(MethylatedOxBS_sim2,file="MethylatedOxBS_sim2.rda")
save(UnMethylatedOxBS_sim2,file="UnMethylatedOxBS_sim2.rda")
save(MethylatedTAB_sim2,file="MethylatedTAB_sim2.rda")
save(UnMethylatedTAB_sim2,file="UnMethylatedTAB_sim2.rda")


true_parameters_sim2 <- data.frame(p_m=results_exact$mC[,1],p_h=results_exact$hmC[,1])
true_parameters_sim2$p_u <- 1-true_parameters_sim2$p_m-true_parameters_sim2$p_h
true_parameters_sim2 <- true_parameters_sim2[a,]
save(true_parameters_sim2,file="true_parameters_sim2.rda")


samarafk/MLML2R documentation built on Oct. 19, 2019, 6:04 p.m.