1 bumphunter example

The bumphunter package can be used for methylation analyses where you are interested in identifying differentially methylated regions. The vignette explains in greater detail the data set we are using in this example.

## Load bumphunter
library('bumphunter')
## Loading required package: S4Vectors
## Loading required package: stats4
## Loading required package: BiocGenerics
## Loading required package: parallel
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:parallel':
## 
##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
##     clusterExport, clusterMap, parApply, parCapply, parLapply,
##     parLapplyLB, parRapply, parSapply, parSapplyLB
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     Filter, Find, Map, Position, Reduce, anyDuplicated, append,
##     as.data.frame, basename, cbind, colMeans, colSums, colnames,
##     dirname, do.call, duplicated, eval, evalq, get, grep, grepl,
##     intersect, is.unsorted, lapply, lengths, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, rank, rbind,
##     rowMeans, rowSums, rownames, sapply, setdiff, sort, table,
##     tapply, union, unique, unsplit, which, which.max, which.min
## 
## Attaching package: 'S4Vectors'
## The following object is masked from 'package:base':
## 
##     expand.grid
## Loading required package: IRanges
## Loading required package: GenomeInfoDb
## Loading required package: GenomicRanges
## Loading required package: foreach
## Loading required package: iterators
## Loading required package: locfit
## locfit 1.5-9.1    2013-03-22
## Create data from the vignette
pos <- list(pos1=seq(1, 1000, 35),
            pos2=seq(2001, 3000, 35),
            pos3=seq(1, 1000, 50))
chr <- rep(paste0('chr', c(1, 1, 2)), times = sapply(pos, length))
pos <- unlist(pos, use.names = FALSE)

## Find clusters
cl <- clusterMaker(chr, pos, maxGap = 300)

## Build simulated bumps
Indexes <- split(seq_along(cl), cl)
beta1 <- rep(0, length(pos))
for(i in seq(along=Indexes)){
    ind <- Indexes[[i]]
    x <- pos[ind]
    z <- scale(x, median(x), max(x)/12)
    beta1[ind] <- i*(-1)^(i+1)*pmax(1-abs(z)^3,0)^3 ##multiply by i to vary size
}

## Build data
beta0 <- 3 * sin(2 * pi * pos / 720)
X <- cbind(rep(1, 20), rep(c(0, 1), each = 10))
set.seed(23852577)
error <- matrix(rnorm(20 * length(beta1), 0, 1), ncol = 20)
y <- t(X[, 1]) %x% beta0 + t(X[, 2]) %x% beta1 + error

## Perform bumphunting
tab <- bumphunter(y, X, chr, pos, cl, cutoff=.5)
## [bumphunterEngine] Using a single core (backend: doSEQ, version: 1.4.4).
## [bumphunterEngine] Computing coefficients.
## [bumphunterEngine] Finding regions.
## [bumphunterEngine] Found 15 bumps.
## Explore data
lapply(tab, head)
## $table
##     chr start  end      value       area cluster indexStart indexEnd  L
## 10 chr1  2316 2631 -1.5814747 15.8147473       2         39       48 10
## 7  chr2   451  551  1.5891293  4.7673878       3         68       70  3
## 2  chr1   456  526  1.0678828  3.2036485       1         14       16  3
## 5  chr1  2176 2211  0.7841794  1.5683589       2         35       36  2
## 6  chr1  2841 2841  1.2010184  1.2010184       2         54       54  1
## 4  chr1   771  771  0.7780902  0.7780902       1         23       23  1
##    clusterL
## 10       29
## 7        20
## 2        29
## 5        29
## 6        29
## 4        29
## 
## $coef
##             [,1]
## [1,]  0.60960932
## [2,] -0.09052769
## [3,] -0.21482638
## [4,]  0.13053755
## [5,] -0.21723642
## [6,]  0.39934961
## 
## $fitted
##             [,1]
## [1,]  0.60960932
## [2,] -0.09052769
## [3,] -0.21482638
## [4,]  0.13053755
## [5,] -0.21723642
## [6,]  0.39934961
## 
## $pvaluesMarginal
## [1] NA

Once we have the regions we can proceed to build the required GRanges object.

library('GenomicRanges')

## Build GRanges with sequence lengths
regions <- GRanges(seqnames = tab$table$chr, 
    IRanges(start = tab$table$start, end = tab$table$end),
    strand = '*', value = tab$table$value, area = tab$table$area, 
    cluster = tab$table$cluster, L = tab$table$L, clusterL = tab$table$clusterL)

## Assign chr lengths
data(hg19Ideogram, package = 'biovizBase')
seqlengths(regions) <- seqlengths(hg19Ideogram)[names(seqlengths(regions))]

## Explore the regions
regions
## GRanges object with 15 ranges and 5 metadata columns:
##        seqnames    ranges strand |              value              area
##           <Rle> <IRanges>  <Rle> |          <numeric>         <numeric>
##    [1]     chr1 2316-2631      * |  -1.58147472668612  15.8147472668612
##    [2]     chr2   451-551      * |   1.58912926544627  4.76738779633882
##    [3]     chr1   456-526      * |   1.06788283103948  3.20364849311844
##    [4]     chr1 2176-2211      * |  0.784179442360784  1.56835888472157
##    [5]     chr1      2841      * |   1.20101842543356  1.20101842543356
##    ...      ...       ...    ... .                ...               ...
##   [11]     chr1       631      * |  0.618602646982714 0.618602646982714
##   [12]     chr1         1      * |  0.609609318450113 0.609609318450113
##   [13]     chr1      2911      * | -0.576423040796044 0.576423040796044
##   [14]     chr2       251      * | -0.556159535339166 0.556159535339166
##   [15]     chr1      2806      * | -0.521605772372843 0.521605772372843
##          cluster         L  clusterL
##        <numeric> <numeric> <integer>
##    [1]         2        10        29
##    [2]         3         3        20
##    [3]         1         3        29
##    [4]         2         2        29
##    [5]         2         1        29
##    ...       ...       ...       ...
##   [11]         1         1        29
##   [12]         1         1        29
##   [13]         2         1        29
##   [14]         3         1        20
##   [15]         2         1        29
##   -------
##   seqinfo: 2 sequences from an unspecified genome

Now that we have identified a set of differentially methylated regions we can proceed to creating the HTML report. Note that this report has less information than the DiffBind example because we don’t have a p-value variable.

## Load regionReport
library('regionReport')
## Make it so that the report will be available as a vignette
original <- readLines(system.file('regionExploration', 'regionExploration.Rmd',
    package = 'regionReport'))
vignetteInfo <- c(
    'vignette: >',
    '  %\\VignetteEngine{knitr::rmarkdown}',
    '  %\\VignetteIndexEntry{Basic genomic regions exploration}',
    '  %\\VignetteEncoding{UTF-8}'
)
new <- c(original[1:16], vignetteInfo, original[17:length(original)])
writeLines(new, 'regionReportBumphunter.Rmd')

## Now create the report
report <- renderReport(regions, 'Example bumphunter', pvalueVars = NULL,
    densityVars = c('Area' = 'area', 'Value' = 'value',
    'Cluster Length' = 'clusterL'), significantVar = NULL,
    output = 'bumphunterExampleOutput', outdir = '.',
    template = 'regionReportBumphunter.Rmd', device = 'png')
## Writing 11 Bibtex entries ... OK
## Results written to file './bumphunterExampleOutput.bib'
## processing file: bumphunterExampleOutput.Rmd
## No annotationPackage supplied. Trying org.Hs.eg.db.
## Loading required package: org.Hs.eg.db
## 
## Getting TSS and TSE.
## Getting CSS and CSE.
## Getting exons.
## Annotating genes.
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## output file: bumphunterExampleOutput.knit.md
## /usr/bin/pandoc +RTS -K512m -RTS bumphunterExampleOutput.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output bumphunterExampleOutput.html --email-obfuscation none --self-contained --wrap preserve --standalone --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template /tmp/RtmplXliXl/BiocStyle/template.html --no-highlight --variable highlightjs=1 --number-sections --css /home/biocbuild/bbs-3.8-bioc/R/library/BiocStyle/resources/html/bioconductor.css --variable 'theme:bootstrap' --include-in-header /tmp/RtmplXliXl/rmarkdown-str2c09ba46e5e.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --metadata pagetitle=bumphunterExampleOutput.utf8.md --variable code_folding=hide --variable code_menu=1
## 
## Output created: bumphunterExampleOutput.html
## Clean up
file.remove('regionReportBumphunter.Rmd')
## [1] TRUE

You can view the final report here.

In case the link does not work, a pre-compiled version of this document and its corresponding report are available at leekgroup.github.io/regionReportSupp/.

2 Reproducibility

## Date generated:
Sys.time()
## [1] "2018-12-03 20:19:37 EST"
## Time spent making this page:
proc.time()
##    user  system elapsed 
## 149.288   2.752 152.007
## R and packages info:
options(width = 120)
sessioninfo::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
##  setting  value                                      
##  version  R version 3.5.1 Patched (2018-07-12 r74967)
##  os       Ubuntu 16.04.5 LTS                         
##  system   x86_64, linux-gnu                          
##  ui       X11                                        
##  language (EN)                                       
##  collate  C                                          
##  ctype    en_US.UTF-8                                
##  tz       America/New_York                           
##  date     2018-12-03                                 
## 
## ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
##  package                           * version   date       lib source        
##  acepack                             1.4.1     2016-10-29 [2] CRAN (R 3.5.1)
##  annotate                            1.60.0    2018-12-03 [2] Bioconductor  
##  AnnotationDbi                     * 1.44.0    2018-12-03 [2] Bioconductor  
##  AnnotationFilter                    1.6.0     2018-12-03 [2] Bioconductor  
##  assertthat                          0.2.0     2017-04-11 [2] CRAN (R 3.5.1)
##  backports                           1.1.2     2017-12-13 [2] CRAN (R 3.5.1)
##  base64enc                           0.1-3     2015-07-28 [2] CRAN (R 3.5.1)
##  bibtex                              0.4.2     2017-06-30 [2] CRAN (R 3.5.1)
##  bindr                               0.1.1     2018-03-13 [2] CRAN (R 3.5.1)
##  bindrcpp                            0.2.2     2018-03-29 [2] CRAN (R 3.5.1)
##  Biobase                           * 2.42.0    2018-12-03 [2] Bioconductor  
##  BiocGenerics                      * 0.28.0    2018-12-03 [2] Bioconductor  
##  BiocManager                         1.30.4    2018-11-13 [2] CRAN (R 3.5.1)
##  BiocParallel                        1.16.2    2018-12-03 [2] Bioconductor  
##  BiocStyle                         * 2.10.0    2018-12-03 [2] Bioconductor  
##  biomaRt                             2.38.0    2018-12-03 [2] Bioconductor  
##  Biostrings                          2.50.1    2018-12-03 [2] Bioconductor  
##  biovizBase                          1.30.0    2018-12-03 [2] Bioconductor  
##  bit                                 1.1-14    2018-05-29 [2] CRAN (R 3.5.1)
##  bit64                               0.9-7     2017-05-08 [2] CRAN (R 3.5.1)
##  bitops                              1.0-6     2013-08-17 [2] CRAN (R 3.5.1)
##  blob                                1.1.1     2018-03-25 [2] CRAN (R 3.5.1)
##  bookdown                            0.7       2018-02-18 [2] CRAN (R 3.5.1)
##  BSgenome                            1.50.0    2018-12-03 [2] Bioconductor  
##  bumphunter                        * 1.24.5    2018-12-03 [2] Bioconductor  
##  checkmate                           1.8.5     2017-10-24 [2] CRAN (R 3.5.1)
##  cli                                 1.0.1     2018-09-25 [2] CRAN (R 3.5.1)
##  cluster                             2.0.7-1   2018-04-13 [2] CRAN (R 3.5.1)
##  codetools                           0.2-15    2016-10-05 [2] CRAN (R 3.5.1)
##  colorspace                          1.3-2     2016-12-14 [2] CRAN (R 3.5.1)
##  crayon                              1.3.4     2017-09-16 [2] CRAN (R 3.5.1)
##  crosstalk                           1.0.0     2016-12-21 [2] CRAN (R 3.5.1)
##  curl                                3.2       2018-03-28 [2] CRAN (R 3.5.1)
##  data.table                          1.11.8    2018-09-30 [2] CRAN (R 3.5.1)
##  DBI                                 1.0.0     2018-05-02 [2] CRAN (R 3.5.1)
##  DEFormats                           1.10.0    2018-12-03 [2] Bioconductor  
##  DelayedArray                        0.8.0     2018-12-03 [2] Bioconductor  
##  derfinder                         * 1.16.1    2018-12-03 [2] Bioconductor  
##  derfinderHelper                     1.16.1    2018-12-03 [2] Bioconductor  
##  derfinderPlot                     * 1.16.1    2018-12-03 [2] Bioconductor  
##  DESeq2                              1.22.1    2018-12-03 [2] Bioconductor  
##  dichromat                           2.0-0     2013-01-24 [2] CRAN (R 3.5.1)
##  digest                              0.6.18    2018-10-10 [2] CRAN (R 3.5.1)
##  doRNG                               1.7.1     2018-06-22 [2] CRAN (R 3.5.1)
##  dplyr                               0.7.8     2018-11-10 [2] CRAN (R 3.5.1)
##  DT                                * 0.5       2018-11-05 [2] CRAN (R 3.5.1)
##  edgeR                               3.24.1    2018-12-03 [2] Bioconductor  
##  ensembldb                           2.6.3     2018-12-03 [2] Bioconductor  
##  evaluate                            0.12      2018-10-09 [2] CRAN (R 3.5.1)
##  foreach                           * 1.4.4     2017-12-12 [2] CRAN (R 3.5.1)
##  foreign                             0.8-71    2018-07-20 [2] CRAN (R 3.5.1)
##  Formula                             1.2-3     2018-05-03 [2] CRAN (R 3.5.1)
##  genefilter                          1.64.0    2018-12-03 [2] Bioconductor  
##  geneplotter                         1.60.0    2018-12-03 [2] Bioconductor  
##  GenomeInfoDb                      * 1.18.1    2018-12-03 [2] Bioconductor  
##  GenomeInfoDbData                    1.2.0     2018-10-06 [2] Bioconductor  
##  GenomicAlignments                   1.18.0    2018-12-03 [2] Bioconductor  
##  GenomicFeatures                   * 1.34.1    2018-12-03 [2] Bioconductor  
##  GenomicFiles                        1.18.0    2018-12-03 [2] Bioconductor  
##  GenomicRanges                     * 1.34.0    2018-12-03 [2] Bioconductor  
##  GGally                              1.4.0     2018-05-17 [2] CRAN (R 3.5.1)
##  ggbio                             * 1.30.0    2018-12-03 [2] Bioconductor  
##  ggplot2                           * 3.1.0     2018-10-25 [2] CRAN (R 3.5.1)
##  glue                                1.3.0     2018-07-17 [2] CRAN (R 3.5.1)
##  graph                               1.60.0    2018-12-03 [2] Bioconductor  
##  gridExtra                         * 2.3       2017-09-09 [2] CRAN (R 3.5.1)
##  gtable                              0.2.0     2016-02-26 [2] CRAN (R 3.5.1)
##  highr                               0.7       2018-06-09 [2] CRAN (R 3.5.1)
##  Hmisc                               4.1-1     2018-01-03 [2] CRAN (R 3.5.1)
##  hms                                 0.4.2     2018-03-10 [2] CRAN (R 3.5.1)
##  htmlTable                           1.12      2018-05-26 [2] CRAN (R 3.5.1)
##  htmltools                           0.3.6     2017-04-28 [2] CRAN (R 3.5.1)
##  htmlwidgets                         1.3       2018-09-30 [2] CRAN (R 3.5.1)
##  httpuv                              1.4.5     2018-07-19 [2] CRAN (R 3.5.1)
##  httr                                1.3.1     2017-08-20 [2] CRAN (R 3.5.1)
##  IRanges                           * 2.16.0    2018-12-03 [2] Bioconductor  
##  iterators                         * 1.0.10    2018-07-13 [2] CRAN (R 3.5.1)
##  jsonlite                            1.5       2017-06-01 [2] CRAN (R 3.5.1)
##  knitcitations                       1.0.8     2017-07-04 [2] CRAN (R 3.5.1)
##  knitr                             * 1.20      2018-02-20 [2] CRAN (R 3.5.1)
##  knitrBootstrap                      1.0.2     2018-05-24 [2] CRAN (R 3.5.1)
##  labeling                            0.3       2014-08-23 [2] CRAN (R 3.5.1)
##  later                               0.7.5     2018-09-18 [2] CRAN (R 3.5.1)
##  lattice                             0.20-38   2018-11-04 [2] CRAN (R 3.5.1)
##  latticeExtra                        0.6-28    2016-02-09 [2] CRAN (R 3.5.1)
##  lazyeval                            0.2.1     2017-10-29 [2] CRAN (R 3.5.1)
##  limma                               3.38.3    2018-12-03 [2] Bioconductor  
##  locfit                            * 1.5-9.1   2013-04-20 [2] CRAN (R 3.5.1)
##  lubridate                           1.7.4     2018-04-11 [2] CRAN (R 3.5.1)
##  magrittr                            1.5       2014-11-22 [2] CRAN (R 3.5.1)
##  markdown                            0.8       2017-04-20 [2] CRAN (R 3.5.1)
##  Matrix                              1.2-15    2018-11-01 [2] CRAN (R 3.5.1)
##  matrixStats                         0.54.0    2018-07-23 [2] CRAN (R 3.5.1)
##  memoise                             1.1.0     2017-04-21 [2] CRAN (R 3.5.1)
##  mgcv                              * 1.8-26    2018-11-21 [2] CRAN (R 3.5.1)
##  mime                                0.6       2018-10-05 [2] CRAN (R 3.5.1)
##  munsell                             0.5.0     2018-06-12 [2] CRAN (R 3.5.1)
##  nlme                              * 3.1-137   2018-04-07 [2] CRAN (R 3.5.1)
##  nnet                                7.3-12    2016-02-02 [2] CRAN (R 3.5.1)
##  org.Hs.eg.db                      * 3.7.0     2018-12-03 [2] Bioconductor  
##  OrganismDbi                         1.24.0    2018-12-03 [2] Bioconductor  
##  pillar                              1.3.0     2018-07-14 [2] CRAN (R 3.5.1)
##  pkgconfig                           2.0.2     2018-08-16 [2] CRAN (R 3.5.1)
##  pkgmaker                            0.27      2018-05-25 [2] CRAN (R 3.5.1)
##  plyr                                1.8.4     2016-06-08 [2] CRAN (R 3.5.1)
##  prettyunits                         1.0.2     2015-07-13 [2] CRAN (R 3.5.1)
##  progress                            1.2.0     2018-06-14 [2] CRAN (R 3.5.1)
##  promises                            1.0.1     2018-04-13 [2] CRAN (R 3.5.1)
##  ProtGenerics                        1.14.0    2018-12-03 [2] Bioconductor  
##  purrr                               0.2.5     2018-05-29 [2] CRAN (R 3.5.1)
##  qvalue                              2.14.0    2018-12-03 [2] Bioconductor  
##  R6                                  2.3.0     2018-10-04 [2] CRAN (R 3.5.1)
##  RBGL                                1.58.1    2018-12-03 [2] Bioconductor  
##  RColorBrewer                      * 1.1-2     2014-12-07 [2] CRAN (R 3.5.1)
##  Rcpp                                1.0.0     2018-11-07 [2] CRAN (R 3.5.1)
##  RCurl                               1.95-4.11 2018-07-15 [2] CRAN (R 3.5.1)
##  RefManageR                          1.2.0     2018-04-25 [2] CRAN (R 3.5.1)
##  regionReport                      * 1.16.1    2018-12-03 [1] Bioconductor  
##  registry                            0.5       2017-12-03 [2] CRAN (R 3.5.1)
##  reshape                             0.8.8     2018-10-23 [2] CRAN (R 3.5.1)
##  reshape2                            1.4.3     2017-12-11 [2] CRAN (R 3.5.1)
##  rlang                               0.3.0.1   2018-10-25 [2] CRAN (R 3.5.1)
##  rmarkdown                           1.10      2018-06-11 [2] CRAN (R 3.5.1)
##  rngtools                            1.3.1     2018-05-15 [2] CRAN (R 3.5.1)
##  rpart                               4.1-13    2018-02-23 [2] CRAN (R 3.5.1)
##  rprojroot                           1.3-2     2018-01-03 [2] CRAN (R 3.5.1)
##  Rsamtools                           1.34.0    2018-12-03 [2] Bioconductor  
##  RSQLite                             2.1.1     2018-05-06 [2] CRAN (R 3.5.1)
##  rstudioapi                          0.8       2018-10-02 [2] CRAN (R 3.5.1)
##  rtracklayer                         1.42.1    2018-12-03 [2] Bioconductor  
##  S4Vectors                         * 0.20.1    2018-12-03 [2] Bioconductor  
##  scales                              1.0.0     2018-08-09 [2] CRAN (R 3.5.1)
##  sessioninfo                       * 1.1.1     2018-11-05 [2] CRAN (R 3.5.1)
##  shiny                               1.2.0     2018-11-02 [2] CRAN (R 3.5.1)
##  stringi                             1.2.4     2018-07-20 [2] CRAN (R 3.5.1)
##  stringr                             1.3.1     2018-05-10 [2] CRAN (R 3.5.1)
##  SummarizedExperiment                1.12.0    2018-12-03 [2] Bioconductor  
##  survival                            2.43-3    2018-11-26 [2] CRAN (R 3.5.1)
##  tibble                              1.4.2     2018-01-22 [2] CRAN (R 3.5.1)
##  tidyselect                          0.2.5     2018-10-11 [2] CRAN (R 3.5.1)
##  TxDb.Hsapiens.UCSC.hg19.knownGene * 3.2.2     2018-07-26 [2] Bioconductor  
##  VariantAnnotation                   1.28.3    2018-12-03 [2] Bioconductor  
##  whisker                           * 0.3-2     2013-04-28 [2] CRAN (R 3.5.1)
##  withr                               2.1.2     2018-03-15 [2] CRAN (R 3.5.1)
##  xfun                                0.4       2018-10-23 [2] CRAN (R 3.5.1)
##  XML                                 3.98-1.16 2018-08-19 [2] CRAN (R 3.5.1)
##  xml2                                1.2.0     2018-01-24 [2] CRAN (R 3.5.1)
##  xtable                              1.8-3     2018-08-29 [2] CRAN (R 3.5.1)
##  XVector                             0.22.0    2018-12-03 [2] Bioconductor  
##  yaml                                2.2.0     2018-07-25 [2] CRAN (R 3.5.1)
##  zlibbioc                            1.28.0    2018-12-03 [2] Bioconductor  
## 
## [1] /tmp/Rtmpk99QfU/Rinst21f43dbdd5a4
## [2] /home/biocbuild/bbs-3.8-bioc/R/library