Skip to content

Peaks, promoters, and nearby genes

A nearby gene gives an accessible region a useful annotation, but distance does not establish regulation. This lesson reports promoter overlaps and nearest transcription start sites separately, retaining every tied gene instead of selecting the first name in an annotation file.

State the coordinate and promoter definitions

Section titled “State the coordinate and promoter definitions”

The gene table comes from GENCODE v19 nuclear gene records on GRCh37/hg19. It preserves versioned Ensembl gene identifiers alongside gene names. Each gene contributes its annotated gene start on the positive strand or gene end on the negative strand. This is a gene-level TSS definition; it does not represent every alternative transcript start.

All stored intervals use zero-based starts and exclusive ends. The TSS itself is a single base. The promoter includes that base, 2,000 bases upstream, and 500 bases downstream along the gene’s strand, clipped at chromosome bounds. Thus an unclipped promoter contains 2,501 bases. The R example adds one to BED starts when it constructs inclusive GRanges intervals.

Nearest-TSS distance uses the lower integer midpoint of each peak and the genomic TSS base. Positive signed distance means that midpoint lies downstream along the gene’s strand. The calculation selects genes by absolute distance and retains all ties. A peak can overlap one gene’s promoter while its midpoint lies closer to another gene’s TSS.

Both examples use the same autosomal, blacklist-free regions and count filter as the count lesson. They annotate the entire tested universe before choosing a particular differential result. R uses interval overlap operations for promoters. Python uses the ordered, nonoverlapping consensus intervals to find the same overlaps.

The original experiment comes from Calderon and colleagues, deposited as GSE118189, SRP156496, and PRJNA484801. The companion workflow generates these analysis inputs from eight public read runs covered by the INSDC use policy. The source notice identifies those runs, the GENCODE v19 annotation, the UCSC/NCBI reference, and the Boyle Lab blacklist. It records the source grants and the transformations applied to the inputs.

library(GenomicRanges)
library(jsonlite)
#' Find all genes tied at the nearest TSS on one chromosome.
#'
#' @param peaks A data frame with region identifiers and BED intervals.
#' @param genes A data frame with gene identifiers and zero-based TSS bases.
#' @return A data frame with all nearest gene assignments.
NearestTss <- function(peaks, genes) {
positions <- sort(unique(genes$tss_start))
midpoint <- floor((peaks$start + peaks$end - 1) / 2)
left_index <- findInterval(midpoint, positions)
left <- positions[pmax(1, left_index)]
right <- positions[pmin(length(positions), left_index + 1)]
minimum <- pmin(abs(midpoint - left), abs(midpoint - right))
left_rows <- abs(midpoint - left) == minimum
right_rows <- abs(midpoint - right) == minimum & right != left
matches <- rbind(
data.frame(region_id = peaks$region_id[left_rows],
midpoint = midpoint[left_rows], tss_start = left[left_rows]),
data.frame(region_id = peaks$region_id[right_rows],
midpoint = midpoint[right_rows], tss_start = right[right_rows])
)
result <- merge(matches, genes, by = "tss_start")
direction <- ifelse(result$strand == "+", 1, -1)
result$distance_bp <- (result$midpoint - result$tss_start) * direction
result[, c("region_id", "gene_id", "gene_name", "chrom", "strand",
"tss_start", "distance_bp")]
}
regions <- read.delim("/fixtures/regions.tsv")
counts <- read.delim(gzfile("/fixtures/counts.tsv.gz"), row.names = 1,
check.names = FALSE)
stopifnot(identical(rownames(counts), regions$region_id))
retained <- regions$autosomal & !regions$blacklist_overlap &
rowSums(counts >= 10L) >= 4L
peaks <- regions[retained, c("region_id", "chrom", "start", "end")]
genes <- read.delim("/fixtures/genes.tsv", check.names = FALSE)
genes <- genes[genes$chrom %in% paste0("chr", 1:22), ]
sizes <- read.delim("/fixtures/chrom_sizes.tsv", header = FALSE,
col.names = c("chrom", "length"))
chromosome_length <- sizes$length[match(genes$chrom, sizes$chrom)]
promoter_start <- pmax(0, genes$tss_start -
ifelse(genes$strand == "+", 2000, 500))
promoter_end <- pmin(chromosome_length, genes$tss_start +
ifelse(genes$strand == "+", 501, 2001))
peak_ranges <- GRanges(peaks$chrom, IRanges(peaks$start + 1L, peaks$end))
promoters <- GRanges(genes$chrom, IRanges(promoter_start + 1L, promoter_end))
overlaps <- findOverlaps(peak_ranges, promoters, ignore.strand = TRUE)
promoter_pairs <- data.frame(
region_id = peaks$region_id[queryHits(overlaps)],
gene_id = genes$gene_id[subjectHits(overlaps)]
)
promoter_pairs <- promoter_pairs[order(promoter_pairs$region_id,
promoter_pairs$gene_id), ]
nearest_parts <- list()
for (chromosome in paste0("chr", 1:22)) {
chromosome_peaks <- peaks[peaks$chrom == chromosome, ]
chromosome_genes <- genes[genes$chrom == chromosome, ]
if (nrow(chromosome_peaks) > 0L) {
stopifnot(nrow(chromosome_genes) > 0L)
nearest_parts[[chromosome]] <- NearestTss(chromosome_peaks,
chromosome_genes)
}
}
nearest <- do.call(rbind, nearest_parts)
nearest <- nearest[order(nearest$region_id, nearest$gene_id), ]
stopifnot(setequal(nearest$region_id, peaks$region_id))
nearest_counts <- table(nearest$region_id)
promoter_counts <- table(factor(promoter_pairs$region_id,
levels = peaks$region_id))
distances <- abs(nearest$distance_bp[!duplicated(nearest$region_id)])
cat(sprintf("Tested regions: %d; promoter overlaps: %d\n",
nrow(peaks), nrow(promoter_pairs)))
cat(sprintf("Regions with a promoter: %d; with multiple promoters: %d\n",
sum(promoter_counts > 0L), sum(promoter_counts > 1L)))
cat(sprintf("Regions with tied nearest genes: %d\n",
sum(nearest_counts > 1L)))
cat(sprintf("Median absolute midpoint-to-TSS distance: %.1f bp\n",
median(distances)))
dir.create("outputs", showWarnings = FALSE)
write.table(nearest, "outputs/nearest_tss_r.tsv", sep = "\t",
row.names = FALSE, quote = FALSE)
write.table(promoter_pairs, "outputs/promoter_pairs_r.tsv", sep = "\t",
row.names = FALSE, quote = FALSE)
write_json(list(regions = nrow(peaks), promoter_pairs = nrow(promoter_pairs),
promoter_regions = sum(promoter_counts > 0L),
tied_nearest = sum(nearest_counts > 1L),
median_distance = median(distances)),
"outputs/metrics_r.json", auto_unbox = TRUE, digits = 16)
png("outputs/peak_annotation_r.png", width = 1400, height = 650, res = 160)
par(mfrow = c(1, 2), mar = c(4.5, 4.5, 1.5, 1))
plot(ecdf(log10(distances + 1)), verticals = TRUE, do.points = FALSE,
xlab = "log10 absolute TSS distance + 1", ylab = "Fraction of regions",
main = "", col = "#287d8e", lwd = 2)
categories <- c(sum(promoter_counts == 0L), sum(promoter_counts == 1L),
sum(promoter_counts > 1L))
barplot(categories, names.arg = c("None", "One", "Multiple"),
col = "#87b9c1", xlab = "Overlapping gene promoters",
ylab = "Number of regions")
invisible(dev.off())
Tested regions: 48292; promoter overlaps: 18286
Regions with a promoter: 14022; with multiple promoters: 3734
Regions with tied nearest genes: 83
Median absolute midpoint-to-TSS distance: 8222.5 bp

The plots show nearest-TSS distances and promoter ambiguity.

The completed annotation contains 83 regions with tied nearest genes and 3,734 regions that overlap more than one promoter within the 48,292 tested regions. The exported tables preserve these observed ambiguities.

The promoter table can contain several genes for one region. The nearest-TSS table can also contain several genes, including genes that share a TSS base or lie at equal distances on opposite sides of the midpoint. Neither table should become a unique gene label through an arbitrary first-row choice.

A distal accessible region may regulate a gene beyond its nearest neighbor, and proximity does not show whether expression changes in this experiment. Chromatin contact data, expression measurements, and perturbation experiments answer different parts of that question. The visualization lesson displays paired counts and genomic coverage without assigning a regulatory target.

The GENCODE release 19 record identifies the GRCh37.p13 annotation used here. Reference and annotation coordinates must agree before assigning a peak to a gene.

The GenomicRanges 1.64.0 source package contains the GRanges and overlap method references. Their inclusive intervals explain the conversion from BED coordinates.