\documentclass[a4paper]{article} \usepackage[margin=1in]{geometry} \setlength\parindent{0pt} \usepackage{amsmath} \usepackage{amscd} \usepackage[tableposition=top]{caption} \usepackage{ifthen} \usepackage[utf8]{inputenc} \SweaveOpts{keep.source=TRUE} %\VignetteIndexEntry{ChIP-Enrich Vignette/Tutorial} \begin{document} \title{chipenrich: A package for gene set enrichment \linebreak testing of genome region data} \author{R.P. Welch, C. Lee, R.A. Smith, P. Imbriano, S. Patil, T. Weymouth, L.J. Scott, M.A. Sartor} \maketitle \tableofcontents <>= options(width=60) @ \section {Introduction} This document describes how to use \verb@chipenrich@ to analyze results from ChIP-Seq experiments and other DNA sequencing experiments that result in a set of genomic regions. \verb@chipenrich@ includes a method that adjusts for potential confounders of gene set enrichment testing (locus length and mappability of the sequence reads.) \section {Synopsis} After starting R, the package should be loaded using the following: <>= library(chipenrich) library(chipenrich.data) @ \begin{verbatim} > library(chipenrich) \end{verbatim} This will load chipenrich, the chipenrich.data package, as well as all other dependency packages. The main function for conducting all gene set enrichment testing is \verb@chipenrich()@. \\* \linebreak The defaults for the \verb@chipenrich()@ function are \begin{verbatim} chipenrich(peaks, out_name = "chipenrich", out_path = getwd(), genome = "hg19", genesets = ('GOBP', 'GOCC', 'GOMF'), locusdef = "nearest_tss ", method = "chipenrich", fisher_alt = "two.sided", use_mappability = F, read_length = 24, genome_length = NULL, qc_plots = T) \end{verbatim} The ``\verb@peaks@'' option should be either a data frame or character vector representing the path to a file containing the peaks. The file (or data frame) should have at least 3 columns: ``chrom,'' ``start,'' and ``end,'' denoting the chromosome, starting position, and ending position of the peak. Chromosome should be in UCSC format, e.g. chrX, chrY, chr22, etc. If a file, it must be tab-delimited, and the header must exist. The input file may also be a .bed file. Additional columns can exist, so long as they do not contain tab characters. An example dataset, ``peaks\_E2F4,'' is included in the package. <>= data(peaks_E2F4) @ <>= data(peaks_E2F4) head(peaks_E2F4) @ The first task of chipenrich() is to assign the peaks to genes. Currently supported genomes include human (hg19), mouse (mm9), and rat (rn4). Data from older versions of the genome may be converted using UCSC's liftover tool: http://genome.ucsc.edu/cgi-bin/hgLiftOver. <>= supported_genomes() @ Peaks are assigned to genes according to a pre-defined locus definition, i.e. the region where peaks have to occur in order to be assigned to a gene. The following locus definitions are supported in \verb@chipenrich@: <>= supported_locusdefs() @ Using the options ``1kb'' or ``5kb'' will only assign peaks to genes if the peaks are within 1 kilobases (kb) or 5kb of a gene's transcription start site (TSS) respectively. The option ``exon'' will assign peaks to genes if the peaks occur within a gene's exons. Using ``nearest\_gene'' or ``nearest\_tss'' will assign peaks to genes according to the nearest gene or the nearest TSS. Only the ``nearest\_gene'' and ``nearest\_tss'' locus definitions retain all peaks, others use only a subset of peaks that fall within the defined region. All gene loci are non-overlapping. The command ``\verb@help(chipenrich.data)@'' may also provide more information on the locus definitions. \\* \linebreak Seventeen gene set annotation databases are supported by \verb@chipenrich@: <>= supported_genesets() @ Two methods for gene set enrichment testing are provided: the main ChIP-Enrich method (``chipenrich''), and Fisher's exact test (``fet''). While ``chipenrich'' is the main method offered, the ``fet'' method is also offered for comparison purposes and/or for use in limited situations when its assumptions are met (see examples.) <>= supported_methods() @ The default gene set database is Gene Ontology (GO) terms, comprising of all three GO branches (GOBP, GOCC, and GOMF). \\* \linebreak Accounting for mappability of reads is optional and can only be accomplished using the ChIP-Enrich method. Mappabilities for the following read lengths are available: <>= supported_read_lengths() @ Read lengths of 24mer are only available for the hg19 genome. \\* \linebreak See the section on mappability for more information on how it is calculated. \section{Locus definitions} We define a gene \textit{locus} as the region from which we predict a gene could be regulated. ChIP-seq peaks, or other types of genomic regions, falling within a locus for a gene are assigned to that gene. \\ We provide a number of different definitions of a gene locus: \begin{description} \item[nearest\_tss] The locus is the region spanning the midpoints between the TSSs of adjacent genes. \item[nearest\_gene] The locus is the region spanning the midpoints between the boundaries of each gene, where a gene is defined as the region between the furthest upstream TSS and furthest downstream TES for that gene. If two gene loci overlap each other, we take the midpoint of the overlap as the boundary between the two loci. When a gene locus is completely nested within another, we create a disjoint set of 3 intervals, where the outermost gene is separated into 2 intervals broken apart at the endpoints of the nested gene. \item[1kb] The locus is the region within 1 kb of any of the TSSs belonging to a gene. If TSSs from two adjacent genes are within 2 kb of each other, we use the midpoint between the two TSSs as the boundary for the locus for each gene. \item[5kb] The locus is the region within 5 kb of any of the TSSs belonging to a gene. If TSSs from two adjacent genes are within 10 kb of each other, we use the midpoint between the two TSSs as the boundary for the locus for each gene. \item[exons] Each gene has multiple loci corresponding to its exons. \end{description} \section{Mappability} \subsection{Base pair 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. We calculated base pair mappability for reads of lengths 24, 36, 40, 50, 75, and 100 base pairs for \textit{Homo sapiens} (build hg19) and for reads of lengths 36, 40, 50, 75, and 100 base pairs for \textit{Mus musculus} (build mm9). Mappability is unavailable for \textit{Rattus norvegicus} (build rn4) as there are no tracks available from UCSC. \subsection{Locus mappability} We define locus mappability as the average of all base pair mappability values for a gene's locus. Locus mappability is calculated for each available locus definition. \section{Examples} \subsection{Diagnostic plots} If ``qc\_plots = T'' then two pdf files will be output: One with a binomial smoothing spline fitted to the probability of a peak given gene length (this plot is only relevant to when ``method = `chipenrich'\,'') and one showing the distribution of the distance of peaks to the nearest TSS of a gene. These plots may also be generated using separate functions as illustrated below. Figure 1 shows the distribution of peaks to the nearest TSS. In figure 2, a spline is fitted to the data given gene locus length. The same is shown in figure 3 but here we account for the mappable locus length ($mappability \times locus length$). \\ \begin{figure} \begin{center} \begin{verbatim} > plot_dist_to_tss(peaks = peaks_E2F4, genome = 'hg19') \end{verbatim} <>= plot_dist_to_tss(peaks = peaks_E2F4, genome = 'hg19') @ \caption{Distribution of distance from each peak in the dataset to the nearest TSS. All peaks are considered in creating this plot, regardless of locus definition.} \end{center} \label{fig:one} \end{figure} \begin{figure} \begin{center} \begin{verbatim} > plot_spline_length(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19') \end{verbatim} <>= plot_spline_length(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19') @ \caption{The relationship between the probability of a gene being assigned a peak and locus length. In the E2F4 dataset, we can see such a relationship exists (orange), and does not match either the assumption that each gene has the same probability of a peak (dark grey horizontal line), or that the probability is proportional to locus length (light grey curve.)} \end{center} \label{fig:two} \end{figure} \begin{figure} \begin{center} \begin{verbatim} > plot_spline_length(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19', use_mappability = T, read_length = 24) \end{verbatim} <>= plot_spline_length(peaks = peaks_E2F4, locusdef = 'nearest_tss', genome = 'hg19', use_mappability = T, read_length = 24) @ \caption{Spline fit using the mappable locus length as opposed to simply the locus length of each gene. In many cases, using mappability improves the spline fit, such as for those long locus length genes with poor mappability (duplicated and/or pseudo-genes.) } \end{center} \label{fig:three} \end{figure} There are many combinations of methods, genesets, and mappabiity settings that may be used to do gene set enrichment testing using \verb@chipenrich@. In the following, we include some examples of gene set enrichment testing using the peaks\_E2F4 example dataset. \subsection{ChIP-Enrich} Gene set enrichment of Drug Bank using ChIP-Enrich: <>= results = chipenrich(peaks = peaks_E2F4, genesets = "drug_bank", locusdef = "nearest_tss", qc_plots = F, out_name = NULL) results.ce = results$results[order(results$results$P.value),] results.ce[1:5,1:5] @ \subsection{ChIP-Enrich with mappability} Gene set enrichment of KEGG pathways using ChIP-Enrich, accounting for mappability: <>= results = chipenrich(peaks = peaks_E2F4,genesets = "kegg_pathway", locusdef = "nearest_tss", use_mappability=T, read_length=24, qc_plots = F, out_name = NULL) results.cem = results$results[order(results$results$P.value),] results.cem[1:5,1:5] @ \subsection{Fisher's exact test} Fisher's Exact test assumes that each gene is equally likely to have a peak. We recommend using Fisher’s exact test with the ``1kb'' or ``5kb'' locus definitions only. This will force all genes to have approximately the same locus length and avoid returning bias results. \\ Gene set enrichment of KEGG pathways using Fisher's exact test: <>= results = chipenrich(peaks = peaks_E2F4, genesets = c("kegg_pathway"), locusdef = "5kb", method = "fet", fisher_alt = "two.sided", qc_plots = F, out_name = NULL) results.fet = results$results[order(results$results$P.value),] results.fet[1:5,1:5] @ \section {Output} The output of \verb@chipenrich()@ is an R object containing the results of the test and the peak to gene assignments. Both of these are also written to text files in the working directory (unless specified otherwised) after the test is completed. \subsection{Peak-to-gene assignments} Peak assignments are stored in \verb@$peaks@. The following is an example of how to access the peak to gene assignments in R after a gene set enrichment test has already been performed: <>= peaks_to_genes = results$peaks head(peaks_to_genes) @ \subsection{Gene set enrichment test results} The results of a \verb@chipenrich()@ R object is stored in \verb@$results@. It contains 9 columns: <>= colnames(results$results) @ \begin{description} \item[Geneset.ID] is the identifier for a given gene set from the selected database. For example, ``GO:0000003.'' \item[Geneset.Type] specifies from which database the ``\verb@Geneset.ID@'' originates. For example, ``Gene Ontology Biological Process." \item[Description] gives a definition of the``\verb@Geneset.ID@.'' For example,``reproduction." \item[P.Value] is the probability of observing the degree of enrichment (see``\verb@Odds.Ratio@") of the gene set given the null hypothesis that peaks are not associated with any gene sets. \item[FDR] is the false discovery rate proposed by Bejamini \& Hochberg for adjusting the p-value to control for family-wise error rate. \item[Odds.Ratio] is the estimated odds that peaks are associated with a given gene set compared to the odds that peaks are associated with other gene sets, after controlling for locus length and/or mappability. An odds ratio greater than 1 indicates enrichment, and less than 1 indicates depletion. \item[Status] denotes whether the gene set was enriched or depleted. \item[N.Geneset.Genes] is the number of genes in the gene set. \item[N.Geneset.Peak.Genes] is the number of genes in the genes set that were assigned at least one peak. \item[Geneset.Peak.Genes] is the list of genes from the gene set that had at least one peak assigned. \end{description} \section {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." In preparation. \end{document}