Where does a protein bind, relative to genes? This lesson reads real peak files, annotates every peak with ChIPseeker, and shows how much the answer depends on what you call a promoter.
This lesson follows Genomic ranges with Bioconductor.
What a peak is
ChIP-seq (chromatin immunoprecipitation followed by sequencing) finds where a protein sits on the genome. Cells are treated so that proteins stick to the DNA they are touching, the DNA is broken into short fragments, and an antibody against the protein of interest pulls out the fragments it is bound to. Those fragments are sequenced and aligned. Where the protein was bound, reads pile up; elsewhere they are sparse.
A peak caller turns those pile-ups into a list of regions. The most widely used is MACS (Model-based Analysis of ChIP-Seq), now in its second and third versions, MACS2 and MACS3. It compares the read density in the ChIP sample with a control, usually "input" DNA that went through the same steps without the antibody, and reports regions where the ChIP has many more reads than expected. Each such region is a peak.
MACS2 writes several files. The main one for sharp, point-like binding is NAME_peaks.narrowPeak, a BED-like file with ten tab-separated columns:
- columns 1–3: chromosome, start and end, with 0-based starts as in any BED file;
- column 4: a peak name; column 5: an integer score used for display; column 6: strand, usually .;
- column 7: the fold enrichment at the peak summit, how many times more reads than expected;
- columns 8 and 9: the p-value and q-value, written as −log10, so 5 means 10−5;
- column 10: the position of the summit, the highest point of the pile-up, counted from the peak start.
MACS2 also writes NAME_summits.bed (one base per summit) and a table, NAME_peaks.xls, which despite its name is plain text. For broad marks, such as histone modifications that spread over many kilobases, --broad mode writes a broadPeak file instead. Peak calling itself is done at the command line, outside R; this lesson starts from its output.
The ChIPseeker sample files
ChIPseeker, the Bioconductor package for annotating peaks, includes five peak files from public experiments, all on the hg19 build. They must therefore be annotated with hg19 gene models, not the hg38 models used in Genomic ranges with Bioconductor. This lesson uses two: peaks for CBX6 and CBX7, two members of the Polycomb family of proteins, which keep developmental genes switched off.
library(ChIPseeker) library(GenomicRanges) files <- getSampleFiles() names(files) basename(files[[5]]) readLines(gzfile(files[[5]]), n = 3) cbx7 <- readPeakFile(files[[5]]) cbx6 <- readPeakFile(files[[4]]) cbx7 length(cbx6) summary(width(cbx7))
What this does
getSampleFiles()returns the paths of the five files, named by experiment: three named ARmo, at 0, 1 nM and 100 nM of a treatment, and the two Polycomb files. The file name of the CBX7 file starts with its GEO accession, GSM1295077, so you can look up how it was made.readLines(gzfile(...))reads the first lines of the compressed file without unpacking it. These are not narrowPeak files: they have five columns (chromosome, start, end, a name such as MACS_peak_1, and a score). The names show MACS called the peaks, and "mergedReps" in the file name suggests the replicates were combined. Always look inside a peak file before trusting its format.readPeakFile()reads it into aGRanges. The first peak starts at 815462 in the file and at 815463 in R: the BED start was converted, as withimport(). Columns without a header becomeV4andV5.- There are 1,663 CBX7 peaks and 1,331 CBX6 peaks. Their widths range from 465 to 27,194 bases, with a median of 1,781: broader than a typical transcription factor peak, as expected for Polycomb proteins, which cover stretches of chromatin.
The seqinfo says "unspecified genome". The file does not record its build; the ChIPseeker documentation does. That is why it matters to know where a peak file came from.
Annotating peaks
A peak on its own is just coordinates. Annotation says where each peak lies relative to genes: at a promoter, in an exon or intron, downstream of a gene, or far from any gene (distal intergenic). annotatePeak() does this for every peak, using a TxDb for the gene models and, optionally, an org database for gene names.
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(org.Hs.eg.db)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
anno7 <- annotatePeak(cbx7, tssRegion = c(-3000, 3000),
TxDb = txdb, annoDb = "org.Hs.eg.db")
anno7
anno_df <- as.data.frame(anno7)
head(anno_df[, c("seqnames", "start", "end", "annotation", "distanceToTSS", "SYMBOL")])What this does
tssRegion = c(-3000, 3000)defines a promoter as 3,000 bases either side of a TSS. A peak touching that window is called a promoter peak, and split into ≤1 kb, 1–2 kb and 2–3 kb from the TSS.- The summary gives the percentage of peaks in each category. Each peak gets one category, by a priority order: promoter first, then 5′ UTR, 3′ UTR, exon, intron, downstream, and distal intergenic last. A peak at a promoter of one gene and inside an intron of another is called a promoter peak.
as.data.frame()turns the result into a table with one row per peak and the annotation columns added: the category, the nearest gene's coordinates and ID,distanceToTSS, and, fromannoDb, its Ensembl ID, symbol and full name.distanceToTSSis the distance from the peak to the TSS of the nearest gene, taking the gene's strand into account: negative means upstream, positive downstream, and 0 means the peak covers the TSS.
Two rows in the head are worth a second look. Peak 1 is 3,281 bases upstream of FAM41C, just outside the ±3 kb window, so it is distal intergenic even though a gene is nearby. Peak 6 is in the first exon of a transcript, yet its nearest TSS is 13,273 bases away. The two kinds of annotation answer different questions. The category comes from what the peak overlaps among all transcripts; the gene and distance come from the nearest TSS. They need not agree.
The UCSC known-gene models list many transcripts per gene, each with its own TSS. A peak counts as a promoter peak if it is near any of them, which is one reason promoter percentages from different annotations differ.
Categories and distances, in numbers and pictures
anno_df$category <- sub(" \\(.*", "", anno_df$annotation)
sort(table(anno_df$category), decreasing = TRUE)
mean(abs(anno_df$distanceToTSS) <= 1000)
mean(abs(anno_df$distanceToTSS) <= 3000)
median(abs(anno_df$distanceToTSS))
plotAnnoBar(anno7)
plotDistToTSS(anno7, title = "CBX7 peaks: distance to TSS")
library(ggplot2)
anno_df$dist_kb <- pmax(pmin(anno_df$distanceToTSS / 1000, 50), -50)
ggplot(anno_df, aes(x = dist_kb)) +
geom_histogram(binwidth = 1, fill = "#0072B2") +
labs(x = "Distance to nearest TSS (kb, capped at ±50)", y = "Peaks") +
theme_classic()What this does
sub(" \\(.*", "", ...)deletes everything from the first space-and-bracket onwards, so "Promoter (<=1kb)" and "Exon (uc021ogr.1/…)" become "Promoter" and "Exon". Thentable()counts each category.- The two
mean()lines give the share of peaks within 1 kb and within 3 kb of a TSS: 44% and 53%. The median distance is 2,056 bases. plotAnnoBar()draws one horizontal bar split into the categories.plotDistToTSS()draws the share of peaks in distance bands (0–1 kb, 1–3 kb, 3–5 kb and so on) upstream and downstream of the TSS.- The ggplot2 histogram shows the same distances directly, in 1 kb bins.
pmin()andpmax()cap them at ±50 kb so a few far-off peaks do not stretch the axis; say so in the axis label, as here.
Over half of the CBX7 peaks lie within 3 kb of a TSS, and 889 of 1,663 are promoter peaks. In the run for this lesson, the distance plot showed a large central block of peaks within 1 kb of the TSS on both sides, and a long tail of peaks 10–100 kb away. That is the pattern you would expect for Polycomb proteins, which bind the CpG-rich promoters of the genes they silence. Is 53% a lot? It depends on the comparison. Promoters within 3 kb of a TSS cover only a few per cent of the genome, so a set of randomly placed peaks would have far fewer. The project at the end of this module tests a comparison of this kind directly.
Worked example · from counts to the summary table
The summary reports promoter peaks in three bands. Do they add up to the 889 promoter peaks in the table?
total promoter share = 43.90 + 5.89 + 3.67 = 53.46%
53.46% × 1,663 peaks = 889 promoter peaks
check: mean(|distanceToTSS| ≤ 3000) = 0.5346 → 0.5346 × 1,663 = 889
Step by step. The three promoter bands add to 53.46% of 1,663 peaks, which is 889, matching the table. The share of peaks within 3 kb of the nearest TSS is also 53.46%. Likewise, the ≤1 kb band, 43.90%, equals the share within 1 kb, 0.4390.
What the answer means. Here the category and the distance agree, which is a useful check that you are reading the columns correctly. It also shows that "promoter" in ChIPseeker means "within your tssRegion of a TSS", nothing more.
Two samples, and what "promoter" means
CBX6 and CBX7 belong to the same protein family. Do they bind the same places? With ranges, that is an overlap question.
anno6 <- annotatePeak(cbx6, tssRegion = c(-3000, 3000), TxDb = txdb,
annoDb = "org.Hs.eg.db", verbose = FALSE)
shared <- subsetByOverlaps(cbx7, cbx6)
length(shared)
length(shared) / length(cbx7)
sum(overlapsAny(cbx6, cbx7)) / length(cbx6)
genes7 <- unique(anno_df$geneId[abs(anno_df$distanceToTSS) <= 1000])
df6 <- as.data.frame(anno6)
genes6 <- unique(df6$geneId[abs(df6$distanceToTSS) <= 1000])
length(genes7); length(genes6); length(intersect(genes7, genes6))851 CBX7 peaks, 51%, overlap a CBX6 peak, and 72% of CBX6 peaks overlap a CBX7 peak. The two percentages differ because the sets differ in size and a peak in one set can overlap several in the other. Report both, or say which direction you mean. At the gene level, 654 genes have a CBX7 peak within 1 kb of their TSS, 585 have a CBX6 peak, and 397 have both. overlapsAny() returns TRUE or FALSE for each query range, so its sum counts the ranges with at least one overlap.
Now change only the promoter definition.
anno7b <- annotatePeak(cbx7, tssRegion = c(-1000, 1000), TxDb = txdb, verbose = FALSE) anno7b
With ±1 kb, promoter peaks fall from 53.5% to 43.9% of the total. The 1–3 kb peaks have not vanished: they are now counted as introns, exons, UTRs or distal intergenic, which rises from 31.3% to 34.6%. The data did not change; the definition did. Papers use ±1 kb, ±2 kb, ±3 kb, −2 kb to +500 bases and more, so "half the peaks are at promoters" means little until the window is stated.
Common mistakes
- Annotating with the wrong build. These files are hg19; annotating them with an hg38 TxDb gives wrong genes and no error, because the peak file records no build.
- Not stating the promoter window. Report
tssRegionwith every promoter percentage. - Reading "nearest gene" as "target gene". The nearest TSS is a convenient label. Enhancers can act on genes hundreds of kilobases away, skipping nearer ones.
- Comparing peak counts between samples as if they were measurements. The number of peaks depends on sequencing depth, antibody quality and the caller's thresholds as much as on biology.
Go deeper: overlap is not the same as co-binding
Two peaks that overlap by one base count as overlapping. With peaks several kilobases wide, as here, that is a generous test, and two broad peak sets will overlap more than two sets of narrow transcription-factor peaks would. Options include requiring a minimum overlap (minoverlap in findOverlaps()), comparing summits rather than whole peaks, or using a method that compares read counts at a common set of regions, such as the DiffBind package. Whatever you choose, compare the observed overlap with what chance would give: a shuffled set of peaks of the same widths on the same chromosomes is the usual reference, and the project at the end of this module builds one.
ChIPseeker is described in Yu, Wang & He 2015, "ChIPseeker: an R/Bioconductor package for ChIP peak annotation, comparison and visualization" (Bioinformatics), with an update in Wang et al. 2022 (Current Protocols). MACS is described in Zhang et al. 2008, "Model-based Analysis of ChIP-Seq (MACS)" (Genome Biology). The ENCODE guidelines for ChIP-seq experiments, including controls and replicates, are in Landt et al. 2012 (Genome Research). When reporting, give the peak caller and its settings, the genome build, the TxDb version and the tssRegion.
Further reading · Module 7Yu, Wang & He 2015: ChIPseeker and its annotation rules. · All reading for this course
Check your understanding
1. The ChIPseeker sample peak files are on hg19. Which gene models should you annotate them with?
2. Changing tssRegion from ±3 kb to ±1 kb lowered the CBX7 promoter share from 53.5% to 43.9%. What happened to the other peaks?
3. 51% of CBX7 peaks overlap a CBX6 peak, but 72% of CBX6 peaks overlap a CBX7 peak. Why do the two differ?