Skip to content

Paired methylation from IDAT files

An IDAT file contains the array’s measured intensities before they become beta values. Start there when you need detection checks, bead counts, and a defined normalization method. A beta matrix alone cannot recover those measurements.

This lesson compares activated and resting naive T cells from three donors in GSE49667. Each donor contributes one array per condition. The six arrays therefore give three biological pairs, not six independent donors. The study also contains regulatory T cell arrays, which do not enter this comparison.

Preserve the public samples and raw signals

Section titled “Preserve the public samples and raw signals”

Download the sample records and extract their inputs/ directory. Download the versioned workflow archive and copy the contents of methylationArrayAnalysis/inst/extdata/ into inputs/idat/. That directory contains the IDAT files, the original sample sheet, and the published cross-reactive probe list. The sample records include SHA-256 hashes of the source archive and each file used here.

The archive includes eleven arrays. Ten belong to GSE49667, and one unrelated birth sample illustrates poor quality in the source workflow. Only the six arrays listed below enter this lesson. Their donor and cell labels agree with the GEO sample records and the archived sample sheet.

suppressPackageStartupMessages(library(minfi))
suppressPackageStartupMessages(library(limma))
sample_table <- read.csv("inputs/samples.csv", stringsAsFactors = FALSE)
sample_table$donor <- factor(sample_table$donor)
sample_table$condition <- factor(sample_table$condition,
levels = c("naive", "activated"))
stopifnot(!anyNA(sample_table), !anyDuplicated(sample_table$sample_id))
stopifnot(all(table(sample_table$donor, sample_table$condition) == 1L))
data_dir <- Sys.getenv("METHYLATION_INPUT_DIR", "inputs/idat")
rg_set <- read.metharray(file.path(data_dir, sample_table$basename),
extended = TRUE)
sampleNames(rg_set) <- sample_table$sample_id
stopifnot(ncol(rg_set) == nrow(sample_table))
dir.create("outputs", showWarnings = FALSE)
print(sample_table, row.names = FALSE)
cat("Biological donor pairs:", nlevels(sample_table$donor), "\n")
sample_id donor condition basename
GSM1204705 M28 naive 6264509100/6264509100_R01C01
GSM1204707 M28 activated 6264509100/6264509100_R03C01
GSM1204708 M29 naive 6264509100/6264509100_R04C01
GSM1204709 M29 activated 6264509100/6264509100_R05C01
GSM1204711 M30 naive 6264509100/6264509100_R01C02
GSM1204713 M30 activated 6264509100/6264509100_R03C02
Biological donor pairs: 3

Detection p-values compare probe signal with background estimated from negative controls. This example requires fewer than 1% of probes to have detection p-values above 0.01 in each sample. The threshold is a declared analysis rule; an array with a different failure pattern also needs inspection of its raw intensities and laboratory records.

The code stops if a sample fails. It does not remove one member of a pair and continue with a different design. The intensity plot shows median methylated and unmethylated signals before correction, with the sample identities visible.

det_p <- detectionP(rg_set)
raw_set <- preprocessRaw(rg_set)
raw_qc <- as.data.frame(getQC(raw_set))
sample_qc <- data.frame(sample_table[, 1:3], raw_qc,
failed_fraction = colMeans(det_p > 0.01))
sample_qc$pass <- sample_qc$failed_fraction < 0.01
print(sample_qc, row.names = FALSE, digits = 4)
stopifnot(all(sample_qc$pass))
write.csv(sample_qc, "outputs/sample_qc.csv", row.names = FALSE)
png("outputs/methylation_sample_qc.png", width = 1600,
height = 700, res = 150)
par(mfrow = c(1, 2), mar = c(7, 4, 3, 1))
barplot(sample_qc$failed_fraction * 100,
names.arg = sample_table$sample_id, las = 2, col = "#46708c",
ylim = c(0, 1.1), ylab = "Probes failing detection (%)")
abline(h = 1, lty = 2, col = "#ad4d3e")
plot(raw_qc$mMed, raw_qc$uMed, pch = 19, col = "#46708c",
xlim = range(raw_qc$mMed) + c(-0.25, 0.25),
ylim = range(raw_qc$uMed) + c(-0.1, 0.2),
xlab = "Median log2 methylated signal",
ylab = "Median log2 unmethylated signal")
text(raw_qc$mMed, raw_qc$uMed, labels = sample_table$sample_id,
pos = 3, cex = 0.6)
invisible(dev.off())
sample_id donor condition mMed uMed failed_fraction pass
GSM1204705 M28 naive 10.30 9.765 0.0004861 TRUE
GSM1204707 M28 activated 10.90 10.568 0.0005211 TRUE
GSM1204708 M29 naive 11.89 11.088 0.0003254 TRUE
GSM1204709 M29 activated 11.86 11.478 0.0003131 TRUE
GSM1204711 M30 naive 11.21 10.444 0.0004820 TRUE
GSM1204713 M30 activated 11.06 10.663 0.0007024 TRUE

The sample plot shows the fraction of failed detection tests and median raw intensities for each of the six arrays.

Correct background and remove unreliable probes

Section titled “Correct background and remove unreliable probes”

Single sample noob corrects background and dye bias without forcing every sample to have the same methylation distribution. It does not remove a donor effect, correct cell mixtures, or repair sample swaps. The subsequent model handles donor differences.

The probe filter requires detection p-values at most 0.01 and at least three beads in every sample. Type I probes require both assay addresses to pass. The analysis then restricts the family to autosomal CpGs, removes probes with an annotated SNP at the CpG or single base extension site, and removes the cross-reactive probes identified by Chen and colleagues. The SNP rule uses the archived annotation at any recorded minor allele frequency.

norm_set <- preprocessNoob(rg_set, dyeMethod = "single")
genome_set <- mapToGenome(norm_set)
annotation <- getAnnotation(genome_set)
beads <- getNBeads(rg_set)
type_one <- getProbeInfo(rg_set, type = "I")
type_two <- getProbeInfo(rg_set, type = "II")
beads_one <- pmin(beads[type_one$AddressA, ], beads[type_one$AddressB, ])
beads_two <- beads[type_two$AddressA, ]
rownames(beads_one) <- type_one$Name
rownames(beads_two) <- type_two$Name
probe_beads <- rbind(beads_one, beads_two)[rownames(genome_set), ]
detection_ok <- rowSums(det_p[rownames(genome_set), ] > 0.01) == 0
beads_ok <- rowSums(is.na(probe_beads) | probe_beads < 3) == 0
autosomal <- annotation$chr %in% paste0("chr", 1:22) &
startsWith(rownames(genome_set), "cg")
snp_free <- rownames(dropLociWithSnps(genome_set,
snps = c("CpG", "SBE"), maf = 0))
cross_reactive <- read.csv(file.path(data_dir,
"48639-non-specific-probes-Illumina450k.csv"))$TargetID
probe_qc <- data.frame(probe_id = rownames(genome_set),
detection_ok, beads_ok, autosomal,
snp_ok = rownames(genome_set) %in% snp_free,
specificity_ok = !rownames(genome_set) %in% cross_reactive)
probe_qc$keep <- rowSums(!probe_qc[, -1]) == 0
print(colSums(probe_qc[, -1]))
filtered_set <- genome_set[probe_qc$keep, ]
beta_values <- getBeta(filtered_set)
m_values <- getM(filtered_set)
stopifnot(all(is.finite(m_values)), !anyNA(beta_values))
write.csv(probe_qc, "outputs/probe_qc.csv", row.names = FALSE)
cat("Autosomal CpGs in the test family:", nrow(m_values), "\n")
detection_ok beads_ok autosomal snp_ok specificity_ok
484779 481451 470870 467971 456279
keep
423100
Autosomal CpGs in the test family: 423100

Each filter count above describes that rule separately. Their overlap means that subtracting those counts from the array size would count some probes more than once. The final keep count defines the multiple-testing family. The hg19 annotation belongs to this archived 450K analysis; use a matching manifest and probe exclusion resources for EPIC or another array generation.

M-values are log ratios of methylated to unmethylated signal. Limma fits these values with one donor term per additional donor and an activation term. With six samples and four design columns, each probe has two residual degrees of freedom before empirical Bayes moderation borrows variance information across probes.

Beta differences remain easier to read as effect sizes. A difference of 0.10 is ten percentage points of beta value, not a 10% relative increase and not proof that 10% more cells carry a methylated allele.

design <- model.matrix(~ donor + condition, data = sample_table)
stopifnot(qr(design)$rank == ncol(design))
fit <- eBayes(lmFit(m_values, design))
coefficient <- "conditionactivated"
result <- topTable(fit, coef = coefficient, number = Inf,
adjust.method = "BH", sort.by = "none")
naive <- which(sample_table$condition == "naive")
activated <- which(sample_table$condition == "activated")
stopifnot(identical(sample_table$donor[naive],
sample_table$donor[activated]))
paired_delta <- beta_values[, activated] - beta_values[, naive]
result$delta_beta <- rowMeans(paired_delta)
result$probe_id <- rownames(result)
result <- result[order(result$P.Value), ]
stopifnot(isTRUE(all.equal(result$adj.P.Val,
p.adjust(result$P.Value, "BH"))))
cat("Design rank:", qr(design)$rank, "\n")
cat("Residual degrees of freedom:", unique(fit$df.residual), "\n")
cat("CpGs with BH adjusted p < 0.05:",
sum(result$adj.P.Val < 0.05), "\n")
print(head(result[, c("probe_id", "logFC", "delta_beta", "P.Value",
"adj.P.Val")], 6), row.names = FALSE, digits = 4)
write.csv(result, "outputs/differential_methylation.csv", row.names = FALSE)
write.csv(beta_values, "outputs/filtered_beta_values.csv")
write.csv(design, "outputs/design.csv")
saveRDS(list(fit = fit, m_values = m_values, beta_values = beta_values,
sample_table = sample_table), "outputs/fitted_analysis.rds")
Design rank: 4
Residual degrees of freedom: 2
CpGs with BH adjusted p < 0.05: 2240
probe_id logFC delta_beta P.Value adj.P.Val
cg03899643 -5.940 -0.7550 4.344e-09 0.0005138
cg15459165 4.752 0.4967 6.786e-09 0.0005138
cg19704755 5.316 0.7185 9.757e-09 0.0005138
cg00183239 -4.287 -0.5394 1.087e-08 0.0005138
cg12966876 -4.425 -0.6317 1.141e-08 0.0005138
cg04677410 -5.194 -0.7030 1.237e-08 0.0005138

The coefficient called logFC by limma is a difference in M-values here. It is not an expression fold change. The BH adjustment covers all retained autosomal CpGs, and the reported count uses only the declared p-value rule. An additional beta threshold would describe a selected subset of those discoveries, not a new test of a minimum effect. The top 1,000 results provide a ranked extract for inspection. The code writes the complete result table, and every adjusted p-value uses the full filtered family.

The plot selects the CpG with the smallest p-value after the analysis. Lines connect each donor’s resting and activated cells. A consistent direction across these three donors is useful context, but selection from the same data does not provide an independent confirmation.

top_probe <- result$probe_id[1]
top_beta <- beta_values[top_probe, ]
png("outputs/methylation_paired_effect.png", width = 1400,
height = 700, res = 150)
par(mfrow = c(1, 2), mar = c(5, 4, 3, 1))
plot(result$delta_beta, -log10(result$P.Value), pch = 16, cex = 0.35,
col = ifelse(result$adj.P.Val < 0.05, "#ad4d3e66", "#46708c22"),
xlab = "Mean paired beta difference", ylab = "-log10 p-value")
abline(v = 0, lty = 2)
plot(c(1, 2), c(0, 1), type = "n", xaxt = "n", xlim = c(0.8, 2.2),
xlab = "Condition", ylab = "Beta value", main = top_probe)
axis(1, at = c(1, 2), labels = c("Resting", "Activated"))
donor_colors <- c("#46708c", "#ad4d3e", "#63844d")
for (i in seq_along(naive)) {
lines(c(1, 2), top_beta[c(naive[i], activated[i])], type = "b",
pch = 19, col = donor_colors[i], lwd = 2)
}
legend("topright", legend = levels(sample_table$donor),
col = donor_colors, pch = 19, lty = 1, bty = "n")
invisible(dev.off())
cat("Displayed CpG:", top_probe, "\n")
print(data.frame(sample_table[, 1:3], beta_value = top_beta),
row.names = FALSE, digits = 4)
Displayed CpG: cg03899643
sample_id donor condition beta_value
GSM1204705 M28 naive 0.9367
GSM1204707 M28 activated 0.1807
GSM1204708 M29 naive 0.9118
GSM1204709 M29 activated 0.1115
GSM1204711 M30 naive 0.9166
GSM1204713 M30 activated 0.2077

The first panel shows paired beta differences and p-values. The second connects each donor’s beta values for the selected CpG.

Three donors provide little information about variation between people. The arrays share one slide, and the design has no separate slide effect to estimate. A larger study should balance conditions across slides and include measured technical variables when its design permits them.

These sorted cell populations also differ from whole blood. Applying the same formula to whole blood without considering cell composition can assign a change in cell proportions to methylation within a cell type. Probe-level results do not establish regional methylation changes or regulation of a nearby gene.

Aryee and colleagues, 2014 describe minfi and its analysis of Infinium methylation arrays.

Triche and colleagues, 2013 describe the noob background correction used in this lesson.

Fortin, Triche, and Hansen, 2017 describe single sample noob and support for multiple methylation array generations.

Ritchie and colleagues, 2015 describe limma and its linear models for differential expression in microarray and RNA-seq data.

Zhang and colleagues, 2013 describe the public T cell methylation experiment used here.

Chen and colleagues, 2013 identify cross-reactive probes and polymorphic CpGs in the 450K array.

Hansen and Aryee, 2012 document the 450K manifest used to map assay addresses to probes.

Hansen, 2021 documents the hg19 probe and SNP annotation used in the filter.

Maksimovic, 2026 documents the workflow package that distributes the IDAT files, sample sheet, and cross-reactive probe list.

The versioned methylation workflow extends the analysis to other cell types, regions, and cell composition. Its sample descriptions explain the additional arrays excluded from this lesson.

The minfi 1.58.0 user guide explains raw array objects and preprocessing methods. It helps distinguish correction of technical signals from a biological comparison.