Differential accessibility

From consensus peaks to a count matrix, normalisation and DESeq2 for chromatin accessibility

Epigenetics

About this lecture

ATAC-seq processing and peak calling ended with one set of peaks for all samples. Now we ask which of those regulatory elements are more open in one cell type (or condition) than in another. Most of the statistics is the DESeq2 you know from RNA-seq; this lecture spends its time on what is different.

  • From peaks and BAM files to a count matrix: consensus peaks, what to count.
  • The running example: B cells vs CD4 T cells from three donors (Corces et al. 2016), and why the design is paired.
  • Exploration: reads in peaks, PCA, sample correlation.
  • Normalisation, the central difference from RNA-seq: peaks, background, spike-ins, and what a global change does.
  • DESeq2 on peaks: dispersion, MA and volcano plots, shrinkage.
  • Interpretation: marker genes, nearest-gene caveats, agreement with RNA-seq.

The question

  • Two cell types share most of their open chromatin (promoters of housekeeping genes), but each has its own enhancers.
  • Differential accessibility (DA): which peaks have more fragments in one group than in the other, more than donors differ among themselves?
  • Answers can be all-or-none (an enhancer open only in B cells) or quantitative (2.5-fold more open).

What is the same as RNA-seq, and what is not

  • Same: a count matrix, the negative binomial GLM, the design formula, dispersion shrinkage, Wald test, Benjamini–Hochberg, fold-change shrinkage. DESeq2 or edgeR run unchanged.
  • Different: the rows are found in the data; the normalisation assumption (“most features do not change”) is shakier; the result is a list of regions, which needs annotation before it means anything.

One set of regions for all samples

  • Every sample must be counted in the same regions. Peaks called per sample must be combined into a consensus set.
  • Union and merge (A) is simple, but nearby elements fuse into wide regions of unequal width.
  • Fixed-width peaks (B): extend each summit to 500 bp, keep the most significant, drop those that overlap it. Used by Corces et al. 2016 and by ArchR; DiffBind re-centres on summits (± 200 bp).
  • Keep only peaks found in at least k samples (DiffBind default: 2) or call peaks on pooled data per group, so one noisy sample does not add thousands of peaks.

What to count in a peak

  • ATAC-seq measures Tn5 insertions: each fragment end is a cut site in open chromatin. Fragment 4 spans the peak without a single cut inside it.
  • Counting fragments that overlap the peak (featureCounts with pairs, bedtools multicov) is the common default; counting insertions (fragment ends, shifted +4/−5) is more precise and what ArchR and chromVAR use.
  • Either way: one number per peak per sample, integer counts, no normalisation yet.

Counting on the command line

# consensus peaks (BED) -> SAF, the simple annotation format of featureCounts
awk 'BEGIN { OFS = "\t"; print "GeneID", "Chr", "Start", "End", "Strand" }
     { print "peak" NR, $1, $2 + 1, $3, "." }' consensus.bed > consensus.saf

# count fragments (read pairs) per peak, all samples at once
featureCounts -F SAF -a consensus.saf -p --countReadPairs -B -C \
  -T 8 -o atac_counts.txt sample1.bam sample2.bam sample3.bam ...

# or, with bedtools: one column per BAM
bedtools multicov -bams sample1.bam sample2.bam -bed consensus.bed > atac_counts.bed
  • -p --countReadPairs: count fragments, not reads. -B -C: both ends aligned, on the same chromosome.
  • SAF is 1-based (start + 1), BED is 0-based: the boundary from Genomic intervals again.
  • The output is the matrix: peaks × samples. Corces et al. provide it, so the exercise starts there.

The dataset: Corces et al. 2016

  • ATAC-seq of 13 FACS-sorted blood cell types from 7 healthy donors (plus AML samples we ignore): 590 650 peaks (hg19) × 132 libraries, GEO GSE74912.
  • Our comparison: B cells vs CD4 T cells from the 3 donors with both (1022, 4983, 5483): 8 libraries.
  • Column names encode donor and cell type: Donor4983-CD4-9A-150120 = donor 4983, CD4 T cells (code 9), library A, run date. Early samples are just 4983-7A (code 7 = monocytes): decode from the GEO sample table, never guess.

The peaks are hg19: liftOver

gr19 <- GRanges(atac$Chr, IRanges(atac$Start + 1, atac$End))   # 0-based starts in the file
lo   <- liftOver(gr19, import.chain("hg19ToHg38.over.chain"))  # a GRangesList: 0, 1 or more pieces
table(lengths(lo))
result of liftOver peaks
no match in GRCh38 (deleted or rearranged) 159
split into ≥ 2 pieces 1 375
one piece, but not 500 bp or a different chromosome 46
one piece, 500 bp: kept 589 070 (99.7%)
  • Dropping 0.3% of the peaks is fine here. Better still, when you have the reads: re-align to GRCh38 and call peaks there.

Technical and biological replicates

  • Biological replicates = independent donors. They carry the variation the test must beat.
  • Technical replicates (A, B) = two libraries from the same sorted cells. They measure library noise only: sum them (collapseReplicates), do not count them as extra samples.
  • 8 libraries → 6 columns: 3 donors × 2 cell types.

Why pair by donor?

  • If donors differ (genotype, age, sex, sample handling), each B-cell sample shares part of that difference with the T-cell sample from the same person.
  • ~ donor + celltype compares every donor with itself: the donor effect is removed, and the celltype coefficient is the within-donor log fold change.
  • The cost: one coefficient per extra donor. With 6 samples, the residual degrees of freedom drop from 4 to 2.

Exploration: reads in peaks per library

  • Reads in peaks range from 0.6 to 25 million per library: a 40-fold range, partly sequencing depth and partly signal-to-noise (the fraction of reads in peaks, FRiP).
  • Erythroblasts are low in every donor (Corces et al. report poor replicate agreement for them, r ≈ 0.5). The B-cell library of donor 1022 has 4.6 M reads in peaks; the B cells of 4983 and 5483 have 17–18 M (5483: two libraries summed).

Signal-to-noise differs between libraries

  • Same depth, FRiP 40% vs 10%: a typical peak gets 4 times fewer fragments in library 2.
  • Normalising by total reads makes every peak “4-fold up” in library 1. Normalising within peaks says nothing changed.
  • Which one is right depends on why FRiP differs. A worse library? Then within-peak normalisation. Fewer or weaker open sites in the cells? Then the total-read answer may be the biology.

PCA: cell type dominates

  • VST of 127 515 peaks with mean count ≥ 10, all 77 healthy libraries, the 10 000 most variable peaks.
  • Libraries cluster by cell type, not by donor (shape). PC1 runs from stem and progenitor cells (left) to mature cells (right); PC2 separates the erythroid branch (MEP → erythroblasts).

The six samples of our comparison

  • Pearson correlation of log2 CPM over 75 922 peaks (mean CPM ≥ 2), all 8 libraries.
  • Technical replicates: r = 0.94. Same cell type, other donor: 0.77–0.88 (B), 0.87–0.93 (CD4). B vs CD4: 0.19–0.37.
  • The 1022 B-cell library correlates least with its group: fewest reads in peaks (4.6 M).

Normalisation: median of ratios, on peaks

  • DESeq2 size factor for sample j: s_j = \text{median}_i \, \dfrac{k_{ij}}{\left(\prod_{v} k_{iv}\right)^{1/m}}, the median over peaks of the count divided by the peak’s geometric mean.
  • The same as for genes. The assumption is too: the typical (median) peak does not change.
  • Here, for the 1022 B-cell library: size factor 0.46 from the median ratio, 0.35 from total counts in peaks.

When most peaks do change: a global opening

  • A treatment that opens chromatin everywhere (e.g. an HDAC inhibitor) gives more fragments in every peak. Sequenced to the same depth, the extra signal is diluted.
  • Peak-based size factors make the median peak unchanged: the global opening disappears, and only the relative change (p5) survives, at half its size.
  • Background bins (reads outside peaks) can recover it, if the background truly is constant.

Four ways to normalise, four assumptions

  • No method is assumption-free. Pick the one whose assumption you can defend for your experiment, and say it in the methods.
  • If two reasonable methods disagree, the disagreement is the result: report it (Reske et al. 2020 found the number and direction of DA peaks change with the method).

Real data: the choice changes the answer

  • DESeq2 and TMM factors agree within 10%; total counts differ by up to 25% (B cells of 1022 and 4983).
  • Same model, same data: 19 438 / 17 202 peaks up in B / up in T with DESeq2 factors, 18 342 / 19 074 with TMM, 23 703 / 13 540 with total counts.
  • Total counts shift all fold changes towards B (median log2 FC 0.52 vs 0.26 with DESeq2 factors): relative to the typical peak, the B-cell libraries have more reads in peaks.

Tools: DiffBind and csaw

  • DiffBind: peak-based. Builds the consensus, counts, then calls DESeq2 or edgeR. What we do by hand in this unit.
  • csaw: window-based. No peak calling; counts in sliding windows, normalises on background bins, tests each window, merges windows into regions and controls the FDR over regions.
  • Neither is installed in this course: the exercise does the same steps with DESeq2 and edgeR directly.

DESeq2 on peaks

dds <- DESeqDataSet(se, design = ~ donor + celltype)       # se: peaks x 8 libraries, rowRanges in hg38
dds <- collapseReplicates(dds, groupby = dds$unit)         # 8 libraries -> 6 samples
dds <- dds[rowSums(counts(dds) >= 10) >= 3, ]              # 211 824 of 589 070 peaks
dds <- DESeq(dds)                                          # about 1 minute
res <- results(dds, name = "celltype_Bcell_vs_CD4", alpha = 0.05)
shr <- lfcShrink(dds, coef = "celltype_Bcell_vs_CD4", type = "apeglm")   # about 2 minutes
  • Exactly the RNA-seq workflow. Filter first: most of the 589 070 peaks were called in other cell types and have almost no reads in B or T cells.
  • celltype levels CD4, Bcell: positive log2 fold change = more open in B cells.

Dispersion: paired or not

  • The familiar picture: noisy per-peak estimates, a fitted trend, shrunk final values. Typical dispersion ≈ 0.4 (coefficient of variation ≈ 60% between donors), higher than for genes.
  • Here the donor effect is small: only 47 peaks have a significant donor term (LRT). Pairing costs 2 degrees of freedom: 36 703 peaks at padj < 0.05 paired, 41 671 unpaired.

MA plot and fold-change shrinkage

  • Left: maximum-likelihood fold changes are huge and noisy for weak peaks (few reads: 0 vs 5 is “infinitely” open).
  • Right: apeglm shrinks uncertain fold changes towards 0 and leaves well-measured ones alone. Use shrunk values to rank and filter by effect size, and for plots.
  • Blue/orange: padj < 0.05 and |shrunk LFC| > 1. Where counts are high, the grey cloud of unchanged peaks sits on 0: the normalisation assumption holds for most peaks.

Volcano plot

  • 19 404 peaks more open in B cells and 16 897 more open in CD4 T cells (padj < 0.05, |shrunk log2 FC| > 1), out of 211 824 tested.
  • 17% of tested peaks differ more than 2-fold: B and T cells are distinct lineages, so this is expected. A drug treatment typically moves hundreds, not tens of thousands.

Do the peaks make sense? Marker loci

  • Each bar is one peak (mean normalised count over 3 donors): blue = open in B, orange = open in T, grey = not differential.
  • PAX5 (B-cell identity factor): 31 peaks whose nearest TSS is PAX5 open in B, none in T. BCL11B (T-cell commitment): 58 open in T, 1 in B.
  • Other markers: CD79A, MS4A1, CD19, BLK, EBF1 (B); CD3E, TCF7, LEF1, GATA3, CD28 (T).

From peaks to genes: the nearest-TSS caveat

  • Only 8% of B-specific and 14% of T-specific peaks are within 1 kb of a protein-coding TSS (20% of all tested peaks): DA peaks are mostly distal.
  • Assigning each peak to its nearest gene is a first guess, right for perhaps half of enhancers. Better links use contacts or correlation (Linking regulatory elements to genes).

Does accessibility agree with expression?

  • RNA-seq from the same study (GSE74246), B vs CD4 T cells from 4 donors, DESeq2 ~ donor + celltype.
  • Genes near B-open peaks go up in B (median RNA log2 FC +0.5), near T-open peaks go up in T (−0.6). Promoter peaks agree well (Spearman 0.69), distal peaks less (0.42).

The result to reuse

tab <- data.frame(peak_id = names(dds), chr = seqnames(dds), start = start(dds), end = end(dds),
                  baseMean = res$baseMean, log2FoldChange = shr$log2FoldChange, lfcSE = shr$lfcSE,
                  pvalue = res$pvalue, padj = res$padj, nearest_gene = ..., dist_to_tss = ...)
tab$class <- ifelse(tab$padj < 0.05 & tab$log2FoldChange >  1, "B_up",
             ifelse(tab$padj < 0.05 & tab$log2FoldChange < -1, "T_up", "ns"))
write.table(tab, "differential_peaks.tsv", sep = "\t", quote = FALSE, row.names = FALSE)
  • Definition: differential = padj < 0.05 and |shrunken log2 FC| > 1; B_up = more open in B cells, T_up = more open in CD4 T cells. GRCh38, 1-based coordinates, 500 bp.
  • Keep all tested peaks (class ns included): motif enrichment needs a background.

Limitations of this analysis

  • Sorted populations are still mixtures: a 2% contamination of T cells in the B-cell sort puts T-cell peaks into the B-cell counts. “Specific” means “much more”, not “only”. Single-cell ATAC avoids this, at the price of sparse counts.
  • Peaks lifted from hg19: 0.3% lost; reads were aligned to an older genome.
  • Fixed 500-bp peaks: good for TF sites and comparable counts, but a broad domain is cut into pieces or partly missed.
  • Peaks called in all 13 cell types: the set includes elements never open in B or T cells (filtered out), and misses none that are open in only one sample.
  • Three donors per group: dispersion estimates rely heavily on the trend; one weak library (1022) carries a lot of weight.
  • Normalisation: peak-based by choice. A real global difference in accessibility between B and T cells would be hidden.

Summary

idea key fact
consensus peaks one region set for all samples; fixed-width summit peaks keep elements apart
counting fragments (or Tn5 insertions) per peak; featureCounts / multicov; integer counts
replicates donors are biological replicates; technical replicates are summed
design ~ donor + celltype for paired samples; decide before looking at the hit count
normalisation peak-based (median ratio, TMM) assumes most peaks unchanged; background bins, spike-ins otherwise
global change hidden by peak-based size factors; FRiP differences can fake or hide it
statistics DESeq2/edgeR exactly as for RNA-seq; filter low-count peaks; shrink fold changes
interpretation DA peaks are mostly distal; nearest gene is a guess; check markers and RNA
this dataset 211 824 peaks tested; 19 404 B_up, 16 897 T_up (padj < 0.05, |LFC| > 1)

Key papers (optional further reading)

Not required reading and not examined. For those who want the primary literature.