derfinderPlot
If you wish, you can view this vignette online here.
derfinderPlot
(Collado-Torres, Jaffe, and Leek, 2014)
is an addon package for derfinder
(Collado-Torres, Frazee, Jaffe, and Leek, 2014)
with functions that allow you to visualize the results.
While the functions in derfinderPlot
assume you generated the data with derfinder
, they can be used with other GRanges
objects properly formatted.
The functions in derfinderPlot
are:
plotCluster()
is a tailored ggbio
(Yin, Cook, and Lawrence, 2012)
plot that shows all the regions in a cluster (defined by distance). It shows the base-level coverage for each sample as well as the mean for each group. If these regions overlap any known gene, the gene and the transcript annotation is displayed.plotOverview()
is another tailored ggbio
(Yin, Cook, and Lawrence, 2012)
plot showing an overview of the whole genome. This plot can be useful to observe if the regions are clustered in a subset of a chromosome. It can also be used to check whether the regions match predominantly one part of the gene structure (for example, 3' overlaps).plotRegionCoverage()
is a fast plotting function using R
base graphics that shows the base level coverage for each sample inside a specific region of the genome. If the region overlaps any known gene or intron, the information is displayed. Optionally, it can display the known transcripts. This function is most likely the easiest to use with GRanges
objects from other packages.As an example, we will analyze a small subset of the samples from the BrainSpan Atlas of the Human Brain (BrainSpan, 2011)
publicly available data.
We first load the required packages.
## Load libraries suppressPackageStartupMessages(library('derfinder')) library('derfinderData') library('derfinderPlot')
For this example, we created a small table with the relevant phenotype data for 12 samples: 6 from fetal samples and 6 from adult samples. We chose at random a brain region, in this case the primary auditory cortex (core) and for the example we will only look at data from chromosome 21. Other variables include the age in years and the gender. The data is shown below.
library('knitr') ## Get pheno table pheno <- subset(brainspanPheno, structure_acronym == 'A1C') ## Display the main information p <- pheno[, -which(colnames(pheno) %in% c('structure_acronym', 'structure_name', 'file'))] rownames(p) <- NULL kable(p, format = 'html', row.names = TRUE)
gender | lab | Age | group | |
---|---|---|---|---|
1 | M | HSB114.A1C | -0.6428571 | fetal |
2 | M | HSB103.A1C | -0.6428571 | fetal |
3 | M | HSB178.A1C | -0.5714286 | fetal |
4 | M | HSB154.A1C | -0.5714286 | fetal |
5 | F | HSB150.A1C | -0.6666667 | fetal |
6 | F | HSB149.A1C | -0.6428571 | fetal |
7 | F | HSB130.A1C | 21.0000000 | adult |
8 | M | HSB136.A1C | 23.0000000 | adult |
9 | F | HSB126.A1C | 30.0000000 | adult |
10 | M | HSB145.A1C | 36.0000000 | adult |
11 | M | HSB123.A1C | 37.0000000 | adult |
12 | F | HSB135.A1C | 40.0000000 | adult |
We can load the data from derfinderData
(Collado-Torres, Jaffe, and Leek, 2014)
by first identifying the paths to the BigWig files with derfinder::rawFiles()
and then loading the data with derfinder::fullCoverage()
.
## Determine the files to use and fix the names files <- rawFiles(system.file('extdata', 'A1C', package = 'derfinderData'), samplepatt = 'bw', fileterm = NULL) names(files) <- gsub('.bw', '', names(files)) ## Load the data from disk system.time(fullCov <- fullCoverage(files = files, chrs = 'chr21'))
## user system elapsed ## 3.548 0.028 3.850
Alternatively, since the BigWig files are publicly available from BrainSpan (see here), we can extract the relevant coverage data using derfinder::fullCoverage()
. Note that as of rtracklayer
1.25.16 BigWig files are not supported on Windows: you can find the fullCov
object inside derfinderData
to follow the examples.
## Determine the files to use and fix the names files <- pheno$file names(files) <- gsub('.A1C', '', pheno$lab) ## Load the data from the web system.time(fullCov <- fullCoverage(files = files, chrs = 'chr21'))
Once we have the base-level coverage data for all 12 samples, we can construct the models. In this case, we want to find differences between fetal and adult samples while adjusting for gender and a proxy of the library size.
## Get some idea of the library sizes sampleDepths <- sampleDepth(collapseFullCoverage(fullCov), 1)
## Define models models <- makeModels(sampleDepths, testvars = pheno$group, adjustvars = pheno[, c('gender')])
Next, we can find candidate differentially expressed regions (DERs) using as input the segments of the genome where at least one sample has coverage greater than 3. In this particular example, we chose a low theoretical F-statistic cutoff and used 20 permutations.
## Filter coverage filteredCov <- lapply(fullCov, filterData, cutoff = 3)
## Perform differential expression analysis suppressPackageStartupMessages(library('bumphunter')) system.time(results <- analyzeChr(chr = 'chr21', filteredCov$chr21, models, groupInfo = pheno$group, writeOutput = FALSE, cutoffFstat = 5e-02, nPermute = 20, seeds = 20140923 + seq_len(20)))
## Matching regions to genes. ## nearestgene: loading bumphunter hg19 transcript database ## finding nearest transcripts... ## AnnotatingDone.
## user system elapsed ## 26.086 0.328 26.487
## Quick access to the results regions <- results$regions$regions ## Annotation database to use suppressPackageStartupMessages(library('TxDb.Hsapiens.UCSC.hg19.knownGene')) txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
plotOverview()
Now that we have obtained the main results using derfinder
, we can proceed to visualizing the results using derfinderPlot
. The easiest to use of all the functions is plotOverview()
which takes a set of regions and annotation information produced by bumphunter::annotateNearest()
.
The plot below shows the candidate DERs colored by whether their q-value was less than 0.10 or not.
## Q-values overview plotOverview(regions = regions, annotation = results$annotation, type = 'qval')
The next plot shows the candidate DERs colored by the type of gene feature they are nearest too.
## Annotation overview plotOverview(regions = regions, annotation = results$annotation, type = 'annotation')
In this particular example, because we are only using data from one chromosome the above plot is not as informative as in a real case scenario. However, with this plot we can quickly observe that nearly all of the candidate DERs are inside an exon.
plotRegionCoverage()
The complete opposite of visualizing the candidate DERs at the genome level is to visualize them one region at a time. plotRegionCoverage()
allows us to do this quickly for a large number of regions.
Before using this function, we need to process more detailed information using two derfinder
functions: annotateRegions()
and getRegionCoverage()
as shown below.
## Get required information for the plots annoRegs <- annotateRegions(regions, genomicState$fullGenome)
regionCov <- getRegionCoverage(fullCov, regions)
Once we have the relevant information we can proceed to plotting the first 10 regions. In this case, we will supply plotRegionCoverage()
with the information it needs to plot transcripts overlapping these 10 regions.
## Plot top 10 regions plotRegionCoverage(regions = regions, regionCoverage = regionCov, groupInfo = pheno$group, nearestAnnotation = results$annotation, annotatedRegions = annoRegs, whichRegions=1:10, txdb = txdb, scalefac = 1, ask = FALSE)
The base level coverage is shown in a log2 scale with any overlapping exons shown in dark blue and known introns in light blue.
plotCluster()
In this example, we noticed with the plotRegionCoverage()
plots that most of the candidate DERs are contained in known exons. Sometimes, the signal might be low or we might have used very stringent cutoffs in the derfinder
analysis. One way we can observe this is by plotting clusters of regions where a cluster is defined as regions within 300 bp (default option) of each other.
To visualize the clusters, we can use plotCluster()
which takes similar input to plotOverview()
with the notable addition of the coverage information as well as the idx
argument. This argument specifies which region to focus on: it will be plotted with a red bar and will determine the cluster to display.
In the plot below we observe one large candidate DER with other nearby ones that do not have a q-value less than 0.10. In a real analysis, we would probably discard this region as the coverage is fairly low.
## First cluster plotCluster(idx = 1, regions = regions, annotation = results$annotation, coverageInfo = fullCov$chr21, txdb = txdb, groupInfo = pheno$group, titleUse = 'pval')
The second cluster shows a larger number of potential DERs (again without q-values less than 0.10) in a segment of the genome where the coverage data is highly variable. This is a common occurrence with RNA-seq data.
## Second cluster plotCluster(idx = 2, regions = regions, annotation = results$annotation, coverageInfo = fullCov$chr21, txdb = txdb, groupInfo = pheno$group, titleUse = 'pval')
These plots show an ideogram which helps quickly identify which region of the genome we are focusing on. Then, the coverage level information for each sample is displayed in log2. Next, the coverage group means are shown in the log2 scale. The plot is completed with the potential and candidate DERs as well as any known transcripts.
If you are interested in using the advanced arguments, use derfinder::advancedArg()
as shown below:
## URLs to advanced arguemtns sapply(c('plotCluster', 'plotOverview'), derfinder::advancedArg, package = 'derfinderPlot', browse = FALSE)
## plotCluster ## "https://github.com/search?utf8=%E2%9C%93&q=advanced_argument+filename%3Acluster+repo%3Alcolladotor%2FderfinderPlot+path%3A%2FR&type=Code" ## plotOverview ## "https://github.com/search?utf8=%E2%9C%93&q=advanced_argument+filename%3Aoverview+repo%3Alcolladotor%2FderfinderPlot+path%3A%2FR&type=Code"
## Set browse = TRUE if you want to open them in your browser
This package was made possible thanks to:
(R Core Team, 2014)
(Arora, Morgan, Carlson, and Pages, 2014)
(Lawrence, Huber, Pagès, Aboyoun, et al., 2013)
(Yin, Cook, and Lawrence, 2012)
(Wickham, 2009)
(Lawrence, Huber, Pagès, Aboyoun, et al., 2013)
(Wickham, 2011)
(Neuwirth, 2011)
(Wickham, 2007)
(Wickham, 2014)
(Yin, Lawrence, and Cook, 2014)
(Irizarry, Ayree, Hansen, and Hansen, 2014)
and (Jaffe, E, Murakami, Peter, et al., 2012)
(Collado-Torres, Frazee, Jaffe, and Leek, 2014)
(Collado-Torres, Jaffe, and Leek, 2014)
(Wickham and Chang, 2014)
(Boettiger, 2014)
(Xie, 2014)
(Hester, 2013)
(Allaire, McPherson, Xie, Wickham, et al., 2014)
(Wickham, 2011)
(Carlson, 2014)
Code for creating the vignette
## Create the vignette library('knitrBootstrap') knitrBootstrapFlag <- packageVersion('knitrBootstrap') < '1.0.0' if(knitrBootstrapFlag) { ## CRAN version system.time(knit_bootstrap('derfinderPlot.Rmd', chooser=c('boot', 'code'), show_code = TRUE)) unlink('derfinderPlot.md') } else { ## GitHub version library('rmarkdown') system.time(render('derfinderPlot.Rmd', 'knitrBootstrap::bootstrap_document')) } ## Note: if you prefer the knitr version use: # library('rmarkdown') # system.time(render('derfinderPlot.Rmd', 'html_document')) unlink('chr21', recursive = TRUE) ## Extract the R code library('knitr') knit('derfinderPlot.Rmd', tangle = TRUE) ## Clean up file.remove('derfinderPlotRef.bib')
Date the vignette was generated.
## [1] "2014-11-04 21:01:18 PST"
Wallclock time spent generating the vignette.
## Time difference of 1.478 mins
R
session information.
## setting value ## version R version 3.1.2 (2014-10-31) ## system x86_64, linux-gnu ## ui X11 ## language en_US: ## collate C ## tz
## package * version date source ## AnnotationDbi * 1.28.1 2014-11-05 Bioconductor ## BBmisc 1.8 2014-10-30 CRAN (R 3.1.2) ## BSgenome 1.34.0 2014-11-05 Bioconductor ## BatchJobs 1.5 2014-10-30 CRAN (R 3.1.2) ## Biobase * 2.26.0 2014-11-05 Bioconductor ## BiocGenerics * 0.12.0 2014-11-05 Bioconductor ## BiocParallel 1.0.0 2014-11-05 Bioconductor ## Biostrings 2.34.0 2014-11-05 Bioconductor ## DBI 0.3.1 2014-09-24 CRAN (R 3.1.2) ## Formula 1.1.2 2014-07-13 CRAN (R 3.1.2) ## GGally 0.4.8 2014-08-26 CRAN (R 3.1.2) ## GenomeInfoDb * 1.2.2 2014-11-05 Bioconductor ## GenomicAlignments 1.2.1 2014-11-05 Bioconductor ## GenomicFeatures * 1.18.2 2014-11-05 Bioconductor ## GenomicFiles 1.2.0 2014-11-05 Bioconductor ## GenomicRanges * 1.18.1 2014-11-05 Bioconductor ## Hmisc 3.14.5 2014-09-12 CRAN (R 3.1.2) ## IRanges * 2.0.0 2014-11-05 Bioconductor ## MASS 7.3.35 2014-09-30 CRAN (R 3.1.2) ## Matrix 1.1.4 2014-06-15 CRAN (R 3.1.2) ## OrganismDbi 1.8.0 2014-11-05 Bioconductor ## R.methodsS3 1.6.1 2014-01-05 CRAN (R 3.1.2) ## RBGL 1.42.0 2014-11-05 Bioconductor ## RColorBrewer 1.0.5 2011-06-17 CRAN (R 3.1.2) ## RCurl 1.95.4.3 2014-07-29 CRAN (R 3.1.2) ## RJSONIO 1.3.0 2014-07-28 CRAN (R 3.1.2) ## RSQLite 1.0.0 2014-10-25 CRAN (R 3.1.2) ## Rcpp 0.11.3 2014-09-29 CRAN (R 3.1.2) ## RefManageR 0.8.40 2014-10-29 CRAN (R 3.1.2) ## Rsamtools 1.18.1 2014-11-05 Bioconductor ## S4Vectors * 0.4.0 2014-11-05 Bioconductor ## TxDb.Hsapiens.UCSC.hg19.knownGene * 3.0.0 2014-11-01 Bioconductor ## VariantAnnotation 1.12.3 2014-11-05 Bioconductor ## XML 3.98.1.1 2013-06-20 CRAN (R 3.1.2) ## XVector * 0.6.0 2014-11-05 Bioconductor ## acepack 1.3.3.3 2013-05-03 CRAN (R 3.1.2) ## base64enc 0.1.2 2014-06-26 CRAN (R 3.1.2) ## bibtex 0.3.6 2013-07-29 CRAN (R 3.1.2) ## biomaRt 2.22.0 2014-11-05 Bioconductor ## biovizBase 1.14.0 2014-11-05 Bioconductor ## bitops 1.0.6 2013-08-17 CRAN (R 3.1.2) ## brew 1.0.6 2011-04-13 CRAN (R 3.1.2) ## bumphunter * 1.6.0 2014-11-05 Bioconductor ## checkmate 1.5.0 2014-10-19 CRAN (R 3.1.2) ## cluster 1.15.3 2014-09-04 CRAN (R 3.1.2) ## codetools 0.2.9 2014-08-21 CRAN (R 3.1.2) ## colorspace 1.2.4 2013-09-30 CRAN (R 3.1.2) ## derfinder * 1.0.6 2014-11-05 Bioconductor ## derfinderData * 0.99.2 2014-11-01 Bioconductor ## derfinderHelper 1.0.3 2014-11-05 Bioconductor ## derfinderPlot * 1.0.3 2014-11-05 Bioconductor ## devtools * 1.6.1 2014-10-07 CRAN (R 3.1.2) ## dichromat 2.0.0 2013-01-24 CRAN (R 3.1.2) ## digest 0.6.4 2013-12-03 CRAN (R 3.1.2) ## doRNG 1.6 2014-03-07 CRAN (R 3.1.2) ## evaluate 0.5.5 2014-04-29 CRAN (R 3.1.2) ## fail 1.2 2013-09-19 CRAN (R 3.1.2) ## foreach * 1.4.2 2014-04-11 CRAN (R 3.1.2) ## foreign 0.8.61 2014-03-28 CRAN (R 3.1.2) ## formatR 1.0 2014-08-25 CRAN (R 3.1.2) ## ggbio 1.14.0 2014-11-05 Bioconductor ## ggplot2 1.0.0 2014-05-21 CRAN (R 3.1.2) ## graph 1.44.0 2014-11-05 Bioconductor ## gridExtra 0.9.1 2012-08-09 CRAN (R 3.1.2) ## gtable 0.1.2 2012-12-05 CRAN (R 3.1.2) ## httr 0.5 2014-09-02 CRAN (R 3.1.2) ## iterators * 1.0.7 2014-04-11 CRAN (R 3.1.2) ## knitcitations * 1.0.4 2014-10-28 CRAN (R 3.1.2) ## knitr * 1.7 2014-10-13 CRAN (R 3.1.2) ## knitrBootstrap * 0.9.0 2013-10-17 CRAN (R 3.1.2) ## labeling 0.3 2014-08-23 CRAN (R 3.1.2) ## lattice 0.20.29 2014-04-04 CRAN (R 3.1.2) ## latticeExtra 0.6.26 2013-08-15 CRAN (R 3.1.2) ## locfit * 1.5.9.1 2013-04-20 CRAN (R 3.1.2) ## lubridate 1.3.3 2013-12-31 CRAN (R 3.1.2) ## markdown 0.7.4 2014-08-24 CRAN (R 3.1.2) ## matrixStats 0.10.3 2014-10-15 CRAN (R 3.1.2) ## memoise 0.2.1 2014-04-22 CRAN (R 3.1.2) ## munsell 0.4.2 2013-07-11 CRAN (R 3.1.2) ## nnet 7.3.8 2014-03-28 CRAN (R 3.1.2) ## pkgmaker 0.22 2014-05-14 CRAN (R 3.1.2) ## plyr 1.8.1 2014-02-26 CRAN (R 3.1.2) ## proto 0.3.10 2012-12-22 CRAN (R 3.1.2) ## qvalue 1.40.0 2014-11-05 Bioconductor ## registry 0.2 2012-01-24 CRAN (R 3.1.2) ## reshape 0.8.5 2014-04-23 CRAN (R 3.1.2) ## reshape2 1.4 2014-04-23 CRAN (R 3.1.2) ## rngtools 1.2.4 2014-03-06 CRAN (R 3.1.2) ## rpart 4.1.8 2014-03-28 CRAN (R 3.1.2) ## rstudioapi 0.1 2014-03-27 CRAN (R 3.1.2) ## rtracklayer 1.26.1 2014-11-05 Bioconductor ## scales 0.2.4 2014-04-22 CRAN (R 3.1.2) ## sendmailR 1.2.1 2014-09-21 CRAN (R 3.1.2) ## stringr 0.6.2 2012-12-06 CRAN (R 3.1.2) ## survival 2.37.7 2014-01-22 CRAN (R 3.1.2) ## xtable 1.7.4 2014-09-12 CRAN (R 3.1.2) ## zlibbioc 1.12.0 2014-11-05 Bioconductor
This vignette was generated using knitrBootstrap
(Hester, 2013)
with knitr
(Xie, 2014)
and rmarkdown
(Allaire, McPherson, Xie, Wickham, et al., 2014)
running behind the scenes.
Citations made with knitcitations
(Boettiger, 2014)
.
[1] J. Allaire, J. McPherson, Y. Xie, H. Wickham, et al. rmarkdown: Dynamic Documents for R. R package version 0.3.3. 2014. URL: http://CRAN.R-project.org/package=rmarkdown.
[2] S. Arora, M. Morgan, M. Carlson and H. Pages. GenomeInfoDb: Utilities for manipulating chromosome and other 'seqname' identifiers. R package version 1.2.2. 2014.
[3] C. Boettiger. knitcitations: Citations for knitr markdown files. R package version 1.0.4. 2014. URL: http://CRAN.R-project.org/package=knitcitations.
[4] BrainSpan. “Atlas of the Developing Human Brain [Internet]. Funded by ARRA Awards 1RC2MH089921-01, 1RC2MH090047-01, and 1RC2MH089929-01.” 2011. URL: http://developinghumanbrain.org.
[5] M. Carlson. TxDb.Hsapiens.UCSC.hg19.knownGene: Annotation package for TxDb object(s). R package version 3.0.0. 2014.
[6] L. Collado-Torres, A. C. Frazee, A. E. Jaffe and J. T. Leek. derfinder: Annotation-agnostic differential expression analysis of RNA-seq data at base-pair resolution. https://github.com/lcolladotor/derfinder - R package version 1.0.6. 2014. URL: http://www.bioconductor.org/packages/release/bioc/html/derfinder.html.
[7] L. Collado-Torres, A. E. Jaffe and J. T. Leek. derfinderPlot: Plotting functions for derfinder. https://github.com/lcolladotor/derfinderPlot - R package version 1.0.3. 2014. URL: http://www.bioconductor.org/packages/release/bioc/html/derfinderPlot.html.
[8] L. Collado-Torres, A. Jaffe and J. Leek. derfinderData: Processed BigWigs from BrainSpan for examples. R package version 0.99.2. 2014. URL: https://github.com/lcolladotor/derfinderData.
[9] J. Hester. knitrBootstrap: Knitr Bootstrap framework. R package version 0.9.0. 2013. URL: http://CRAN.R-project.org/package=knitrBootstrap.
[10] R. A. Irizarry, M. Ayree, K. D. Hansen and H. C. Hansen. bumphunter: Bump Hunter. R package version 1.6.0. 2014. URL: https://github.com/ririzarr/bumphunter.
[11] Jaffe, A. E, Murakami, Peter, et al. “Bump hunting to identify differentially methylated regions in epigenetic epidemiology studies”. In: International Journal of Epidemiology (2012).
[12] M. Lawrence, W. Huber, H. Pagès, P. Aboyoun, et al. “Software for Computing and Annotating Genomic Ranges”. In: PLoS Computational Biology 9 (8 2013). DOI: 10.1371/journal.pcbi.1003118. URL: http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1003118}.
[13] E. Neuwirth. RColorBrewer: ColorBrewer palettes. R package version 1.0-5. 2011. URL: http://CRAN.R-project.org/package=RColorBrewer.
[14] R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria, 2014. URL: http://www.R-project.org/.
[15] H. Wickham. “Reshaping Data with the reshape Package”. In: Journal of Statistical Software 21.12 (2007), pp. 1–20. URL: http://www.jstatsoft.org/v21/i12/.
[16] H. Wickham. “The Split-Apply-Combine Strategy for Data Analysis”. In: Journal of Statistical Software 40.1 (2011), pp. 1–29. URL: http://www.jstatsoft.org/v40/i01/.
[17] H. Wickham. ggplot2: elegant graphics for data analysis. Springer New York, 2009. ISBN: 978-0-387-98140-6. URL: http://had.co.nz/ggplot2/book.
[18] H. Wickham. scales: Scale functions for graphics. R package version 0.2.4. 2014. URL: http://CRAN.R-project.org/package=scales.
[19] H. Wickham. “testthat: Get Started with Testing”. In: The R Journal 3 (2011), pp. 5–10. URL: http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf.
[20] H. Wickham and W. Chang. devtools: Tools to make developing R code easier. R package version 1.6.1. 2014. URL: http://CRAN.R-project.org/package=devtools.
[21] Y. Xie. “knitr: A Comprehensive Tool for Reproducible Research in R”. In: Implementing Reproducible Computational Research. Ed. by V. Stodden, F. Leisch and R. D. Peng. ISBN 978-1466561595. Chapman and Hall/CRC, 2014. URL: http://www.crcpress.com/product/isbn/9781466561595.
[22] T. Yin, D. Cook and M. Lawrence. “ggbio: an R package for extending the grammar of graphics for genomic data”. In: Genome Biology 13.8 (2012), p. R77.
[23] T. Yin, M. Lawrence and D. Cook. biovizBase: Basic graphic utilities for visualization of genomic data. R package version 1.14.0. 2014.