% \VignetteEngine{knitr} % \VignetteIndexEntry{ChIPseeker: an R package for ChIP peak Annotation, Comparison, and Visualization} % \VignettePackage{ChIPseeker} % \VignetteDepends{clusterProfiler} % \VignetteDepends{org.Hs.eg.db} % To compile this document, run the commands within R % require(knitr); knit2pdf("ChIPseeker.Rnw") \documentclass[12pt]{article} \usepackage[a4paper,left=3cm,top=2cm,bottom=3cm,right=3cm,ignoreheadfoot]{geometry} \pagestyle{empty} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{helvet} \usepackage[titletoc]{appendix} \usepackage{tocloft} \setlength{\parindent}{0em} \setlength{\parskip}{.5em} \renewcommand{\familydefault}{\sfdefault} \newcommand{\Rcode}[1]{{\texttt{#1}}} \newcommand{\Robject}[1]{{\small\texttt{#1}}} \newcommand{\Rfunction}[1]{\Robject{#1}} \newcommand{\Rpackage}[1]{\textit{#1}} \newcommand{\Rparameter}[1]{\textit{#1}} \newcommand{\Rclass}[1]{\textit{#1}} \newcommand{\R}{\textsf{R}} \usepackage[ bookmarks,% colorlinks,% linktoc=section,% linkcolor=RedViolet,% citecolor=RedViolet,% urlcolor=RedViolet,% linkbordercolor={1 1 1},% citebordercolor={1 1 1},% urlbordercolor={1 1 1},% raiselinks,% plainpages,% pdftex ]{hyperref} \usepackage{cite} \renewcommand{\floatpagefraction}{0.9} \usepackage{sectsty} \sectionfont{\sffamily\bfseries\color{RoyalBlue}\sectionrule{0pt}{0pt}{-1ex}{1pt}} \subsectionfont{\sffamily\bfseries\color{RoyalBlue}} \subsubsectionfont{\sffamily\bfseries\color{RoyalBlue}} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhead{} \fancyfoot{} \lfoot{}\cfoot{}\rfoot{} \renewcommand{\headrule}{} \usepackage{graphicx} %\usepackage{xstring} <>= library(TxDb.Hsapiens.UCSC.hg19.knownGene) library(clusterProfiler) library(ChIPseeker) library(org.Hs.eg.db) library(GenomicFeatures) library(GenomicRanges) library(knitr) opts_chunk$set(tidy_source=TRUE, tidy.opts=list(blank=FALSE, width.cutoff=50), out.truncate=80, out.lines=6, cache=TRUE, dev='pdf', include=TRUE, fig.width=6, fig.height=6, resolution=100) @ \newcommand{\fixme}[1]{{\textbf{Fixme:} \textit{\textcolor{blue}{#1}}}} \title{\textsf{\textbf{ChIPseeker: an R package for ChIP peak Annotation, Comparision and Visualization}}} \author{Guangchuang Yu\\ The University of Hong Kong} \begin{document} \maketitle <>= options(digits=3, width=80, prompt=" ", continue=" ") @ \tableofcontents \section{Introduction} Chromatin immunoprecipitation followed by high-throughput sequencing (ChIP-seq) has become standard technologies for genome wide identification of DNA-binding protein target sites. After read mappings and peak callings, the peak should be annotated to answer the biological questions. Annotation also create the possibility of integrate expression profile data to predict gene expression regulation. \Rpackage{ChIPseeker} was developed for annotating nearest genes and genomic features to peaks. \\ \\ ChIP peak data set comparison is also very important. We can use it as an index to estimate how well biological replications are. Even more important is applying to infer cooperative regulation. If two ChIP seq data, obtained by two different binding proteins, overlap significantly, these two proteins may form a complex or have interaction in regulation chromosome remodelling or gene expression. \Rpackage{ChIPseeker} support statistical testing of significant overlap among ChIP seq data sets, and incorporate open access database GEO for users to compare their own dataset to those deposited in database. Protein interaction hypothesis can be generated by mining data deposited in database. Converting genome coordinations from one genome version to another is also supported, making this comparison available for different genome version and different species. \\ \\ Several visualization functions are implemented to visualize the coverage of the ChIP seq data, peak annotation, average profile and heatmap of peaks binding to TSS region. \\ \\ Functional enrichment analysis of the peaks can be performed by my Bioconductor packages \Rpackage{DOSE} , \Rpackage{ReactomePA}, \Rpackage{clusterProfiler} \cite{yu_clusterprofiler:_2012} . <>= ## loading packages require(ChIPseeker) require(TxDb.Hsapiens.UCSC.hg19.knownGene) txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene require(clusterProfiler) @ \section{ChIP profiling} The datasets CBX6 and CBX7 in this vignettes were downloaded from GEO (GSE40740) \cite{pemberton_genome-wide_2014} while ARmo\_0M, ARmo\_1nM and ARmo\_100nM were downloaded from GEO (GSE48308) \cite{urbanucci_overexpression_2012} . \Rpackage{ChIPseeker} provides \Rfunction{readPeakFile} to load the peak and store in \Robject{GRanges} object. %%Most of the functions in \Rpackage{ChIPseeker} can accept input in peak file (bed format) or \Robject{GRanges} object. <>= files <- getSampleFiles() print(files) peak <- readPeakFile(files[[4]]) peak @ \subsection{ChIP peaks coverage plot} After peak calling, we would like to know the peak locations over the whole genome, \Rfunction{covplot} function calculates the coverage of peak regions over chromosomes and generate a figure to visualize. <>= covplot(peak, weightCol="V5") @ <>= covplot(peak, weightCol="V5", chrs=c("chr17", "chr18"), xlim=c(4.5e7, 5e7)) @ \subsection{Profile of ChIP peaks binding to TSS regions} First of all, for calculate the profile of ChIP peaks binding to TSS regions, we should prepare the TSS regions, which are defined as the flanking sequence of the TSS sites. Then align the peaks that are mapping to these regions, and generate the tagMatrix. <>= ## promoter <- getPromoters(TxDb=txdb, upstream=3000, downstream=3000) ## tagMatrix <- getTagMatrix(peak, windows=promoter) ## ## to speed up the compilation of this vignettes, we use a precalculated tagMatrix data("tagMatrixList") tagMatrix <- tagMatrixList[[4]] @ In the above code, you should notice that tagMatrix is not restricted to TSS regions. The regions can be other types that defined by the user. \subsubsection{Heatmap of ChIP binding to TSS regions} <>= tagHeatmap(tagMatrix, xlim=c(-3000, 3000), color="red") @ %% \begin{figure}[htb] %% \begin{center} %% \includegraphics[width=.4\linewidth]{figures/peakHeat.png} %% \caption{Heatmap of ChIP peaks binding to TSS regions} %% \label{Fig:heatmap} %% \end{center} %% \end{figure} \Rpackage{ChIPseeker} provide a one step function to generate this figure from bed file. The following function will generate the same figure as above. <>= peakHeatmap(files[[4]], TxDb=txdb, upstream=3000, downstream=3000, color="red") @ \subsubsection{Average Profile of ChIP peaks binding to TSS region} <>= plotAvgProf(tagMatrix, xlim=c(-3000, 3000), xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency") @ %% \begin{figure}[htb] %% \begin{center} %% \includegraphics[width=.7\linewidth]{figures/avgProf.png} %% \caption{Average Profile of ChIP peaks binding to TSS region} %% \label{Fig:avgProf} %% \end{center} %% \end{figure} The function \Rfunction{plotAvgProf2} provide a one step from bed file to average profile plot. The following command will generate the same figure as shown above. <>= plotAvgProf2(files[[4]], TxDb=txdb, upstream=3000, downstream=3000, xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency") @ \section{Peak Annotation} <>= peakAnno <- annotatePeak(files[[4]], tssRegion=c(-3000, 3000), TxDb=txdb, annoDb="org.Hs.eg.db") peakAnno @ Peak Annotation is performed by \Rfunction{annotatePeak}. User can define TSS (transcription start site) region, by default TSS is defined from -3kb to +3kb. The output of \Rfunction{annotatePeak} is \Robject{csAnno} instance. \Rpackage{ChIPseeker} provides \Rfunction{as.GRanges} to convert \Robject{csAnno} to \Robject{GRanges} instance, and \Rfunction{as.data.frame} to convert \Robject{csAnno} to \Robject{data.frame} which can be exported to file by \Rfunction{write.table}. \\ \\ \Robject{TxDb} object contained transcript-related features of a particular genome. Bioconductor provides several package that containing \Robject{TxDb} object of model organisms with multiple commonly used genome version, for instance \Rpackage{TxDb.Hsapiens.UCSC.hg19.knownGene} and \Rpackage{TxDb.Hsapiens.UCSC.hg18.knownGene} for human genome hg19 and hg18, \Rpackage{TxDb.Mmusculus.UCSC.mm10.knownGene} and \Rpackage{TxDb.Mmusculus.UCSC.mm9.knownGene} for mouse genome mm10 and mm9, etc. User can also prepare their own \Robject{TxDb} object by retrieving information from UCSC Genome Bioinformatics and BioMart data resources by R function \Rfunction{makeTranscriptDbFromBiomart} and \Rfunction{makeTranscriptDbFromUCSC}. TxDb object should be passed for peak annotation. \\ \\ All the peak information contained in peakfile will be retained in the output of \Rfunction{annotatePeak}. The position and strand information of nearest genes are reported. The distance from peak to the TSS of its nearest gene is also reported. The genomic region of the peak is reported in annotation column. Since some annotation may overlap, \Rpackage{ChIPseeker} adopted the following priority in genomic annotation. \begin{itemize} \item Promoter \item 5' UTR \item 3' UTR \item Exon \item Intron \item Downstream \item Intergenic \end{itemize} Downstream is defined as the downstream of gene end. \\ \\ \Rfunction{annotatePeak} report detail information when the annotation is Exon or Intron, for instance "Exon (uc002sbe.3/9736, exon 69 of 80)", means that the peak is overlap with an Exon of transcript uc002sbe.3, and the corresponding Entrez gene ID is 9736 (Transcripts that belong to the same gene ID may differ in splice events), and this overlaped exon is the 69th exon of the 80 exons that this transcript uc002sbe.3 prossess. \\ \\ Parameter annoDb is optional, if provided, extra columns including SYMBOL, GENENAME, ENSEMBL/ENTREZID will be added. The geneId column in annotation output will be consistent with the geneID in TxDb. If it is ENTREZID, ENSEMBL will be added if annoDb is provided, while if it is ENSEMBL ID, ENTREZID will be added. \subsection{Visualize Genomic Annotation} To annotate the location of a given peak in terms of genomic features, \Rfunction{annotatePeak} assigns peaks to genomic annotation in "annotation" column of the output, which includes whether a peak is in the TSS, Exon, 5' UTR, 3' UTR, Intronic or Intergenic. Many researchers are very interesting in these annotations. TSS region can be defined by user and \Rfunction{annotatePeak} output in details of which exon/intron of which genes as illustrated in previous section. \\ \\ Pie and Bar plot are supported to visualize the genomic annotation. <>= plotAnnoPie(peakAnno) @ <>= plotAnnoBar(peakAnno) @ Since some annotation overlap, user may interested to view the full annotation with their overlap, which can be partially resolved by \Rfunction{vennpie} function. <>= vennpie(peakAnno) @ \subsection{Visualize distribution of TF-binding loci relative to TSS} The distance from the peak (binding site) to the TSS of the nearest gene is calculated by \Rfunction{annotatePeak} and reported in the output. We provide \Rfunction{plotDistToTSS} to calculate the percentage of binding sites upstream and downstream from the TSS of the nearest genes, and visualize the distribution. <>= plotDistToTSS(peakAnno, title="Distribution of transcription factor-binding loci \n relative to TSS") @ \section{Functional enrichment analysis} Once we have obtained the annotated nearest genes, we can perform functional enrichment analysis to identify predominant biological themes among these genes by incorporating biological knowledge provided by biological ontologies. For instance, Gene Ontology (GO) \cite{ashburner_gene_2000} annotates genes to biological processes, molecular functions, and cellular components in a directed acyclic graph structure, Kyoto Encyclopedia of Genes and Genomes (KEGG) \cite{kanehisa_kegg_2004} annotates genes to pathways, Disease Ontology (DO) \cite{schriml_disease_2011} annotates genes with human disease association, and Reactome \cite{croft_reactome_2013} annotates gene to pathways and reactions. \\ \\ Enrichment analysis is a widely used approach to identify biological themes. I have developed several Bioconductor packages for investigating whether the number of selected genes associated with a particular biological term is larger than expected, including \Rpackage{DOSE} for Disease Ontology, \Rpackage{ReactomePA} for reactome pathway, \Rpackage{clusterProfiler} \cite{yu_clusterprofiler:_2012} for Gene Ontology and KEGG enrichment analysis. <>= require(clusterProfiler) bp <- enrichGO(as.data.frame(peakAnno)$geneId, ont="BP", readable=TRUE) head(summary(bp)) @ More information can be found in the vignettes of Bioconductor packages \Rpackage{DOSE} , \Rpackage{ReactomePA}, \Rpackage{clusterProfiler} \cite{yu_clusterprofiler:_2012}, which also provide several methods to visualize enrichment results. The \Rpackage{clusterProfiler} package is designed for comparing and visualizing functional profiles among gene clusters, and can directly applied to compare biological themes at GO, DO, KEGG, Reactome perspective. \\ \\ \section{ChIP peak data set comparison} \subsection{Profile of several ChIP peak data binding to TSS region} Function \Rfunction{plotAvgProf} and \Rfunction{tagHeatmap} can accept a list of \Robject{tagMatrix} and visualize profile or heatmap among several ChIP experiments, while \Rfunction{plotAvgProf2} and \Rfunction{peakHeatmap} can accept a list of bed files and perform the same task in one step. \subsubsection{Average profiles} <>= ## promoter <- getPromoters(TxDb=txdb, upstream=3000, downstream=3000) ## tagMatrixList <- lapply(files, getTagMatrix, windows=promoter) ## ## to speed up the compilation of this vigenettes, we load a precaculated tagMatrixList data("tagMatrixList") plotAvgProf(tagMatrixList, xlim=c(-3000, 3000)) @ %% \begin{figure}[htb] %% \begin{center} %% \includegraphics[width=.7\linewidth]{figures/avgProf2.png} %% \caption{Average Profiles of ChIP peaks among different experiments} %% \label{Fig:avgProf2} %% \end{center} %% \end{figure} \subsubsection{Peak heatmaps} <>= tagHeatmap(tagMatrixList, xlim=c(-3000, 3000), color=NULL) @ %% \begin{figure}[htb] %% \begin{center} %% \includegraphics[width=.4\linewidth]{figures/peakHeat2.png} %% \caption{Heatmap of ChIP peaks among different experiments} %% \label{Fig:heatmap2} %% \end{center} %% \end{figure} \subsection{ChIP peak annotation comparision} The \Rfunction{plotAnnoBar} and \Rfunction{plotDistToTSS} can also accept input of a named list of annotated peaks (output of \Rfunction{annotatePeak}). <>= peakAnnoList <- lapply(files, annotatePeak, TxDb=txdb, tssRegion=c(-3000, 3000), verbose=FALSE) @ We can use \Rfunction{plotAnnoBar} to comparing their genomic annotation. <>= plotAnnoBar(peakAnnoList) @ R function \Rfunction{plotDistToTSS} can use to comparing distance to TSS profiles among ChIPseq data. <>= plotDistToTSS(peakAnnoList) @ \subsection{Functional profiles comparison} As shown in section 4, the annotated genes can analyzed by \Rpackage{clusterProfiler}, \Rpackage{DOSE} and \Rpackage{ReactomePA} for Gene Ontology, KEGG, Disease Ontology and Reactome Pathway enrichment analysis. \\ \\ The \Rpackage{clusterProfiler} package provide \Rfunction{compareCluster} function for comparing biological themes among gene clusters, and can be easily adopted to compare different ChIP peak experiments. <>= genes = lapply(peakAnnoList, function(i) as.data.frame(i)$geneId) names(genes) = sub("_", "\n", names(genes)) compGO <- compareCluster(geneCluster=genes, fun="enrichGO", ont="MF", organism="human", pvalueCutoff=0.05, pAdjustMethod="BH") plot(compGO, showCategory=20, title="Molecular Function Enrichment") @ \begin{figure}[htb] \begin{center} \includegraphics[width=.8\linewidth]{figures/mf.png} \caption{Compare Biological themes among different experiments} \label{Fig:MF} \end{center} \end{figure} \subsection{Overlap of peaks and annotated genes} User may want to compare the overlap peaks of replicate experiments or from different experiments. \Rpackage{ChIPseeker} provides \Rfunction{peak2GRanges} that can read peak file and stored in GRanges object. Several files can be read simultaneously using lapply, and then passed to \Rfunction{vennplot} to calculate their overlap and draw venn plot. \\ \\ \Rfunction{vennplot} accept a list of object, can be a list of GRanges or a list of vector. Here, I will demonstrate using \Rfunction{vennplot} to visualize the overlap of the nearest genes stored in peakAnnoList. <>= genes= lapply(peakAnnoList, function(i) as.data.frame(i)$geneId) vennplot(genes) @ \section{Statistical testing of ChIP seq overlap} Overlap is very important, if two ChIP experiment by two different proteins overlap in a large fraction of their peaks, they may cooperative in regulation. Calculating the overlap is only touch the surface. \Rpackage{ChIPseeker} implemented statistical methods to measure the significance of the overlap. \subsection{Shuffle genome coordination} <>= p <- GRanges(seqnames=c("chr1", "chr3"), ranges=IRanges(start=c(1, 100), end=c(50, 130))) shuffle(p, TxDb=txdb) @ We implement the \Rfunction{shuffle} function to randomly permute the genomic locations of ChIP peaks defined in a genome which stored in \Robject{TxDb} object. \subsection{Peak overlap enrichment analysis} With the ease of this \Rfunction{shuffle} method, we can generate thousands of random ChIP data and calculate the background null distribution of the overlap among ChIP data sets. <>= enrichPeakOverlap(queryPeak=files[[5]], targetPeak=unlist(files[1:4]), TxDb=txdb, pAdjustMethod="BH", nShuffle=50, chainFile=NULL) @ Parameter \Robject{queryPeak} is the query ChIP data, while \Robject{targetPeak} is bed file name or a vector of bed file names from comparison; \Robject{nShuffle} is the number to shuffle the peaks in \Robject{targetPeak}. To speed up the compilation of this vignettes, we only set \Robject{nShuffle} to 50 as an example for only demonstration. User should set the number to 1000 or above for more robust result. Parameter \Robject{chainFile} are chain file name for mapping the \Robject{targetPeak} to the genome version consistent with \Robject{queryPeak} when their genome version are different. This creat the possibility of comparison among different genome version and cross species. In the output, \Robject{qSample} is the name of \Robject{queryPeak} and \Robject{qLen} is the the number of peaks in \Robject{queryPeak}. \Robject{N\_OL} is the number of overlap between \Robject{queryPeak} and \Robject{targetPeak}. \section{Data Mining with ChIP seq data deposited in GEO} There are many ChIP seq data sets that have been published and deposited in GEO database. We can compare our own dataset to those deposited in GEO to search for significant overlap data. Significant overlap of ChIP seq data by different binding proteins may be used to infer cooperative regulation and thus can be used to generate hypotheses. \\ \\ We collect about 15,000 bed files deposited in GEO, user can use \Rfunction{getGEOspecies} to get a summary based on speices. \subsection{GEO data collection} <>= getGEOspecies() @ The summary can also based on genome version as illustrated below: <>= getGEOgenomeVersion() @ User can access the detail information by \Rfunction{getGEOInfo}, for each genome version. <>= hg19 <- getGEOInfo(genome="hg19", simplify=TRUE) head(hg19) @ If \Robject{simplify} is set to \Robject{FALSE}, extra information including \Robject{source\_name}, \Robject{extract\_protocol}, \Robject{description}, \Robject{data\_processing}, and \Robject{submission\_date} will be incorporated. \subsection{Download GEO ChIP data sets} \Rpackage{ChIPseeker} provide function \Rfunction{downloadGEObedFiles} to download all the bed files of a particular genome. <>= downloadGEObedFiles(genome="hg19", destDir="hg19") @ Or a vector of GSM accession number by \Rfunction{downloadGSMbedFiles}. <>= gsm <- hg19$gsm[sample(nrow(hg19), 10)] downloadGSMbedFiles(gsm, destDir="hg19") @ \subsection{Overlap significant testing} After download the bed files from GEO, we can pass them to \Rfunction{enrichPeakOverlap} for testing the significant of overlap. Parameter \Robject{targetPeak} can be the folder, e.g. hg19, that containing bed files. \Rfunction{enrichPeakOverlap} will parse the folder and compare all the bed files. It is possible to test the overlap with bed files that are mapping to different genome or different genome versions, \Rfunction{enrichPeakOverlap} provide a parameter \Robject{chainFile} that can pass a chain file and liftOver the \Robject{targetPeak} to the genome version consistent with \Robject{queryPeak}. Signifcant overlap can be use to generate hypothesis of cooperative regulation.By mining the data deposited in GEO, we can identify some putative complex or interacted regulators in gene expression regulation or chromsome remodelling for further validation. \section{Session Information} The version number of R and packages loaded for generating the vignette were: <>= toLatex(sessionInfo()) @ \bibliographystyle{unsrt} \bibliography{ChIPseeker} \end{document}