From reads to coverage

Trimming, alignment, filtering and normalised signal tracks for ChIP, ATAC and CUT&Tag

Epigenetics

About this lecture

ChIP-seq, ATAC-seq and CUT&Tag measure different things, but they all hand you the same raw material: DNA fragments from enriched regions, read by a sequencer. This lecture is the shared processing that turns those reads into a signal track you can trust.

  • Reads: FASTQ, base qualities, adapters, trimming.
  • Alignment: bowtie2, SAM/BAM, FLAGs, MAPQ and multi-mapping reads.
  • Filtering: duplicates, the blacklist, chrM, the order of the steps.
  • Coverage: read extension, CPM and RPGC, fold change over input, with deepTools.
  • Real data throughout: GM12878 CTCF ChIP-seq and its input, chr21.

Three assays, one kind of data

  • ChIP: crosslink, shear, pull down with an antibody. ATAC: Tn5 cuts open DNA. CUT&Tag: an antibody tethers Tn5 to the target.
  • Each gives fragments, more of them at the target than elsewhere. We sequence one end (single-end) or both ends (paired-end) of each fragment.
  • Processing: find where each fragment came from, keep the trustworthy ones, count how many cover each position, compare with the background.

FASTQ and base quality

  • Four lines per read: name, sequence, +, quality. Each quality character encodes Q = −10 log10(perror).
  • Q20 = 1 error in 100, Q30 = 1 in 1000. To decode: ASCII code − offset (33 today, 64 in old Illumina files like this one).

Real data: quality along the read

  • CTCF ChIP (36 bp, 2011): median Q38, mean Q37 at the start, Q35 at the last base. Input (28 bp, 2009): mean Q27 falling to Q24; at the last base 16% of bases are below Q20.
  • Quality falls along the read: the sequencing chemistry loses phase cycle by cycle. A few bad bases are tolerated by the aligner; bad tails are trimmed.

Adapters and read-through

  • If the fragment is shorter than the read, the sequencer reads on into the adapter. The adapter part matches nothing in the genome.
  • Common in ATAC and CUT&Tag (fragments under 100 bp), rare in sonicated ChIP with short reads: fastp found no adapter in our 36 bp CTCF reads.
  • fastp detects adapters (from the data, or from the overlap of paired reads) and trims them, removes low-quality and too-short reads (tail trimming on request: --cut_right), and writes an HTML report.
fastp -w 8 -i chip.fastq.gz -o chip.trim.fastq.gz -h chip.fastp.html -j chip.fastp.json

Aligning DNA is simpler than aligning RNA

  • No splicing: a read from genomic DNA aligns contiguously, with at most a few mismatches and small indels. bowtie2 or BWA-MEM, not STAR.
  • No annotation: every position of the genome is a possible target. The regions come from the data (peaks), not from a GTF.

How bowtie2 finds a position: seed and extend

bowtie2 on the command line

# once per genome: build the index (chr21 + chrM in this course; 27 s with 8 threads)
bowtie2-build --threads 8 hg38_chr21_chrM.fa hg38_chr21_chrM

# align, and sort by position on the way out (3 s for 380 000 reads)
bowtie2 -p 8 -x hg38_chr21_chrM -U chip.trim.fastq.gz 2> chip.bowtie2.log \
  | samtools sort -@ 4 -o chip.sorted.bam -
samtools index chip.sorted.bam          # .bai: jump to any region
samtools flagstat chip.sorted.bam       # how many mapped, paired, duplicates ...
samtools idxstats chip.sorted.bam       # reads per chromosome
380570 reads; of these: 2014 (0.53%) aligned 0 times
                        291310 (76.55%) aligned exactly 1 time
                        87246 (22.93%) aligned >1 times

The SAM record

Decoding the FLAG by hand

MAPQ and reads in repeats

  • About half of the human genome is repeat-derived (transposons, segmental duplications, satellites). A short read there fits several places equally well.
  • bowtie2 reports one of them at random, with MAPQ 0 or 1. Keep only MAPQ ≥ 30 (or ≥ 10–20 in some pipelines) for coverage tracks.

Real data: MAPQ on chr21

  • Two peaks: MAPQ 0–1 (22% of ChIP reads, 25% of input reads) and MAPQ 42. Little in between.
  • Filtering at MAPQ ≥ 30 keeps 76% (ChIP, 36 bp) and 74% (input, 28 bp) of the reads on chr21. Shorter reads are unique less often.

Paired-end reads and the fragment

  • A proper pair: the two reads face each other on opposite strands, at a plausible distance. TLEN = rightmost end − leftmost start + 1 = the fragment length.
  • Single-end data know only one end: the fragment length must be estimated and the reads extended.

PCR and optical duplicates

Real data: the blacklist and chrM

  • Blacklist (ENCODE exclusion list): regions with extreme signal in every experiment, input included: satellite repeats, rDNA, centromeres. 910 regions in GRCh38, 24 on chr21. Remove reads there.
  • chrM: many copies per cell, no nucleosomes. 14% of ChIP reads but 66% of input reads here; in ATAC often 20–80%. Remove before normalising.

The filtering chain, step by step

samtools view -b -q 30 -F 1804 -o chip.q30.bam chip.sorted.bam        # unique, mapped, primary
samtools markdup -s chip.q30.bam chip.markdup.bam                     # flag duplicates (1024)
samtools view -b -F 1024 -o chip.dedup.bam chip.markdup.bam chr21     # drop them, and chrM
bedtools intersect -v -abam chip.dedup.bam -b blacklist.bed > chip.final.bam

Single-end reads need extending

Real data: the two strands around CTCF sites

  • Left: 5’ ends of + strand reads peak about 50 bp left of the CTCF summits, − strand reads about 50 bp right. Median distance between them: ≈ 100 bp = the typical fragment.
  • macs3 predictd estimates the same: 100 bp. Right: reads extended to 100 bp give one peak, centred on the summits.

Coverage and normalisation: CPM and RPGC

  • Raw counts scale with sequencing depth. CPM divides by the number of reads (in millions): the same as CPM in RNA-seq.
  • RPGC (1× normalisation) scales so the genome average is 1: a value of 38.7 means 38.7 times the average coverage.
  • Both assume the total amount of signal is comparable between samples. A global change (a drug that removes a mark everywhere) breaks them: spike-ins, in Experimental design and QC.

Fold change over the input

  • The input (same chromatin, no antibody) shows local background: copy number, open chromatin, mappability, GC bias. Dividing by it removes what ChIP and input share.
  • bamCompare scales both to the same depth, then reports ratio or log2 ratio per bin, with a pseudocount to avoid dividing by zero.

Coverage tracks with deepTools

# ChIP and input, each normalised to counts per million, reads extended to 100 bp
bamCoverage -b chip.final.bam  -o chip.cpm.bw  --normalizeUsing CPM --extendReads 100 --binSize 10 -p 8
bamCoverage -b input.final.bam -o input.cpm.bw --normalizeUsing CPM --extendReads 100 --binSize 10 -p 8

# the same ChIP track as "times the average coverage" (RPGC; chr21 only, so chr21's size)
bamCoverage -b chip.final.bam -o chip.rpgc.bw --normalizeUsing RPGC \
  --effectiveGenomeSize 40088619 --extendReads 100 --binSize 10 -p 8

# ChIP over input: depth-scaled, log2 ratio in 50 bp bins, pseudocount 1
bamCompare -b1 chip.final.bam -b2 input.final.bam -o chip_vs_input.log2.bw \
  --operation log2 --scaleFactorsMethod readCount --pseudocount 1 \
  --extendReads 100 --binSize 50 -p 8

Real data: our tracks at a locus

  • Three CTCF sites at chr21:43.78–43.82 Mb. Our ChIP CPM track and ENCODE’s fold change agree on where the peaks are.
  • Our log2 ratio is noisy away from peaks: the input has only 116 000 reads on chr21, about 3 per kb. ENCODE’s track smooths the input over kilobases (MACS2 local λ).

Real data: our track against ENCODE’s

  • Mean signal in 33 287 one-kb bins on chr21 (blacklist and empty bins removed). Bins with an ENCODE peak agree well (r = 0.91); background bins much less (overall r = 0.63).
  • Same data, different tools and choices: the peaks are robust, the background depends on how you treat the input.

The shortcut used in this course

What the production pipelines do

Summary

step key fact
FASTQ quality Q = −10 log10 p; Q20 = 1% error, Q30 = 0.1%; check the offset (+33 or +64)
trimming adapters appear when the fragment is shorter than the read; fastp
alignment contiguous, no splicing: bowtie2 / BWA; seed and extend; end-to-end vs local
SAM FLAG = sum of bits (99/147, 83/163, 16, 4, 1024); POS 1-based leftmost; TLEN = fragment
MAPQ 0–1 = several equal places (repeats); keep ≥ 30; repeats become blind spots
duplicates same start (and end): PCR copies; remove for ChIP/ATAC, not RNA-seq
blacklist, chrM remove artefact regions and mitochondrial reads before normalising
coverage extend single-end reads to the fragment (~100 bp here); CPM, RPGC; ratio to input

Key papers (optional further reading)

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