Contents

1 TL;DR (Too long; didn’t read)

e <- enrichR(treatment = "ChIP.bam",
             control   = "Control.bam",
             genome    = "hg19")
de <- diffR(treatment = "ChIP1.bam",
            control   = "ChIP2.bam",
            genome    = "hg19")
re <- regimeR(treatment = "ChIP.bam",
              control   = "Control.bam",
              genome    = "hg19",
              models    = k)
#export enriched regions with FDR<=10% for downstream analysis
exportR(obj      = e,
        filename = "enriched.bed",
        type     = "bed",
        fdr      = 0.1)
#or
#write normalized differential enrichment to bigWig for genome browser display
exportR(obj      = de,
        filename = "diffEnrichment.bw",
        type     = "bigWig")
citation("normr")
## 
## To cite package 'normr' in publications use:
## 
##   Johannes Helmuth and Ho-Ryun Chung (2016). normr: Normalization
##   and difference calling in ChIP-seq data. R package version
##   1.2.0. https://github.com/your-highness/normR
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {normr: Normalization and difference calling in ChIP-seq data},
##     author = {Johannes Helmuth and Ho-Ryun Chung},
##     year = {2016},
##     note = {R package version 1.2.0},
##     url = {https://github.com/your-highness/normR},
##   }

2 Introduction to normR

Chromatin immunoprecipitation followed by sequencing (ChIP-seq) provides genome-wide localization data for DNA-associated proteins. To infer the regions bound by such proteins the read densities obtained by such a ChIP-seq experiment are compared to the corresponding read profile obtained by a control experiment. A meaningful comparison requires normalization to mitigate the effects of technical biases, e.g. different sequencing depth. But more importantly the effect of the enrichment of certain regions on the overall read statistics. Normalization requires knowledge of the regions that remained unchanged, such that normalization and difference calling are inseparable.

This package, normR (normR obeys regime mixture Rules), follows this logic and performs normalization and difference calling simultaneously to identify genomic regions enriched by the ChIP-procedure (enrichR()). In addition, normR enables the comparison between ChIP-seq data obtained from different conditions allowing for unraveling genomic regions that change their association with the ChIP-target (diffR()). Lastly, normR is capable to differentiate multiple regimes of enrichment, i.e. broad domains and sharp peaks (regimeR()). In brief, all these routines encompass three steps:

  1. Count reads in fixed-size windows along the genome;
  2. Fit a binomial mixture model by Expectation Maximization;
  3. Assign each window a significance based on the fitted background component.

This vignette explains a common workflow of normR analysis on NGS data for calling enrichment, identification of differential ChIP-seq enrichment and stratification of enrichment regimes. Herein, we provide examples for the export of results to common data formats like bigWig and bed. We show how analysis statistics and diagnostic plots are helpful for studying results. In a latter section, we cover more advanced topics including the alteration of read counting strategies, the application of normR on user-defined regions (e.g. promoters) and the integration of Copy Number Variation information in differential ChIP-seq enrichment calls.

3 Toy Examples

3.1 enrichR(): Calling Enrichment with an Input Control

In this first section, we would like to call regions significantly enriched for reads in the ChIP-seq experiment given a Control alignment. Here, we analyze ChIP-seq data for both H3K4me3 (pointy enrichment) and H3K36me3 (broad enrichment) given an Input-seq control alignment originating from a human immortalized myelogenous leukemia line (K562). Using normR, we show that our representative region on human chromsome 1 (chr1:22500000-25000000) is enriched for H3K4me3 mostly at promoters and precludes H3K36me3 enrichment which is overrepresented in gene bodies.

IGV browser shot of Input (grey), H3K4me3 (green) and H3K36me3 (purple) alignment data on chr1 22.5Mb to 25Mb with genes (black) drawn.

As part of the normR package, we provide 3 alignment files in bam format (Input, H3K4me3 and H3K36me3 ChIP-seq) containing reads for human chr1 22.5Mb to 25Mb. Note, bam files used in normR need to be sorted by read coordinates (samtools sort x.bam x_sorted) and indexed (samtools index x_sorted.bam). Our example files already fullfil this criteria.

Firstly, we retrieve filepaths for toy data:

#Loading required package
library("normr")

inputBamfile <- system.file("extdata", "K562_Input.bam", package="normr")
k4me3Bamfile <- system.file("extdata", "K562_H3K4me3.bam", package="normr")
k36me3Bamfile <- system.file("extdata", "K562_H3K36me3.bam", package="normr")

Secondly and lastly, we need to specify the genome of the alignment. The genome argument can be a character specifying a UCSC genome identifier, e.g. “hg19”, or we can provide a 2-dimensional data.frame with columns seqnames and length. We will follow the later option: You can generate a genome data.frame yourself or can use GenomeInfoDb for retrieving the data.frame from UCSC for given genome identifier:

#Fetch chromosome information
genome <- GenomeInfoDb::fetchExtendedChromInfoFromUCSC("hg19")

#Filter out irregular chromosomes and delete unnecessary columns
idx <- which(!genome$circular & genome$SequenceRole=="assembled-molecule")
genome <- genome[idx,1:2]
genome
##    UCSC_seqlevel UCSC_seqlength
## 1           chr1      249250621
## 2           chr2      243199373
## 3           chr3      198022430
## 4           chr4      191154276
## 5           chr5      180915260
## 6           chr6      171115067
## 7           chr7      159138663
## 8           chr8      146364022
## 9           chr9      141213431
## 10         chr10      135534747
## 11         chr11      135006516
## 12         chr12      133851895
## 13         chr13      115169878
## 14         chr14      107349540
## 15         chr15      102531392
## 16         chr16       90354753
## 17         chr17       81195210
## 18         chr18       78077248
## 19         chr19       59128983
## 20         chr20       63025520
## 21         chr21       48129895
## 22         chr22       51304566
## 23          chrX      155270560
## 24          chrY       59373566
#Toy data has only "chr1"
genome <- genome[genome[,1] == "chr1",]
genome
##   UCSC_seqlevel UCSC_seqlength
## 1          chr1      249250621

Now, we are all set to do a enrichment call with default parameters:

#Enrichment Calling for H3K4me3 and H3K36me3
k4me3Fit <- enrichR(treatment = k4me3Bamfile, control = inputBamfile,
                    genome = genome, verbose = FALSE)
k36me3Fit <- enrichR(treatment = k36me3Bamfile, control = inputBamfile,
                     genome = genome, verbose = FALSE)

That was easy and fast! You must know that all results are stored as NormRFit-class objects. They provide convenient access to count data and fitting results. For example, let’s have a look at some simple fitting statistics for H3K4me3:

k4me3Fit
## NormRFit-class object
## 
##  Type:                    enrichR 
##  Number of Regions:       997003 
##  Theta* (naive bg):       0.3928 
##  Background component B:  1 
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background     Class 1  
##    94.997%      5.003%   
## Theta:
## Background     Class 1  
##    0.09148     0.92761

The “Type” of the NormRFit object is defined by the function generating it, i.e. enrichR(), diffR() or regimeR(). The “Number of Regions” is the number of 250bp bins along the specified genome (default binsize). The “Number of Components” is 2 (background and enriched) in the case of enrichR(). The parameter \(\theta^*\) (“Theta* (naive bg)”) describes a naive background parametrization if the effect of enrichment is not taken into account. The actual \(\theta_B\) is with \(0.09\) much smaller than \(\theta^*\) which allows for more sensitive enrichment calling. Furthermore, by looking at the “Mixture Proportions” we find H3K4me3 is enriched in 5.00% of the windows. For H3K36me3, we find 23.25% of the regions enriched.

k36me3Fit
## NormRFit-class object
## 
##  Type:                    enrichR 
##  Number of Regions:       997003 
##  Theta* (naive bg):       0.5143 
##  Background component B:  1 
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background     Class 1  
##     76.75%      23.25%   
## Theta:
## Background     Class 1  
##     0.1131      0.8383

3.1.1 Analyzing Results

We can use some methods provided by the NormRFit-class to get a grasp on the quality of our normR call, e.g. print a more concise summary that gives the number of significant regions under different False Discovery Rates (\(FDR\)).

summary(k4me3Fit)
## NormRFit-class object
## 
## Type:                  'enrichR'
## Number of Regions:     997003
## Number of Components:  2
## Theta* (naive bg):     0.393
## Background component B: 1
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background       Class 1    
##        95%            5%    
## Theta:
## Background       Class 1    
##     0.0915        0.9276    
## 
## Bayesian Information Criterion:  73401
## 
## +++ Results of binomial test +++ 
## T-Filter threshold: 8
## Number of Regions filtered out: 991635
## Significantly different from background B based on q-values:
## TOTAL:
##            ***        **         *         .                n.s.
## Bins        24       435        62        65        59      4723
## %        0.345     6.597     7.488     8.422     9.270    67.879
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 '  ' 1 'n.s.'

Note, summary() prints an additional section containing information on the statistical testing. The “T-Filter threshold” filters out regions that are not considered for multiple testing correction due to low power. The sum of counts in treatment and control is less than this quantity (Dialsingh et al., Bioinformatics, 2015, 1–7). The “Number of Regions filtered out” is very large in our example because the toy alignment files are filtered for reads within chr1 22.5Mb to 25Mb. However, the specified genome covers chr1:0-249250621 which results in alot of zero counts. This does not influence the fit but for testing the regions are filtered. Based on computed q-vlaues, H3K4me3 shows 586 (24+435+62+65) regions significantly enriched for \(FDR \le 0.05\). The summary for H3K36me3 enrichment calls confirms 2,259 (0+1944+153+162) regions significantly enriched for \(FDR \le 0.05\):

summary(k36me3Fit)
## NormRFit-class object
## 
## Type:                  'enrichR'
## Number of Regions:     997003
## Number of Components:  2
## Theta* (naive bg):     0.514
## Background component B: 1
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background       Class 1    
##      76.7%         23.3%    
## Theta:
## Background       Class 1    
##      0.113         0.838    
## 
## Bayesian Information Criterion:  131166
## 
## +++ Results of binomial test +++ 
## T-Filter threshold: 9
## Number of Regions filtered out: 991341
## Significantly different from background B based on q-values:
## TOTAL:
##          ***      **       *       .            n.s.
## Bins       0    1944     153     162      74    3329
## %        0.0    16.3    17.5    18.9    19.5    27.8
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 '  ' 1 'n.s.'

Based on the fitted background, normR can calculate a standardized, regularized enrichment for further processing:

#background normalized enrichment
k4me3Enr <- getEnrichment(k4me3Fit)

#restrict to regions with non-zero counts
idx <- which(rowSums(do.call(cbind, getCounts(k4me3Fit))) != 0)
summary(k4me3Enr[idx])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1.2590 -0.9680 -0.7688 -0.4050  0.1409  2.0151

If we compare H3K4me3 and H3K36me3 enrichment in non-zero regions, we can see some mutual exclusivity of both marks represented by off-diagonal elements):

x <- k4me3Enr[idx]
y <- getEnrichment(k36me3Fit)[idx]
d.x <- density(x); d.y <- density(y)
limits <- range(x,y)
layout( matrix( c(0,2,2,1,3,3,1,3,3),ncol=3) )
plot(d.x$x, d.x$y, xlim=limits, type='l',
     main="H3K36me3 normalized Enrichment", xlab="", ylab="Density")
abline(v=0, lty=3, lwd=2, col=4)
plot(d.y$y, d.y$x, ylim=limits, xlim=rev(range(d.y$y)), type='l',
     main="H3K4me3 normalized Enrichment", xlab="Density", ylab="")
abline(h=0, lty=3, lwd=2, col=4)
color <- rep("grey10", length(idx))
plot(x, y, xlim=limits, ylim=limits, pch=20, xlab="", ylab="",
     col=adjustcolor(color, alpha.f=.2))
abline(0, 1, lty=2, lwd=3, col=2)
abline(v=0, lty=3, lwd=2, col=4)
abline(h=0, lty=3, lwd=2, col=4)

To analyze mutually exclusivity of H3K4me3 and H3K36me3, we would like to recover the regions signficantly enriched in k4me3Fit and k36me3Fit and color these regions in the scatter plot above.

#integer vector with <NA> set to non-significant regions
k4me3Classes <- getClasses(k4me3Fit, fdr = 0.05)
k36me3Classes <- getClasses(k36me3Fit, fdr = 0.05)

#Color scatter plot based on enrichment
color[!is.na(k4me3Classes[idx])] <- "#2C9500"
color[!is.na(k36me3Classes[idx])] <- "#990099"
color[!is.na(k4me3Classes+k36me3Classes)[idx]] <- "#971621"
plot(x, y, xlim=limits, ylim=limits, pch=20,
     col=adjustcolor(color, alpha.f=.5), xlab="H3K4me3 normalized Enrichment",
     ylab="H3K36me3 normalized Enrichment")
legend("topright", pch=20, col=unique(color), cex=.6, bg="white",
  legend=c("Background", "H3K36me3 enriched", "H3K4me3 enriched",
           "H3K4me3/K36me3 enriched")
  )

Processing of regions within R can be facilitated by getting significantly enriched (\(FDR \le 0.05%\)) regions as a GRanges object:

k4me3Ranges <- getRanges(k4me3Fit)[!is.na(k4me3Classes)]
#Alternatively you can extract ranges without storing the class vector
k4me3Ranges <- getRanges(k4me3Fit, fdr = 0.05)

#as expected we get 586 regions
length(k4me3Ranges)
## [1] 586

As a representative analysis, we would like check for overrepresentation of enriched regions with genes and promoters by using Fisher’s exact test. Let’s start with H3K4me3:

#example gene annotation for representative region (chr1:22500000-25000000)
genes <- read.delim(file = system.file("extdata", "genes.bed",package="normr"),
                    header = FALSE, stringsAsFactors = FALSE)
library("GenomicRanges")
genes <- GRanges(seqnames = genes[, 1],
                 ranges = IRanges(start = genes[, 2], end = genes[, 3]),
                 strand = genes[, 6],
                 ENSTID = genes[, 4])
genes <- unique(genes)

#Fisher-test provides significance of overlap
#(total specifies number of bins in representative region)
overlapOdds <- function(query, subject, total = 10000) {
  subject <- reduce(subject, ignore.strand = TRUE)
  ov1 <- countOverlaps(query, subject)
  m <- matrix(c(sum(ov1 != 0), sum(ov1 == 0),
              ceiling(sum(width(subject))/width(query)[1]-sum(ov1 != 0)), 0),
              ncol = 2)
  m[2,2] <- total - sum(m)
  fisher.test(m, alternative="greater")
}

#Overlap of H3K4me3 with genes
overlapOdds(k4me3Ranges, genes)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value = 1.128e-08
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  1.419849      Inf
## sample estimates:
## odds ratio 
##   1.656686
#Overlap of H3K4me3 with promoters
promoters <- promoters(genes, upstream = 2000, downstream = 2000)
overlapOdds(k4me3Ranges, promoters)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  6.589435      Inf
## sample estimates:
## odds ratio 
##   7.651284

It is known that promoters are marked by H3K4me3 if their gene’s expression is initiated. Our analysis above shows that H3K4me3-enriched regions are indeed significantly overrepresented within genes (Fisher’s signed-exact test; P<0.001; odds ratio = 1.65) and, more pronounced, in promoter regions (odds ratio = 7.65).

By comparing H3K36me3 and H3K4me3 ranges, we can identify significant overlap of H3K36me3 and H3K4me3 that most pronounced in promoter regions (odds ratio = 8.81) than compared to gene bodies (odds ratio = 2.66).

#Overlap of H3K36me3 with H3K4me3
k36me3Ranges <- getRanges(k36me3Fit, fdr = 0.05)
overlapOdds(k36me3Ranges, k4me3Ranges)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value = 3.539e-05
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  1.254101      Inf
## sample estimates:
## odds ratio 
##   1.471461
#Overlap of H3K36me3 with H3K4me3 at promoter regions
overlapOdds(k36me3Ranges[countOverlaps(k36me3Ranges, promoters) != 0],
            k4me3Ranges[countOverlaps(k4me3Ranges, promoters) != 0])
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  7.184033      Inf
## sample estimates:
## odds ratio 
##   8.805401
#Overlap of H3K36me3 with H3K4me3 in genes
overlapOdds(k36me3Ranges[countOverlaps(k36me3Ranges, genes) != 0],
            k4me3Ranges[countOverlaps(k4me3Ranges, genes) != 0])
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  2.219849      Inf
## sample estimates:
## odds ratio 
##   2.659387

H3K36me3 is associated to transcriptional elongation in the gene body. The presence of H3K36me3 within the gene body marks transcribed genes. Indeed, H3K36me3 enrichment is significantly overrepresented mostly at genes (odds ratio = 5.59) and, to a lower extend, at promoters (odds ratio = 2.76).

#Overlap of H3K36me3 in genes
overlapOdds(k36me3Ranges, genes)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  5.036229      Inf
## sample estimates:
## odds ratio 
##   5.594477
#Overlap of H3K36me3 with promoters
overlapOdds(k36me3Ranges, promoters(genes, 1500, 1500))
## 
##  Fisher's Exact Test for Count Data
## 
## data:  m
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is greater than 1
## 95 percent confidence interval:
##  2.498577      Inf
## sample estimates:
## odds ratio 
##   2.762093

3.1.2 Exporting Results

While there exist a plethora of analysis options of normR results within R, exportR() provides functionality to write results to a file. To export coordinates of enriched regions, the widely used BED format is applicable. It is human-readable and can be imported in common genome browsers, e.g. UCSC genome browser or IGV. To export the background-normalized enrichment, the binary bigWig format is used. Check ?exportR for more options.

#export coordinates of significantly (FDR <= 0.05) enriched regions
exportR(k4me3Fit, filename = "k4me3Fit.bed", type = "bed", fdr = 0.05)
exportR(k36me3Fit, filename = "k36me3Fit.bed", type = "bed", fdr = 0.05)

#export background-normalized enrichment
exportR(k4me3Fit, filename = "k4me3Fit.bw", type = "bigWig")
exportR(k36me3Fit, filename = "k36me3Fit.bw", type = "bigWig")

IGV browser shot of Input (grey), H3K4me3 (green) and H3K36me3 (purple) alignment data (bars), normalized enrichment, i.e. “bigWig” files, (lines) and enriched regions, i.e. “bed” files (boxes below respective tracks).

3.2 diffR(): Calling Differential Enrichment without a Control Experiment

Normalization and difference calling are inseparable in calling ChIP-seq enrichment. Following this notion, a direct comparison of two ChIP-seq tracks can be performed with diffR(). In many studies, researchers are interested in conditional changes in ChIP-seq enrichment. Below, we exemplify this analysis by joint analysis of H3K4me3 and H3K36me3 ChIP-seq data. Because we already counted k4me3Bamfile and k36me3Bamfile already in k4me3Fit and k36me3Fit, respectively, we can use these counts directly. Note that, in this case, the genome has be set to a GenomicRanges object specifying the genomic regions. We can extract this from either one of the NormRFit objects.

#We could use read counts from above NormRFit objects
k4k36Dif <- diffR(treatment = getCounts(k4me3Fit)$treatment,
                  control   = getCounts(k36me3Fit)$treatment,
                  genome    = getRanges(k4me3Fit),
                  verbose   = FALSE)
#<or> (unnecessarily) count again
#k4k36Dif <- diffR(treatment = k4me3Bamfile, control = k36me3Bamfile,
#                  genome = genome, verbose = FALSE)

#summary statistics
summary(k4k36Dif)
## NormRFit-class object
## 
## Type:                  'diffR'
## Number of Regions:     997003
## Number of Components:  3
## Theta* (naive bg):     0.379
## Background component B: 2
## 
## +++ Results of fit +++ 
## Mixture Proportions:
##    Class 1    Background       Class 2    
##      49.8%         29.5%         20.7%    
## Theta:
##    Class 1    Background       Class 2    
##     0.0183        0.4798        0.9726    
## 
## Bayesian Information Criterion:  48069
## 
## +++ Results of binomial test +++ 
## T-Filter threshold: 18
## Number of Regions filtered out: 995349
## Significantly different from background B based on q-values:
## TOTAL:
##          ***      **       *       .            n.s.
## Bins       0    1624      24       6       0       0
## %        0.0    24.7    25.0    25.1    25.1     0.0
## Class 1:
##            ***        **         *         .                n.s.
## Bins         0      1341        15         2         0       296
## %        0.000    81.076     0.907     0.121     0.000    17.896
## Class 2:
##            ***        **         *         .                n.s.
## Bins         0       283         9         4         0      1358
## %        0.000    17.110     0.544     0.242     0.000    82.104
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 '  ' 1 'n.s.'

The “Type” of the object has changed to ‘diffR’ because it was generated by this function. The “Number of Regions” did not change because we use the same binning strategy. However, the “Number of Components” is now 3 representing (i) H3K36me3 enrichment without H3K4me3-enrichment, (ii) H3K36me3 and H3K4me3 (non)-enriched and (iii) H3K4me3 enrichment without H3K36me3-enrichment. The “Backgroundcomponent B” is 2 in this case: diffR() identifies significant enrichment and depletion by a two-sided test on the background. Looking at the “Mixture Proportions”, regions are classified to (i) in 49.8%, (ii) in 29.5% and (iii) in 20.7% of the regions. 1,654 (0+1624+24+6) regions are significantly different from background with \(FDR \le 0.05\). These regions are either H3K4me3-positive or H3K36me3 positive. We can export these regions and the normalized enrichment with exportR:

exportR(k4k36Dif, filename = "k4k36Dif.bed", type = "bed", fdr = 0.05)
exportR(k4k36Dif, filename = "k4k36Dif.bw", type = "bigWig")

IGV browser shot of Input (grey), H3K4me3 (green) and H3K36me3 (purple) alignment data. Background normalized difference is plotted as a heatmap, i.e. “bigWig” file, and differential regions are plotted as boxes, i.e. “bed” file (blue: treatment (H3K4me3) enriched, red: control (H3K36me3) enriched).

3.3 regimeR(): Identify Enrichment Regimes in ChIP-seq Experiments

The two sections above aimed at discerning enrichment from background. The extendable normR approach also allows for identification of different enrichment regimes with regimeR() by increasing the number of model components.

Let’s start with 3 components (Background + 2 Enrichment Regimes) for H3K4me3. By using two enrichment regimes, we may uncover effects of sample heterogeneity affecting transcriptional initiation of certian genes.

k4me3Regimes <- regimeR(treatment = getCounts(k4me3Fit)$treatment,
                         control   = getCounts(k4me3Fit)$control,
                         genome    = getRanges(k4me3Fit),
                         models    = 3,
                         verbose   = FALSE)
summary(k4me3Regimes)
## NormRFit-class object
## 
## Type:                  'regimeR'
## Number of Regions:     997003
## Number of Components:  3
## Theta* (naive bg):     0.393
## Background component B: 1
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background       Class 1       Class 2    
##     89.58%         7.64%         2.78%    
## Theta:
## Background       Class 1       Class 2    
##     0.0691        0.5496        0.9547    
## 
## Bayesian Information Criterion:  69872
## 
## +++ Results of binomial test +++ 
## T-Filter threshold: 7
## Number of Regions filtered out: 990754
## Significantly different from background B based on q-values:
## TOTAL:
##           ***       **        *        .              n.s.
## Bins       41      459       70      112       79     5488
## %        0.51     6.22     7.09     8.48     9.46    68.24
## Class 1:
##           ***       **        *        .              n.s.
## Bins        0      261       70      112       79     5727
## %        0.00     4.18     1.12     1.79     1.26    91.65
## Class 2:
##            ***        **         *         .                n.s.
## Bins        41       198         0         0         0      6010
## %        0.656     3.169     0.000     0.000     0.000    96.175
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 '  ' 1 'n.s.'

10.42% of the regions show enrichment which gets segmented into 7.64% low and 2.78% high enrichment. 682 (41+459+70+112) regions are significant (\(FDR \le 0.05\)).

Now, we would like to use two enrichment regimes for H3K36me3. In this way, we might be able to classify genes of low and high transcriptional rates:

k36me3Regimes <- regimeR(treatment = getCounts(k36me3Fit)$treatment,
                         control   = getCounts(k36me3Fit)$control,
                         genome    = getRanges(k36me3Fit),
                         models    = 3,
                         verbose   = FALSE)
summary(k36me3Regimes)
## NormRFit-class object
## 
## Type:                  'regimeR'
## Number of Regions:     997003
## Number of Components:  3
## Theta* (naive bg):     0.514
## Background component B: 1
## 
## +++ Results of fit +++ 
## Mixture Proportions:
## Background       Class 1       Class 2    
##      69.2%         15.9%         14.9%    
## Theta:
## Background       Class 1       Class 2    
##     0.0776        0.5443        0.8858    
## 
## Bayesian Information Criterion:  126538
## 
## +++ Results of binomial test +++ 
## T-Filter threshold: 8
## Number of Regions filtered out: 990557
## Significantly different from background B based on q-values:
## TOTAL:
##          ***      **       *       .            n.s.
## Bins       0    2108     184     217     121    3816
## %        0.0    15.8    17.2    18.8    19.7    28.6
## Class 1:
##           ***       **        *        .              n.s.
## Bins        0      797      184      217      121     5127
## %        0.00    12.36     2.85     3.37     1.88    79.54
## Class 2:
##          ***      **       *       .            n.s.
## Bins       0    1311       0       0       0    5135
## %        0.0    20.3     0.0     0.0     0.0    79.7
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 '  ' 1 'n.s.'

We can now export the called regimes as bed files for browser display. Each track has two enrichment regimes which are shaded for their degree of significance. The export is done analogously to the cases described above:

exportR(k4me3Regimes, filename = "k4me3Regimes.bed", type = "bed", fdr=0.05)
exportR(k36me3Regimes, filename = "k36me3Regimes.bed", type = "bed", fdr=0.05)

IGV browser shot of Input (grey), H3K4me3 (green) and H3K36me3 (purple) alignment data. Regime calls are plotted as boxes below respective tracks (Yellow = low enrichment, Pink = high enrichment)

4 Advanced Topics

In addition to the information covered above, it is recommend to have a look at help pages (?) of normR functions. Here, we would like to discuss three important points:

4.1 Change Read Counting Strategy with NormRCountConfig-class

It is very important how we count reads contained in the bamfile. The NormRCountConfig-class provides methods to define the counting strategy on single-end and paired-end alignment data:

#Single End:
# Count in 500bp bins.
# Consider only reads with Mapping Quality >= 20.
# Filter reads for marked duplicates (e.g. with picard mark-duplicates)
# Shift the counting position for a read 100 bp downstream.
countConfigSE <- countConfigSingleEnd(binsize = 500, mapq = 20,
                                      filteredFlag = 1024, shift = 100)

#Paired End:
# Count in 500bp bins.
# Consider only reads with Mapping Quality >= 30.
# Count the midpoint of the aligned fragment instead of 5' ends.
# Consider only reads corresponding to fragments with size from 100 to 300bp
countConfigPE <- countConfigPairedEnd(binsize = 500, mapq = 30, midpoint=TRUE,
                                      tlenFilter = c(100, 300))

#Plug in the counting configuration into normR, e.g. in enrichR()
fit <- enrichR(treatment   = k4me3Bamfile,
               control     = inputBamfile,
               genome      = genome,
               countConfig = countConfigPE)

4.2 Analyzing Predefined Regions

You could do a fit on a set of pre-defined regions like promoters or known transcription factor binding sites. You need to count beforehand with bamsignals. Note, for the fit to work correctly these regions should be of same size.

#regions have identical size?
all(width(promoters) == 4000)
## [1] TRUE
#count in predefined regions
library("bamsignals")
k4Counts <- bamCount(bampath = k4me3Bamfile, gr = promoters, verbose=FALSE)
inputCounts <- bamCount(bampath = inputBamfile, gr = promoters, verbose=FALSE)

#Fit only on promoters
promotersFit <- enrichR(treatment = k4Counts, control = inputCounts,
                        genome = promoters, verbose = FALSE)

4.3 Post-processing of Difference Calls with CNV information

Copy Number Variations (CNVs) are an important feature of cancerous cells like tumour samples. The difference calling on two ChIP-seq experiments with diffR() is sensitive to CNVs if the underlying sequence is amplified in the genome. However, you can harness diffR()’s functionality to call differences in two Input tracks to detect CNVs in a treatment respective to a control. To allow for coarse-grained detection of difference in Input, a sufficiently large binsize has to be used, e.g. 22kb.

cnvs <- diffR(treatment   = treatmentInputBamfile,
              control     = controlInputBamfile,
              genome      = genome,
              countConfig = countConfigSingleEnd(binsize = 2.5e4))

#export the CNV calls
exportR(cnvs, "CNVs.bed")

#Filter previous ChIP-seq difference calls for CNVs
ov <- countOverlaps(getRanges(diffFit, fdr = .05), getRanges(cnvs, fdr = .05))
idx <- which(ov == 0)
cnvCleanedGR <- getRanges(diffFit, fdr = .05)[idx]