`chipenrich`: Gene Set Enrichment For ChIP-seq Peak Data

Introduction

Gene set enrichment (GSE) testing enables the interpretation of lists of differentially expressed genes (e.g. from RNA-seq), or lists of peaks (e.g. from ChIP-seq), in terms of pathways and other biologically meaningful sets of genes. The chipenrich package was originally designed to perform GSE for ChIP-seq peaks, but it can also be used for genomic regions with different biological meaning. The primary innovation of chipenrich is its accounting for biases that are known to affect the Type I error of such testing. In particular, the length of a gene's regulatory region affects the probability that a peak will be assigned to it, the number of peaks that will be assigned to it, or the proportion of it covered by peaks.

The chipenrich package includes different enrichment methods for different use cases:

Concepts and Usage

library(chipenrich)

Peaks

A ChIP-seq peak is a genomic region that represents a transcription factor binding event or the presence of a histone complex with a particular histone modification. Typically peaks are called with a peak caller (such as MACS2 or PePr) and represent relative enrichment of reads in a sample where the antibody is present versus input. Typically, peaks are output by a peak caller in BED-like format.

The primary user input for chipenrich(), broadenrich(), or polyenrich() are the peaks called from reads in a ChIP-seq experiment. Lists of genomic regions having other biological meaning can be used, but we shall continue to refer to 'peaks'. Peaks can be input as either a file path or a data.frame.

If a file path, the following formats are fully supported via their file extensions: .bed, .broadPeak, .narrowPeak, .gff3, .gff2, .gff, and .bedGraph or .bdg. BED3 through BED6 files are supported under the .bed extension (BED specification). Files without these extensions are supported under the conditions that the first 3 columns correspond to chr, start, and end and that there is either no header column, or it is commented out. Files may be compressed with gzip, and so might end in .narrowPeak.gz, for example. For files with extension support, the rtracklayer::import() function is used to read peaks, so adherence to the mentioned file formats is necessary.

If peaks are already in the R environment as a data.frame, the GenomicRanges::makeGRangesFromDataFrame() function is used to convert to a GRanges object. For the acceptable column names needed for correct interpretation, see ?GenomicRanges::makeGRangesFromDataFrame.

For the purpose of the vignette, we'll load some ChIP-seq peaks from the chipenrich.data companion package:

data(peaks_E2F4, package = 'chipenrich.data')
data(peaks_H3K4me3_GM12878, package = 'chipenrich.data')

head(peaks_E2F4)
head(peaks_H3K4me3_GM12878)

Genomes

Genomes for fly, human, mouse, rat, and zebrafish are supported. Particular supported genome builds are given by:

supported_genomes()

Locus Definitions

A locus definition is a way of defining a gene regulatory region, and enables us to associate peaks with genes. The terms 'gene', 'gene regulatory region', and 'gene locus' are used interchangeably in the vignette. A trivial locus definition might be the gene bodies from the transcription start sites (TSS) to the transcript end sites (TES) for each gene. A locus definition can also express how one expects a transcription factor to regulate genes. For example, a locus definition defined as 1kb upstream and downstream of a TSS (the 1kb definition) would capture TFs binding in proximal-promoter regions.

Built-in locus definitions

A number of locus definitions representing different regulatory paradigms are included in the package:

The complete listing of genome build and locus definition pairs can be listed with supported_locusdefs():

# Take head because it's long
head(supported_locusdefs())

Custom locus definitions

Users can create custom locus definitions for any of the supported_genomes(), and pass the file path as the value of the locusdef parameter in broadenrich(), chipenrich(), or polyenrich(). Custom locus definitions should be defined in a tab-delimited text file with column names chr, start, end, and gene_id. For example:

chr start   end geneid
chr1    839460  839610  148398
chr1    840040  840190  148398
chr1    840040  840190  57801
chr1    840800  840950  148398
chr1    841160  841310  148398

Selecting a locus definition

For a transcription factor ChIP-seq experiment, selecting a particular locus definition for use in enrichment testing implies how the TF is assumed to regulate genes. For example, selecting the 1kb locus definition will imply that the biological processes found enriched are a result of TF regulation near the promoter. In contrast, selecting the 5kb_outside locus definition will imply that the biological processes found enriched are a result of TF regulation distal from the promoter.

Selecting a locus definition can also help reduce the noise in the enrichment tests. For example, if a TF is known to primarily regulate genes by binding around the promoter, then selecting the 1kb locus definition can help to reduce the noise from TSS-distal peaks in the enrichment testing.

The plot_dist_to_tss() QC plot displays where peak midpoints fall relative to TSSs genome-wide, and can help inform the choice of locus definition. For example, if many peaks fall far from the TSS, the nearest_tss locus definition may be a good choice because it will capture all peaks, whereas the 1kb locus definition may not capture many of the peaks and adversely affect the enrichment testing.

Gene Sets

Gene sets are sets of genes that represent a particular biological function.

Built-in gene sets

Gene sets for fly, human, mouse, rat, and zebrafish are built in to chipenrich. Some organisms have gene sets that others do not, so check with:

# Take head because it's long
head(supported_genesets())

Descriptions of our built-in gene sets:

Custom gene sets

Users can perform GSE on custom gene sets for any supported organism by passing the file path as the value of genesets parameter in broadenrich(), chipenrich(), polyenrich(), or hybridenrich(). Custom gene set definitions should be defined in a tab-delimited text file with a header. The first column should be the geneset ID or name, and the second column should be the Entrez IDs belonging to the geneset. For example:

gs_id   gene_id
GO:0006631  30
GO:0006631  31
GO:0006631  32
GO:0006631  33
GO:0006631  34
GO:0006631  35
GO:0006631  36
GO:0006631  37
GO:0006631  51
GO:0006631  131
GO:0006631  183
GO:0006631  207
GO:0006631  208
GO:0006631  215
GO:0006631  225

Mappability

We define base pair mappability as the average read mappability of all possible reads of size K that encompass a specific base pair location, $b$. Mappability files from UCSC Genome Browser mappability track were used to calculate base pair mappability. The mappability track provides values for theoretical read mappability, or the number of places in the genome that could be mapped by a read that begins with the base pair location $b$. For example, a value of 1 indicates a Kmer read beginning at $b$ is mappable to one area in the genome. A value of 0.5 indicates a Kmer read beginning at $b$ is mappable to two areas in the genome. For our purposes, we are only interested in uniquely mappable reads; therefore, all reads with mappability less than 1 were set to 0 to indicate non-unique mappability. Then, base pair mappability is calculated as:

$$ \begin{equation} M_{i} = (\frac{1}{2K-1}) \sum_{j=i-K+1}^{i+(K-1)} M_{j} \end{equation} $$

where $M_{i}$ is the mappability of base pair $i$, and $M_{j}$ is mappability (from UCSC's mappability track) of read $j$ where j is the start position of the K length read.

Built-in mappability

Base pair mappability for reads of lengths 24, 36, 40, 50, 75, and 100 base pairs for hg19 and for reads of lengths 36, 40, 50, 75, and 100 base pairs mm9 a included. See the complete list with:

# Take head because it's long
head(supported_read_lengths())

Custom mappability

Users can use custom mappability with any built-in locus definition (if, for example, the read length needed is not present), or with a custom locus definition. Custom mappability should be defined in a tab-delimited text file with columns named gene_id and mappa. Gene IDs should be Entrez Gene IDs, and mappability should be in [0,1]. A check is performed to verify that the gene IDs in the locus definition and mappability overlap by at least 95\%. An example custom mappability file looks like:

mappa   gene_id
0.8 8487
0.1 84
0.6 91
1   1000

Testing for enrichment

As stated in the introduction, the chipenrich package includes three classes of methods for doing GSE testing. For each method, we describe the intended use case, the model used for enrichment, and an example using the method.

broadenrich()

Broad-Enrich is designed for use with broad peaks that may intersect multiple gene loci, and cumulatively cover greater than 5\% of the genome. For example, ChIP-seq experiments for histone modifications.

The Broad-Enrich method uses the cumulative peak coverage of genes in its logistic regression model for enrichment: GO ~ ratio + s(log10_length). Here, GO is a binary vector indicating whether a gene is in the gene set being tested, ratio is a numeric vector indicating the ratio of the gene covered by peaks, and s(log10_length) is a binomial cubic smoothing spline which adjusts for the relationship between gene coverage and locus length.

gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = broadenrich(peaks = peaks_H3K4me3_GM12878, genome = 'hg19', genesets = gs_path,
    locusdef = "nearest_tss", qc_plots = FALSE, out_name = NULL, n_cores=1)
results.be = results$results
print(results.be[1:5,1:5])

chipenrich()

ChIP-Enrich is designed for use with 1,000s or 10,000s of narrow peaks which results in fewer gene loci containing a peak overall. For example, ChIP-seq experiments for transcription factors.

The ChIP-Enrich method uses the presence of a peak in its logistic regression model for enrichment: peak ~ GO + s(log10_length). Here, GO is a binary vector indicating whether a gene is in the gene set being tested, peak is a binary vector indicating the presence of a peak in a gene, and s(log10_length) is a binomial cubic smoothing spline which adjusts for the relationship between the presence of a peak and locus length.

# Without mappability
gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = chipenrich(peaks = peaks_E2F4, genome = 'hg19', genesets = gs_path,
    locusdef = "nearest_tss", qc_plots = FALSE, out_name = NULL, n_cores = 1)
results.ce = results$results
print(results.ce[1:5,1:5])
# With mappability
gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = chipenrich(peaks = peaks_E2F4, genome = 'hg19', genesets = gs_path,
    locusdef = "nearest_tss", mappability=24, qc_plots = FALSE,
    out_name = NULL,n_cores=1)
results.cem = results$results
print(results.cem[1:5,1:5])

polyenrich()

Poly-Enrich is also designed for narrow peaks, for experiments with 100,000s of peaks, or in cases where the number of binding sites per gene affects its regulation. If unsure whether to use chipenrich or polyenrich, then we recommend hybridenrich.

The Poly-Enrich method uses the number of peaks in genes in its negative binomial regression model for enrichment: num_peaks ~ GO + s(log10_length). Here, GO is a binary vector indicating whether a gene is in the gene set being tested, num_peaks is a numeric vector indicating the number of peaks in each gene, and s(log10_length) is a negative binomial cubic smoothing spline which adjusts for the relationship between the number of peaks in a gene and locus length.

gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = polyenrich(peaks = peaks_E2F4, genome = 'hg19', genesets = gs_path,  method = 'polyenrich',
    locusdef = "nearest_tss", qc_plots = FALSE, out_name = NULL, n_cores = 1)
results.pe = results$results
print(results.pe[1:5,1:5])

hybridenrich()

The hybrid method is used when one is unsure of which method, between ChIP-Enrich or Poly-Enrich, is the optimal method. It will be more conservative than either test for an individual gene set, but is usually more powerful overall.

The hybrid p-value is given as 2*min(chipenrich_pvalue, polyenrich_pvalue). This test will retain the same Type 1 level and will be a consistent test if one of chipenrich or polyenrich is consistent. This can be extended to any number of tests, but currently we only allow a hybrid test for chipenrich and polyenrich. For more information about chipenrich or polyenrich, see their respective sections.

gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = hybridenrich(peaks = peaks_E2F4, genome = 'hg19', genesets = gs_path,
    locusdef = "nearest_tss", qc_plots = F, out_name = NULL, n_cores = 1)
results.hybrid = results$results
print(results.hybrid[1:5,1:5])

proxReg()

The proximity to regulatory regions (proxReg) test is a complementary test to any gene set enrichment test on a set of genomic regions, not just exclusive to the methods in this package. It tests if the genomic regions tend to be closer to (or farther from) gene transcription start sites or enhancer regions in each gene set tested. Currently, testing proximity to enhancer regions is only compatible with the hg19 genome. The purpose of ProxReg is to provide additional information for interpreting gene set enrichment test results, as a gene set enrichment test alone does not give information about whether the genomic regions occur near promoter or enhancer regions.

ProxReg first calculates the distance between the midpoints of peaks and the nearest transcription start site or the nearest enhancer region midpoint for each genomic region. Each genomic region is then assigned to the gene with the nearest transcription start site. The distances are then classified according to whether the gene is in the gene set or not, and a signed Wilcoxon rank-sum test is used to calculate if the regions are closer or farther in the gene set than average.

gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results.prox = proxReg(peaks_E2F4, reglocation = 'tss',
            genome = 'hg19', genesets=gs_path, out_name=NULL)
results.prox = results$results
print(results.prox[1:5,1:5])

QC Plots

Each enrich function outputs QC plots if qc_plots = TRUE. There are also stand-alone functions to make the QC plots without the need for GSE testing. The QC plots can be used to help determine which locus definition to use, or which enrichment method is more appropriate.

Peak distance to TSS distribution

This plot gives a distribution of the distance of the peak midpoints to the TSSs. It can help in selecting a locus definition. For example, if genes are primarily within 5kb of TSSs, then the 5kb locus definition may be a good choice. In contrast, if most genes fall far from TSSs, the nearest_tss locus definition may be a good choice.

# Output in chipenrich and polyenrich
plot_dist_to_tss(peaks = peaks_E2F4, genome = 'hg19')

Presence of peak versus locus length

This plot visualizes the relationship between the presence of at least one peak in a gene locus and the locus length (on the log10 scale). For clarity of visualization, each point represents 25 gene loci binned after sorting by locus length. The expected fit under the assumptions of Fisher's Exact Test (horizontal line), and a binomial-based test (gray curve) are displayed to indicate how the dataset being enriched conforms to the assumption of each. The empirical spline used in the chipenrich method is in orange.

# Output in chipenrich
plot_chipenrich_spline(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19')

Number of peaks versus locus length

This plot visualizes the relationship between the number of peaks assigned to a gene and the locus length (on the log10 scale). For clarity of visualization, each point represents 25 gene loci binned after sorting by locus length. The empirical spline used in the polyenrich method is in orange.

If many gene loci have multiple peaks assigned to them, polyenrich is likely an appropriate method. If there are a low number of peaks per gene, then chipenrich() may be the appropriate method.

# Output in polyenrich
plot_polyenrich_spline(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19')

Gene coverage versus locus length

This plot visualizes the relationship between proportion of the gene locus covered by peaks and the locus length (on the log10 scale). For clarity of visualization, each point represents 25 gene loci binned after sorting by locus length.

# Output in broadenrich
plot_gene_coverage(peaks = peaks_H3K4me3_GM12878, locusdef = 'nearest_tss',  genome = 'hg19')

Output

The output of broadenrich(), chipenrich(), and polyenrich() is a list with components corresponding to each section below. If out_name is not NULL, then a file for each component will be written to the out_path with prefixes of out_name.

Assigned peaks

Peak assignments are stored in $peaks. This is a peak-level summary. Each line corresponds to a peak intersecting a particular gene locus defined in the selected locus definition. In the case of broadenrich() peaks may be assigned to multiple gene loci. Doing table() on the peak_id column will indicate how many genes are assigned to each peak.

head(results$peaks)

Peaks-per-gene

Peak information aggregated over gene loci is stored in $peaks_per_gene. This is a gene-level summary. Each line corresponds to aggregated peak information over the gene_id such as the number of peaks assigned to the gene locus or the ratio of the gene locus covered in the case of broadenrich().

head(results$peaks_per_gene)

Gene set enrichment results

GSE results are stored in $results. For convenience, gene set descriptions are provided in addition to the gene set ID (which is the same as the ID from the originating database). The Status column takes values of enriched if the Effect is > 0 and depleted if \< 0, with enriched results being of primary importance. Finally, the Geneset.Peak.Genes column gives a list of gene IDs that had signal contributing to the test for enrichment. This list can be used to cross reference information from $peaks or $peaks_per_gene if desired.

head(results$results)

Assessing Type I Error with Randomizations

Randomization of locus definitions allows for the assessment of Type I Error under the null hypothesis of no true gene set enrichment. A well-calibrated Type I Error means that the false positive rate is controlled, and the p-values reported for actual data can be trusted. In both Welch & Lee, et al. and Cavalcante, et al., we demonstrated that both chipenrich() and broadenrich() have well-calibrated Type I Error over dozens of publicly available ENCODE ChIP-seq datasets. Unpublished data suggests the same is true for polyenrich().

Within chipenrich(), broadenrich(), and polyenrich(), the randomization parameters can be used to assess the Type I Error for the data being analyzed.

The randomization codes, and their effects are:

The return value of chipenrich(), broadenrich(), or polyenrich() with a selected randomization is the same list object described above. To assess the Type I error, the alpha level for the particular data set can be calculated by dividing the total number of gene sets with p-value < alpha by the total number of tests tested. Users may want to perform multiple randomizations for a set of peaks and take the median of the alpha values.

# Assessing if alpha = 0.05
gs_path = system.file('extdata','vignette_genesets.txt', package='chipenrich')
results = chipenrich(peaks = peaks_E2F4, genome = 'hg19', genesets = gs_path,
    locusdef = "nearest_tss", qc_plots = FALSE, randomization = 'complete',
    out_name = NULL, n_cores = 1)
alpha = sum(results$results$P.value < 0.05) / nrow(results$results)
# NOTE: This is for
print(alpha)

References

R.P. Welch^, C. Lee^, R.A. Smith, P. Imbriano, S. Patil, T. Weymouth, L.J. Scott, M.A. Sartor. "ChIP-Enrich: gene set enrichment testing for ChIP-seq data." Nucl. Acids Res. (2014) 42(13):e105. doi:10.1093/nar/gku463

R.G. Cavalcante, C. Lee, R.P. Welch, S. Patil, T. Weymouth, L.J. Scott, and M.A. Sartor. "Broad-Enrich: functional interpretation of large sets of broad genomic regions." Bioinformatics (2014) 30(17):i393-i400 doi:10.1093/bioinformatics/btu444

C.T. Lee , R.G. Cavalcante, C. Lee, T. Qin, S. Patil, S. Wang, Z. Tsai, A.P. Boyle, M.A. Sartor. “Poly-Enrich: Count-based Methods for Gene Set Enrichment Testing with Genomic Regions.” In review.

C.T. Lee, K. Wang, T. Qin, M.A. Sartor. "Testing proximity of genomic regions to transcription start sites and enhancers complements gene set enrichment testing." In preparation.



Try the chipenrich package in your browser

Any scripts or data that you put into this service are public.

chipenrich documentation built on Nov. 8, 2020, 8:11 p.m.