-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalization.R
53 lines (47 loc) · 2.29 KB
/
normalization.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
############################################################################
############################################################################
########### ###########
########### Script for data Normalization IDATs BMIQ + ENmix ###########
########### Author: Diego Montiel Gonzalez ###########
########### ###########
########### Erasmus MC University Medical Centre ###########
########### Rotterdam, The Netherlands ###########
########### ###########
########### [email protected] ###########
########### ###########
############################################################################
############################################################################
## Load libraries ##
library(minfi)
library(data.table)
library(wateRmelon)
library(ENmix)
library(RPMM)
## Path for IDATs after QC
setwd("PATH/Y-CpG/IDAT/")
#####################################
### Normalization with BMIQ + ENmix
#####################################
# train + validation IDATs
probes2remove <- read.table("../data/qc_train/probes2remove.txt",header = F)
probes2remove <- probes2remove$V1
probes2remove <- (probes2remove[!duplicated(probes2remove)])
## Tested with 40 cores ~2 hours
gc()
rgSet <- read.metharray.exp(getwd())
um.q0 <- preprocessENmix(rgSet, bgParaEst = 'oob', dyeCorr = 'RELIC',
nCores=40, exCpG = probes2remove)
qc();
# Save an object to a file
saveRDS(um.q0, file = "../data/um.q0_preprocessENMIx.rds")
# Restore the object
um.q0 <- readRDS(file = "../data/um.q0_preprocessENMIx.rds")
gc();
um.qi <- norm.quantile(mdat = um.q0, method='quantile1')
saveRDS(um.qi, file = "../data/um.qi_preprocessENMIx.rds")
rm(um.q0) ; gc()
gc()
um.qi <- readRDS(file = "../data/um.qi_preprocessENMIx.rds")
df.beta.bmiq <- ENmix::bmiq.mc(mdat = um.qi, nCores=40)
samples <- unlist(lapply(X = strsplit(colnames(df.beta.bmiq), split = '[_]'), FUN = function(X) {X[1]}))
fwrite(as.data.frame(nocombat.beta.bmiq), file = "../data/beta_values_bmiq.txt", sep="\t", nThread = 40, row.names = T)