Here, we perform a window-based DB analysis to identify differentially bound (DB) regions for CREB-binding protein (CBP). This provides an example of how to use csaw for transcription factor (TF) data, complementing our previous analysis on a histone mark. We use CBP ChIP-seq data from a study comparing wild-type (WT) and CBP knock-out (KO) animals (Kasper et al. 2014), with two biological replicates for each genotype. BAM files and indices are downloaded using chipseqDBData and cached for later use.
library(chipseqDBData)
cbpdata <- CBPData()
cbpdata
## DataFrame with 4 rows and 3 columns
## Name Description Path
## <character> <character> <character>
## 1 SRR1145787 CBP wild-type (1) /tmp/RtmpYqutQs/file42a15b753d3e/SRR1145787.bam
## 2 SRR1145788 CBP wild-type (2) /tmp/RtmpYqutQs/file42a15b753d3e/SRR1145788.bam
## 3 SRR1145789 CBP knock-out (1) /tmp/RtmpYqutQs/file42a15b753d3e/SRR1145789.bam
## 4 SRR1145790 CBP knock-out (2) /tmp/RtmpYqutQs/file42a15b753d3e/SRR1145790.bam
We check some mapping statistics for the CBP dataset with Rsamtools, as previously described.
library(Rsamtools)
diagnostics <- list()
for (bam in cbpdata$Path) {
total <- countBam(bam)$records
mapped <- countBam(bam, param=ScanBamParam(
flag=scanBamFlag(isUnmapped=FALSE)))$records
marked <- countBam(bam, param=ScanBamParam(
flag=scanBamFlag(isUnmapped=FALSE, isDuplicate=TRUE)))$records
diagnostics[[basename(bam)]] <- c(Total=total, Mapped=mapped, Marked=marked)
}
diag.stats <- data.frame(do.call(rbind, diagnostics))
diag.stats$Prop.mapped <- diag.stats$Mapped/diag.stats$Total*100
diag.stats$Prop.marked <- diag.stats$Marked/diag.stats$Mapped*100
diag.stats
## Total Mapped Marked Prop.mapped Prop.marked
## SRR1145787.bam 28525952 24289396 2022868 85.14842 8.328194
## SRR1145788.bam 25514465 21604007 1939224 84.67356 8.976224
## SRR1145789.bam 34476967 29195883 2412650 84.68228 8.263665
## SRR1145790.bam 32624587 27348488 2617879 83.82784 9.572299
We construct a readParam
object to standardize the parameter settings in this analysis.
The ENCODE blacklist is again used1 Assuming you ran the previous workflow, this will be retrieved from cache rather than being downloaded again. to remove reads in problematic regions (ENCODE Project Consortium 2012).
library(BiocFileCache)
bfc <- BiocFileCache("local", ask=FALSE)
black.path <- bfcrpath(bfc, file.path("https://www.encodeproject.org",
"files/ENCFF547MET/@@download/ENCFF547MET.bed.gz"))
library(rtracklayer)
blacklist <- import(black.path)
We set the minimum mapping quality score to 10 to remove poorly or non-uniquely aligned reads.
library(csaw)
param <- readParam(minq=10, discard=blacklist)
param
## Extracting reads in single-end mode
## Duplicate removal is turned off
## Minimum allowed mapping score is 10
## Reads are extracted from both strands
## No restrictions are placed on read extraction
## Reads in 164 regions will be discarded
The average fragment length is estimated by maximizing the cross-correlation function (Figure 1), as previously described. Generally, cross-correlations for TF datasets are sharper than for histone marks as the TFs typically contact a smaller genomic interval. This results in more pronounced strand bimodality in the binding profile.
x <- correlateReads(cbpdata$Path, param=reform(param, dedup=TRUE))
frag.len <- maximizeCcf(x)
frag.len
## [1] 161
plot(1:length(x)-1, x, xlab="Delay (bp)", ylab="CCF", type="l")
abline(v=frag.len, col="red")
text(x=frag.len, y=min(x), paste(frag.len, "bp"), pos=4, col="red")
Reads are then counted into sliding windows using csaw (Lun and Smyth 2015). For TF data analyses, smaller windows are necessary to capture sharp binding sites. A large window size will be suboptimal as the count for a particular site will be “contaminated” by non-specific background in the neighbouring regions. In this case, a window size of 10 bp is used.
win.data <- windowCounts(cbpdata$Path, param=param, width=10, ext=frag.len)
win.data
## class: RangedSummarizedExperiment
## dim: 9952827 4
## metadata(6): spacing width ... param final.ext
## assays(1): counts
## rownames: NULL
## rowData names(0):
## colnames: NULL
## colData names(4): bam.files totals ext rlen
The default spacing of 50 bp is also used here.
This may seem inappropriate given that the windows are only 10 bp.
However, reads lying in the interval between adjacent windows will still be counted into several windows.
This is because reads are extended to the value of frag.len
, which is substantially larger than the 50 bp spacing2 Smaller spacings can be used but will provide little benefit given that each extended read already overlaps multiple windows..
Composition biases are introduced when the amount of DB in each condition is unbalanced (Robinson and Oshlack 2010; Lun and Smyth 2014). More binding in one condition means that more reads are sequenced at the binding sites, leaving fewer reads for the rest of the genome. This suppresses the genomic coverage at non-DB sites, resulting in spurious differences between samples. We expect unbalanced DB in this dataset as CBP function should be compromised in the KO cells, such that most - if not all - of the DB sites should exhibit increased CBP binding in the WT condition.
To remove this bias, we assign reads to large genomic bins and assume that most bins represent non-DB background regions.
Any systematic differences in the coverage of those bins is attributed to composition bias and is normalized out.
Specifically, the trimmed mean of M-values (TMM) method (Robinson and Oshlack 2010) is applied to compute normalization factors from the bin counts.
These factors are stored in win.data
3 See the se.out=
argument. so that they will be applied during the DB analysis with the window counts.
bins <- windowCounts(cbpdata$Path, bin=TRUE, width=10000, param=param)
win.data <- normFactors(bins, se.out=win.data)
(normfacs <- win.data$norm.factors)
## [1] 1.0125617 0.9083253 1.0443668 1.0410799
We visualize the effect of normalization with mean-difference plots between pairs of samples (Figure 2). The dense cloud in each plot represents the majority of bins in the genome. These are assumed to mostly contain background regions. A non-zero log-fold change for these bins indicates that composition bias is present between samples. The red line represents the log-ratio of normalization factors and passes through the centre of the cloud in each plot, indicating that the bias has been successfully identified and removed.
bin.ab <- scaledAverage(bins)
adjc <- calculateCPM(bins, use.norm.factors=FALSE)
par(cex.lab=1.5, mfrow=c(1,3))
smoothScatter(bin.ab, adjc[,1]-adjc[,4], ylim=c(-6, 6),
xlab="Average abundance", ylab="Log-ratio (1 vs 4)")
abline(h=log2(normfacs[1]/normfacs[4]), col="red")
smoothScatter(bin.ab, adjc[,2]-adjc[,4], ylim=c(-6, 6),
xlab="Average abundance", ylab="Log-ratio (2 vs 4)")
abline(h=log2(normfacs[2]/normfacs[4]), col="red")
smoothScatter(bin.ab, adjc[,3]-adjc[,4], ylim=c(-6, 6),
xlab="Average abundance", ylab="Log-ratio (3 vs 4)")
abline(h=log2(normfacs[3]/normfacs[4]), col="red")
Note that this normalization strategy is quite different from that in the H3K9ac analysis. Here, systematic DB in one direction is expected between conditions, given that CBP function is lost in the KO genotype. This means that the assumption of a non-DB majority (required for non-linear normalization of the H3K9ac data) is not valid. No such assumption is made by the binned-TMM approach described above, which makes it more appropriate for use in the CBP analysis.
Removal of low-abundance windows is performed as previously described, by computing the coverage in each window relative to a global estimate of background enrichment. The majority of windows in background regions are filtered out upon applying a modest fold-change threshold. This leaves a small set of relevant windows for further analysis.
filter.stat <- filterWindowsGlobal(win.data, bins)
min.fc <- 3
keep <- filter.stat$filter > log2(min.fc)
summary(keep)
## Mode FALSE TRUE
## logical 9653836 298991
filtered.data <- win.data[keep,]
Note that the 10 kbp bins are used here for filtering, while smaller 2 kbp bins were used in the corresponding step for the H3K9ac analysis. This is purely for convenience – the 10 kbp counts for this dataset were previously loaded for normalization, and can be re-used during filtering to save time. Changes in bin size will have little impact on the results, so long as the bins (and their counts) are large enough for precise estimation of the background abundance. While smaller bins provide greater spatial resolution, this is irrelevant for quantifying coverage in large background regions that span most of the genome.
Counts for each window are modelled using edgeR (McCarthy, Chen, and Smyth 2012; Robinson, McCarthy, and Smyth 2010).
We convert our RangedSummarizedExperiment
object into a DGEList
.
library(edgeR)
y <- asDGEList(filtered.data)
summary(y)
## Length Class Mode
## counts 1195964 -none- numeric
## samples 3 data.frame list
We then construct a design matrix for our experimental design. Again, we have a simple one-way layout with two groups of two replicates.
genotype <- cbpdata$Description
genotype[grep("wild-type", genotype)] <- "wt"
genotype[grep("knock-out", genotype)] <- "ko"
genotype <- factor(genotype)
design <- model.matrix(~0+genotype)
colnames(design) <- levels(genotype)
design
## ko wt
## 1 0 1
## 2 0 1
## 3 1 0
## 4 1 0
## attr(,"assign")
## [1] 1 1
## attr(,"contrasts")
## attr(,"contrasts")$genotype
## [1] "contr.treatment"
We estimate the negative binomial (NB) and quasi-likelihood (QL) dispersions for each window (Lund et al. 2012). The estimated NB dispersions (Figure 3) are substantially larger than those observed in the H3K9ac dataset. They also exhibit an unusual increasing trend with respect to abundance.
y <- estimateDisp(y, design)
summary(y$trended.dispersion)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.1196 0.1645 0.1843 0.1889 0.2159 0.2549
plotBCV(y)
The estimated prior d.f. is also infinite, meaning that all the QL dispersions are equal to the trend (Figure 4).
fit <- glmQLFit(y, design, robust=TRUE)
summary(fit$df.prior)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18260 Inf Inf Inf Inf Inf
plotQLDisp(fit)
These results are consistent with the presence of a systematic difference in CBP enrichment between the WT replicates. An increasing trend in Figure 3 is typical after normalization for composition biases, where replicates exhibit some differences in efficiency that manifest as increased dispersions at high abundance. The dispersions for all windows are inflated to a similarly large value by this difference, manifesting as low variability in the dispersions across windows. This effect is illustrated in Figure 5 where the WT samples are clearly separated in both dimensions.
plotMDS(cpm(y, log=TRUE), top=10000, labels=genotype,
col=c("red", "blue")[as.integer(genotype)])
The presence of a large batch effect between replicates is not ideal. Nonetheless, we can still proceed with the DB analysis - albeit with some loss of power due to the inflated NB dispersions - given that there are strong differences between genotypes in Figure 5,
We test for a significant difference in binding between genotypes in each window using the QL F-test.
contrast <- makeContrasts(wt-ko, levels=design)
res <- glmQLFTest(fit, contrast=contrast)
Windows less than 100 bp apart are clustered into regions (Lun and Smyth 2014) with a maximum cluster width of 5 kbp. We then control the region-level FDR by combining per-window \(p\)-values using Simes’ method (Simes 1986).
merged <- mergeResults(filtered.data, res$table, tol=100,
merge.args=list(max.width=5000))
merged$regions
## GRanges object with 61415 ranges and 0 metadata columns:
## seqnames ranges strand
## <Rle> <IRanges> <Rle>
## [1] chr1 3613551-3613610 *
## [2] chr1 4785501-4785860 *
## [3] chr1 4807601-4808010 *
## [4] chr1 4857451-4857910 *
## [5] chr1 4858301-4858460 *
## ... ... ... ...
## [61411] chrY 90808801-90808910 *
## [61412] chrY 90810901-90810910 *
## [61413] chrY 90811301-90811360 *
## [61414] chrY 90811601-90811660 *
## [61415] chrY 90811851-90813910 *
## -------
## seqinfo: 66 sequences from an unspecified genome
tabcom <- merged$combined
is.sig <- tabcom$FDR <= 0.05
summary(is.sig)
## Mode FALSE TRUE
## logical 59583 1832
All significant regions have increased CBP binding in the WT genotype. This is expected given that protein function should be lost in the KO genotype.
table(tabcom$direction[is.sig])
##
## up
## 1832
# Direction according the best window in each cluster.
tabbest <- merged$best
is.sig.pos <- (tabbest$rep.logFC > 0)[is.sig]
summary(is.sig.pos)
## Mode TRUE
## logical 1832
We save the results to file in the form of a serialized R object for later inspection.
out.ranges <- merged$regions
mcols(out.ranges) <- DataFrame(tabcom,
best.pos=mid(ranges(rowRanges(filtered.data[tabbest$rep.test]))),
best.logFC=tabbest$rep.logFC)
saveRDS(file="cbp_results.rds", out.ranges)
Annotation for each region is added using the detailRanges()
function,
as previously described.
library(TxDb.Mmusculus.UCSC.mm10.knownGene)
library(org.Mm.eg.db)
anno <- detailRanges(out.ranges, orgdb=org.Mm.eg.db,
txdb=TxDb.Mmusculus.UCSC.mm10.knownGene)
mcols(out.ranges) <- cbind(mcols(out.ranges), anno)
We will visualize one of the top-ranked DB regions here. This corresponds to a simple DB event as all windows are changing in the same direction, i.e., up in the WT. The binding region is also quite small relative to some of the H3K9ac examples, consistent with sharp TF binding to a specific recognition site.
o <- order(out.ranges$PValue)
cur.region <- out.ranges[o[2]]
cur.region
## GRanges object with 1 range and 13 metadata columns:
## seqnames ranges strand | num.tests num.up.logFC num.down.logFC
## <Rle> <IRanges> <Rle> | <integer> <integer> <integer>
## [1] chr16 70313851-70314860 * | 21 20 0
## PValue FDR direction rep.test rep.logFC best.pos
## <numeric> <numeric> <character> <integer> <numeric> <integer>
## [1] 1.32085e-13 2.80253e-09 up 115500 4.3254 70314505
## best.logFC overlap left right
## <numeric> <character> <character> <character>
## [1] 4.39456 Gbe1:+:PE
## -------
## seqinfo: 66 sequences from an unspecified genome
We use Gviz (F. and R. 2016) to plot the results. As in the H3K9ac analysis, we set up some tracks to display genome coordinates and gene annotation.
library(Gviz)
gax <- GenomeAxisTrack(col="black", fontsize=15, size=2)
greg <- GeneRegionTrack(TxDb.Mmusculus.UCSC.mm10.knownGene, showId=TRUE,
geneSymbol=TRUE, name="", background.title="transparent")
symbols <- unlist(mapIds(org.Mm.eg.db, gene(greg), "SYMBOL",
"ENTREZID", multiVals = "first"))
symbol(greg) <- symbols[gene(greg)]
We visualize two tracks for each sample – one for the forward-strand coverage, another for the reverse-strand coverage. This allows visualization of the strand bimodality that is characteristic of genuine TF binding sites. In Figure 6, two adjacent sites are present at the Gbe1 promoter, both of which exhibit increased binding in the WT genotype. Coverage is also substantially different between the WT replicates, consistent with the presence of a batch effect.
collected <- list()
lib.sizes <- filtered.data$totals/1e6
for (i in seq_along(cbpdata$Path)) {
reads <- extractReads(bam.file=cbpdata$Path[i], cur.region, param=param)
pcov <- as(coverage(reads[strand(reads)=="+"])/lib.sizes[i], "GRanges")
ncov <- as(coverage(reads[strand(reads)=="-"])/-lib.sizes[i], "GRanges")
ptrack <- DataTrack(pcov, type="histogram", lwd=0, ylim=c(-5, 5),
name=cbpdata$Description[i], col.axis="black", col.title="black",
fill="blue", col.histogram=NA)
ntrack <- DataTrack(ncov, type="histogram", lwd=0, ylim=c(-5, 5),
fill="red", col.histogram=NA)
collected[[i]] <- OverlayTrack(trackList=list(ptrack, ntrack))
}
plotTracks(c(gax, collected, greg), chromosome=as.character(seqnames(cur.region)),
from=start(cur.region), to=end(cur.region))
sessionInfo()
## R version 4.0.0 (2020-04-24)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] grid stats4 parallel stats graphics grDevices utils
## [8] datasets methods base
##
## other attached packages:
## [1] Gviz_1.32.0
## [2] org.Mm.eg.db_3.10.0
## [3] TxDb.Mmusculus.UCSC.mm10.knownGene_3.10.0
## [4] GenomicFeatures_1.40.0
## [5] AnnotationDbi_1.50.0
## [6] edgeR_3.30.0
## [7] limma_3.44.0
## [8] csaw_1.22.0
## [9] SummarizedExperiment_1.18.0
## [10] DelayedArray_0.14.0
## [11] matrixStats_0.56.0
## [12] Biobase_2.48.0
## [13] rtracklayer_1.48.0
## [14] BiocFileCache_1.12.0
## [15] dbplyr_1.4.3
## [16] Rsamtools_2.4.0
## [17] Biostrings_2.56.0
## [18] XVector_0.28.0
## [19] GenomicRanges_1.40.0
## [20] GenomeInfoDb_1.24.0
## [21] IRanges_2.22.0
## [22] S4Vectors_0.26.0
## [23] BiocGenerics_0.34.0
## [24] chipseqDBData_1.3.0
## [25] knitr_1.28
## [26] BiocStyle_2.16.0
##
## loaded via a namespace (and not attached):
## [1] colorspace_1.4-1 ellipsis_0.3.0
## [3] htmlTable_1.13.3 biovizBase_1.36.0
## [5] base64enc_0.1-3 dichromat_2.0-0
## [7] rstudioapi_0.11 bit64_0.9-7
## [9] interactiveDisplayBase_1.26.0 codetools_0.2-16
## [11] splines_4.0.0 Formula_1.2-3
## [13] cluster_2.1.0 png_0.1-7
## [15] shiny_1.4.0.2 BiocManager_1.30.10
## [17] compiler_4.0.0 httr_1.4.1
## [19] backports_1.1.6 lazyeval_0.2.2
## [21] assertthat_0.2.1 Matrix_1.2-18
## [23] fastmap_1.0.1 later_1.0.0
## [25] acepack_1.4.1 htmltools_0.4.0
## [27] prettyunits_1.1.1 tools_4.0.0
## [29] gtable_0.3.0 glue_1.4.0
## [31] GenomeInfoDbData_1.2.3 dplyr_0.8.5
## [33] rappdirs_0.3.1 Rcpp_1.0.4.6
## [35] vctrs_0.2.4 ExperimentHub_1.14.0
## [37] xfun_0.13 stringr_1.4.0
## [39] mime_0.9 lifecycle_0.2.0
## [41] ensembldb_2.12.0 statmod_1.4.34
## [43] XML_3.99-0.3 AnnotationHub_2.20.0
## [45] zlibbioc_1.34.0 scales_1.1.0
## [47] BSgenome_1.56.0 VariantAnnotation_1.34.0
## [49] ProtGenerics_1.20.0 hms_0.5.3
## [51] promises_1.1.0 AnnotationFilter_1.12.0
## [53] RColorBrewer_1.1-2 yaml_2.2.1
## [55] curl_4.3 gridExtra_2.3
## [57] memoise_1.1.0 ggplot2_3.3.0
## [59] rpart_4.1-15 biomaRt_2.44.0
## [61] latticeExtra_0.6-29 stringi_1.4.6
## [63] RSQLite_2.2.0 BiocVersion_3.11.1
## [65] highr_0.8 checkmate_2.0.0
## [67] BiocParallel_1.22.0 rlang_0.4.5
## [69] pkgconfig_2.0.3 bitops_1.0-6
## [71] evaluate_0.14 lattice_0.20-41
## [73] purrr_0.3.4 htmlwidgets_1.5.1
## [75] GenomicAlignments_1.24.0 bit_1.1-15.2
## [77] tidyselect_1.0.0 magrittr_1.5
## [79] bookdown_0.18 R6_2.4.1
## [81] magick_2.3 Hmisc_4.4-0
## [83] DBI_1.1.0 pillar_1.4.3
## [85] foreign_0.8-79 survival_3.1-12
## [87] RCurl_1.98-1.2 nnet_7.3-14
## [89] tibble_3.0.1 crayon_1.3.4
## [91] KernSmooth_2.23-17 rmarkdown_2.1
## [93] jpeg_0.1-8.1 progress_1.2.2
## [95] locfit_1.5-9.4 data.table_1.12.8
## [97] blob_1.2.1 digest_0.6.25
## [99] xtable_1.8-4 httpuv_1.5.2
## [101] openssl_1.4.1 munsell_0.5.0
## [103] askpass_1.1
ENCODE Project Consortium. 2012. “An integrated encyclopedia of DNA elements in the human genome.” Nature 489 (7414):57–74.
F., Hahne, and Ivanek R. 2016. “Visualizing Genomic Data Using Gviz and Bioconductor.” In Statistical Genomics: Methods and Protocols, edited by Ewy Mathé and Sean Davis, 335–51. New York, NY: Springer New York. https://doi.org/10.1007/978-1-4939-3578-9_16.
Kasper, L. H., C. Qu, J. C. Obenauer, D. J. McGoldrick, and P. K. Brindle. 2014. “Genome-wide and single-cell analyses reveal a context dependent relationship between CBP recruitment and gene expression.” Nucleic Acids Res. 42 (18):11363–82.
Lun, A. T., and G. K. Smyth. 2014. “De novo detection of differentially bound regions for ChIP-seq data using peaks and windows: controlling error rates correctly.” Nucleic Acids Res. 42 (11):e95.
———. 2015. “csaw: a Bioconductor package for differential binding analysis of ChIP-seq data using sliding windows.” Nucleic Acids Res. https://doi.org/10.1093/nar/gkv1191.
Lund, S. P., D. Nettleton, D. J. McCarthy, and G. K. Smyth. 2012. “Detecting differential expression in RNA-sequence data using quasi-likelihood with shrunken dispersion estimates.” Stat. Appl. Genet. Mol. Biol. 11 (5):Article 8.
McCarthy, D. J., Y. Chen, and G. K. Smyth. 2012. “Differential expression analysis of multifactor RNA-Seq experiments with respect to biological variation.” Nucleic Acids Res. 40 (10):4288–97.
Robinson, M. D., D. J. McCarthy, and G. K. Smyth. 2010. “edgeR: a Bioconductor package for differential expression analysis of digital gene expression data.” Bioinformatics 26 (1):139–40.
Robinson, M. D., and A. Oshlack. 2010. “A scaling normalization method for differential expression analysis of RNA-seq data.” Genome Biol. 11 (3):R25.
Simes, R. J. 1986. “An Improved Bonferroni Procedure for Multiple Tests of Significance.” Biometrika 73 (3):751–54.