Introduction

Assay for Transposase-Accessible Chromatin using sequencing (ATAC-seq) is an alternative or complementary technique to MNase-seq, DNase-seq, and FAIRE-seq for chromatin accessibility analysis. The results obtained from ATAC-seq are similar to those from DNase-seq and FAIRE-seq. ATAC-seq is gaining popularity because it does not require cross-linking, has higher signal to noise ratio, requires a much smaller amount of biological material and is faster and easier to perform, compared to other techniques.1

To help researchers quickly assess the quality of ATAC-seq data, we have developed the ATACseqQC package for easily making diagnostic plots following the published guidelines.1 In addition, it has functions to preprocess ATACseq data for subsequent peak calling.

Quick start

Here is an example using ATACseqQC with a subset of published ATAC-seq data1. Currently, only bam input file format is supported.

First install ATACseqQC and other packages required to run the examples. Please note that the example dataset used here is from human. To run analysis with dataset from a different species or differnt assembly, please install the corresponding BSgenome, TxDb and phastCons. For example, to analyze mouse data aligned to mm10, please install BSgenome.Mmusculus.UCSC.mm10, TxDb.Mmusculus.UCSC.mm10.knownGene and phastCons60way.UCSC.mm10. Please note that phstCons60way.UCSC.mm10 is optional, which can be obtained according to the vignettes of GenomicScores.

library(BiocManager)
BiocManager::install(c("ATACseqQC", "ChIPpeakAnno", "MotifDb", "GenomicAlignments",
           "BSgenome.Hsapiens.UCSC.hg19", "TxDb.Hsapiens.UCSC.hg19.knownGene",
           "phastCons100way.UCSC.hg19"))
## load the library
library(ATACseqQC)
## input the bamFile from the ATACseqQC package 
bamfile <- system.file("extdata", "GL1.bam", 
                        package="ATACseqQC", mustWork=TRUE)
bamfile.labels <- gsub(".bam", "", basename(bamfile))

IGV snapshot

Source code of IGVSnapshot function is available in extdata folder. To call the function, please try

source(system.file("extdata", "IGVSnapshot.R", package = "ATACseqQC"))

Estimate the library complexity

#bamQC(bamfile, outPath=NULL)
estimateLibComplexity(readsDupFreq(bamfile))

Fragment size distribution

First, there should be a large proportion of reads with less than 100 bp, which represents the nucleosome-free region. Second, the fragment size distribution should have a clear periodicity, which is evident in the inset figure, indicative of nucleosome occupacy (present in integer multiples).

## generate fragement size distribution
fragSize <- fragSizeDist(bamfile, bamfile.labels)

Nucleosome positioning

Adjust the read start sites

Tn5 transposase has been shown to bind as a dimer and inserts two adaptors into accessible DNA locations separated by 9 bp.2

Therefore, for downstream analysis, such as peak-calling and footprinting, all reads in input bamfile need to be shifted. The function shiftGAlignmentsList can be used to shift the reads. By default, all reads aligning to the positive strand are offset by +4bp, and all reads aligning to the negative strand are offset by -5bp.1

The adjusted reads will be written into a new bamfile for peak calling or footprinting.

## bamfile tags to be read in
possibleTag <- list("integer"=c("AM", "AS", "CM", "CP", "FI", "H0", "H1", "H2", 
                                "HI", "IH", "MQ", "NH", "NM", "OP", "PQ", "SM",
                                "TC", "UQ"), 
                 "character"=c("BC", "BQ", "BZ", "CB", "CC", "CO", "CQ", "CR",
                               "CS", "CT", "CY", "E2", "FS", "LB", "MC", "MD",
                               "MI", "OA", "OC", "OQ", "OX", "PG", "PT", "PU",
                               "Q2", "QT", "QX", "R2", "RG", "RX", "SA", "TS",
                               "U2"))
library(Rsamtools)
bamTop100 <- scanBam(BamFile(bamfile, yieldSize = 100),
                     param = ScanBamParam(tag=unlist(possibleTag)))[[1]]$tag
tags <- names(bamTop100)[lengths(bamTop100)>0]
tags
##    integer2   integer13 character16 
##        "AS"        "NM"        "MD"
## files will be output into outPath
outPath <- "splited"
dir.create(outPath)
## shift the coordinates of 5'ends of alignments in the bam file
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
## if you don't have an available TxDb, please refer
## GenomicFeatures::makeTxDbFromGFF to create one from gff3 or gtf file.
seqlev <- "chr1" ## subsample data for quick run
seqinformation <- seqinfo(TxDb.Hsapiens.UCSC.hg19.knownGene)
which <- as(seqinformation[seqlev], "GRanges")
gal <- readBamFile(bamfile, tag=tags, which=which, asMates=TRUE, bigFile=TRUE)
shiftedBamfile <- file.path(outPath, "shifted.bam")
gal1 <- shiftGAlignmentsList(gal, outbam=shiftedBamfile)
##   |                                                                              |                                                                      |   0%  |                                                                              |==============                                                        |  20%  |                                                                              |============================                                          |  40%  |                                                                              |==========================================                            |  60%  |                                                                              |========================================================              |  80%  |                                                                              |======================================================================| 100%

Promoter/Transcript body (PT) score

PT score is calculated as the coverage of promoter divided by the coverage of its transcript body. PT score will show if the signal is enriched in promoters.

library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txs <- transcripts(TxDb.Hsapiens.UCSC.hg19.knownGene)
pt <- PTscore(gal1, txs)
plot(pt$log2meanCoverage, pt$PT_score, 
     xlab="log2 mean coverage",
     ylab="Promoter vs Transcript")

Nucleosome Free Regions (NFR) score

NFR score is a ratio between cut signal adjacent to TSS and that flanking the corresponding TSS. Each TSS window of 400 bp is first divided into 3 sub-regions: the most upstream 150 bp (n1), the most downstream of 150 bp (n2), and the middle 100 bp (nf). Then the number of fragments with 5’ ends overlapping each region are calculated for each TSS. The NFR score for each TSS is calculated as NFR-score = log2(nf) - log2((n1+n2)/2). A plot can be generated with the NFR scores as Y-axis and the average signals of 400 bp window as X-axis, very like a MA plot for gene expression data.

nfr <- NFRscore(gal1, txs)
plot(nfr$log2meanCoverage, nfr$NFR_score, 
     xlab="log2 mean coverage",
     ylab="Nucleosome Free Regions score",
     main="NFRscore for 200bp flanking TSSs",
     xlim=c(-10, 0), ylim=c(-5, 5))

Transcription Start Site (TSS) Enrichment Score

TSS enrichment score is a raio between aggregate distribution of reads centered on TSSs and that flanking the corresponding TSSs. TSS score = the depth of TSS (each 100bp window within 1000 bp each side) / the depth of end flanks (100bp each end). TSSE score = max(mean(TSS score in each window)). TSS enrichment score is calculated according to the definition at https://www.encodeproject.org/data-standards/terms/#enrichment. Transcription start site (TSS) enrichment values are dependent on the reference files used; cutoff values for high quality data are listed in the following table from https://www.encodeproject.org/atac-seq/.

tsse <- TSSEscore(gal1, txs)
tsse$TSSEscore
## [1] 14.99366
plot(100*(-9:10-.5), tsse$values, type="b", 
     xlab="distance to TSS",
     ylab="aggregate TSS score")

Split reads

The shifted reads will be split into different bins, namely nucleosome free, mononucleosome, dinucleosome, and trinucleosome. Shifted reads that do not fit into any of the above bins will be discarded. Splitting reads is a time-consuming step because we are using random forest to classify the fragments based on fragment length, GC content and conservation scores.3

By default, we assign the top 10% of short reads (reads below 100_bp) as nucleosome-free regions and the top 10% of intermediate length reads as (reads between 180 and 247 bp) mononucleosome. This serves as the training set to classify the rest of the fragments using random forest. The number of the tree will be set to 2 times of square root of the length of the training set.

library(BSgenome.Hsapiens.UCSC.hg19)
library(phastCons100way.UCSC.hg19)
## run program for chromosome 1 only
txs <- txs[seqnames(txs) %in% "chr1"]
genome <- Hsapiens
## split the reads into NucleosomeFree, mononucleosome, 
## dinucleosome and trinucleosome.
## and save the binned alignments into bam files.
objs <- splitGAlignmentsByCut(gal1, txs=txs, genome=genome, outPath = outPath,
                              conservation=phastCons100way.UCSC.hg19)
## list the files generated by splitGAlignmentsByCut.
dir(outPath)
##  [1] "dinucleosome.bam"       "dinucleosome.bam.bai"   "inter1.bam"            
##  [4] "inter1.bam.bai"         "inter2.bam"             "inter2.bam.bai"        
##  [7] "inter3.bam"             "inter3.bam.bai"         "mononucleosome.bam"    
## [10] "mononucleosome.bam.bai" "NucleosomeFree.bam"     "NucleosomeFree.bam.bai"
## [13] "others.bam"             "others.bam.bai"         "shifted.bam"           
## [16] "shifted.bam.bai"        "trinucleosome.bam"      "trinucleosome.bam.bai"

You can also perform shifting, splitting and saving in one step by calling splitBam.

objs <- splitBam(bamfile, tags=tags, outPath=outPath,
                 txs=txs, genome=genome,
                 conservation=phastCons100way.UCSC.hg19)

Conservation is an optional parameter. If you do not have the conservation score or you would like to simply split the bam files using the fragment length, then you will just need to run the command without providing the conservation argument. Without setting the conservation parameter, it will run much faster.

## split reads by fragment length
## NOT RUN IN THIS example
objs <- splitGAlignmentsByCut(gal1, txs=txs, outPath = outPath)

Heatmap and coverage curve for nucleosome positions

By averaging the signal across all active TSSs, we should observe that nucleosome-free fragments are enriched at the TSSs, whereas the nucleosome-bound fragments should be enriched both upstream and downstream of the active TSSs and display characteristic phasing of upstream and downstream nucleosomes. Because ATAC-seq reads are concentrated at regions of open chromatin, users should see a strong nucleosome signal at the +1 nucleosome, but the signal decreases at the +2, +3 and +4 nucleosomes.

library(ChIPpeakAnno)
bamfiles <- file.path(outPath,
                     c("NucleosomeFree.bam",
                     "mononucleosome.bam",
                     "dinucleosome.bam",
                     "trinucleosome.bam"))
## Plot the cumulative percentage of tag allocation in nucleosome-free 
## and mononucleosome bam files.
cumulativePercentage(bamfiles[1:2], as(seqinformation["chr1"], "GRanges"))

TSS <- promoters(txs, upstream=0, downstream=1)
TSS <- unique(TSS)
## estimate the library size for normalization
(librarySize <- estLibSize(bamfiles))
## splited/NucleosomeFree.bam splited/mononucleosome.bam 
##                      33520                       2041 
##   splited/dinucleosome.bam  splited/trinucleosome.bam 
##                       2017                        443
## calculate the signals around TSSs.
NTILE <- 101
dws <- ups <- 1010
sigs <- enrichedFragments(gal=objs[c("NucleosomeFree", 
                                     "mononucleosome",
                                     "dinucleosome",
                                     "trinucleosome")], 
                          TSS=TSS,
                          librarySize=librarySize,
                          seqlev=seqlev,
                          TSS.filter=0.5,
                          n.tile = NTILE,
                          upstream = ups,
                          downstream = dws)
## log2 transformed signals
sigs.log2 <- lapply(sigs, function(.ele) log2(.ele+1))
#plot heatmap
featureAlignedHeatmap(sigs.log2, reCenterPeaks(TSS, width=ups+dws),
                      zeroAt=.5, n.tile=NTILE)

## get signals normalized for nucleosome-free and nucleosome-bound regions.
out <- featureAlignedDistribution(sigs, 
                                  reCenterPeaks(TSS, width=ups+dws),
                                  zeroAt=.5, n.tile=NTILE, type="l", 
                                  ylab="Averaged coverage")
## rescale the nucleosome-free and nucleosome signals to 0~1
range01 <- function(x){(x-min(x))/(max(x)-min(x))}
out <- apply(out, 2, range01)
matplot(out, type="l", xaxt="n", 
        xlab="Position (bp)", 
        ylab="Fraction of signal")
axis(1, at=seq(0, 100, by=10)+1, 
     labels=c("-1K", seq(-800, 800, by=200), "1K"), las=2)
abline(v=seq(0, 100, by=10)+1, lty=2, col="gray")

plot Footprints

ATAC-seq footprints infer factor occupancy genome-wide. The factorFootprints function uses matchPWM to predict the binding sites using the input position weight matrix (PWM). Then it calculates and plots the accumulated coverage for those binding sites to show the status of the occupancy genome-wide. Unlike CENTIPEDE4, the footprints generated here do not take the conservation (PhyloP) into consideration. factorFootprints function could also accept the binding sites as a GRanges object.

## foot prints
library(MotifDb)
CTCF <- query(MotifDb, c("CTCF"))
CTCF <- as.list(CTCF)
print(CTCF[[1]], digits=2)
##      1    2    3     4     5     6     7     8     9    10    11    12    13
## A 0.10 0.16 0.30 0.072 0.012 0.786 0.024 0.122 0.914 0.012 0.376 0.022 0.028
## C 0.36 0.21 0.10 0.826 0.966 0.024 0.620 0.494 0.010 0.008 0.010 0.022 0.002
## G 0.12 0.41 0.44 0.050 0.012 0.108 0.336 0.056 0.048 0.976 0.602 0.606 0.962
## T 0.42 0.22 0.16 0.052 0.010 0.082 0.020 0.328 0.028 0.004 0.012 0.350 0.008
##      14    15    16    17   18   19
## A 0.024 0.096 0.424 0.086 0.12 0.34
## C 0.016 0.818 0.024 0.532 0.35 0.26
## G 0.880 0.038 0.522 0.326 0.12 0.32
## T 0.080 0.048 0.030 0.056 0.41 0.08
sigs <- factorFootprints(shiftedBamfile, pfm=CTCF[[1]], 
                         genome=genome, ## Don't have a genome? ask ?factorFootprints for help
                         min.score="90%", seqlev=seqlev,
                         upstream=100, downstream=100)

featureAlignedHeatmap(sigs$signal, 
                      feature.gr=reCenterPeaks(sigs$bindingSites,
                                               width=200+width(sigs$bindingSites[1])), 
                      annoMcols="score",
                      sortBy="score",
                      n.tile=ncol(sigs$signal[[1]]))

sigs$spearman.correlation
## $`+`
## 
##  Spearman's rank correlation rho
## 
## data:  predictedBindingSiteScore and highest.sig.windows
## S = 2483380, p-value = 1.454e-05
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.2595536 
## 
## 
## $`-`
## 
##  Spearman's rank correlation rho
## 
## data:  predictedBindingSiteScore and highest.sig.windows
## S = 2697867, p-value = 0.001185
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.1956021
sigs$Profile.segmentation
##           pos   distal_abun proximal_abun       binding 
##   55.75000000    0.09731340    0.14611895    0.05690943

Here is the CTCF footprints for the full dataset. CTCF footprints

V-plot

V-plot is a plot to visualize fragment midpoint vs length for a given transcription factors.

vp <- vPlot(shiftedBamfile, pfm=CTCF[[1]], 
            genome=genome, min.score="90%", seqlev=seqlev,
            upstream=200, downstream=200, 
            ylim=c(30, 250), bandwidth=c(2, 1))

distanceDyad(vp, pch=20, cex=.5)

Here is the CTCF vPlot for the full dataset. CTCF footprints

Plot correlations for multiple samples

path <- system.file("extdata", package="ATACseqQC", mustWork=TRUE)
bamfiles <- dir(path, "*.bam$", full.name=TRUE)
gals <- lapply(bamfiles, function(bamfile){
               readBamFile(bamFile=bamfile, tag=character(0), 
                          which=GRanges("chr1", IRanges(1, 1e6)), 
                          asMates=FALSE)
         })
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txs <- transcripts(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(GenomicAlignments)
plotCorrelation(GAlignmentsList(gals), txs, seqlev="chr1")

Session Info

sessionInfo()
## R version 4.4.0 beta (2024-04-15 r86425)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [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       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] GenomicAlignments_1.40.0               
##  [2] Rsamtools_2.20.0                       
##  [3] SummarizedExperiment_1.34.0            
##  [4] MatrixGenerics_1.16.0                  
##  [5] matrixStats_1.3.0                      
##  [6] MotifDb_1.46.0                         
##  [7] phastCons100way.UCSC.hg19_3.7.2        
##  [8] GenomicScores_2.16.0                   
##  [9] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
## [10] GenomicFeatures_1.56.0                 
## [11] AnnotationDbi_1.66.0                   
## [12] Biobase_2.64.0                         
## [13] BSgenome.Hsapiens.UCSC.hg19_1.4.3      
## [14] BSgenome_1.72.0                        
## [15] rtracklayer_1.64.0                     
## [16] BiocIO_1.14.0                          
## [17] Biostrings_2.72.0                      
## [18] XVector_0.44.0                         
## [19] ChIPpeakAnno_3.38.0                    
## [20] GenomicRanges_1.56.0                   
## [21] GenomeInfoDb_1.40.0                    
## [22] IRanges_2.38.0                         
## [23] ATACseqQC_1.28.0                       
## [24] S4Vectors_0.42.0                       
## [25] BiocGenerics_0.50.0                    
## 
## loaded via a namespace (and not attached):
##   [1] splines_4.4.0               bitops_1.0-7               
##   [3] filelock_1.0.3              tibble_3.2.1               
##   [5] R.oo_1.26.0                 graph_1.82.0               
##   [7] XML_3.99-0.16.1             DirichletMultinomial_1.46.0
##   [9] lifecycle_1.0.4             httr2_1.0.1                
##  [11] pwalign_1.0.0               edgeR_4.2.0                
##  [13] lattice_0.22-6              ensembldb_2.28.0           
##  [15] MASS_7.3-60.2               magrittr_2.0.3             
##  [17] limma_3.60.0                sass_0.4.9                 
##  [19] rmarkdown_2.26              jquerylib_0.1.4            
##  [21] yaml_2.3.8                  grImport2_0.3-1            
##  [23] DBI_1.2.2                   CNEr_1.40.0                
##  [25] ade4_1.7-22                 abind_1.4-5                
##  [27] zlibbioc_1.50.0             purrr_1.0.2                
##  [29] R.utils_2.12.3              preseqR_4.0.0              
##  [31] AnnotationFilter_1.28.0     RCurl_1.98-1.14            
##  [33] pracma_2.4.4                rappdirs_0.3.3             
##  [35] GenomeInfoDbData_1.2.12     seqLogo_1.70.0             
##  [37] BiocStyle_2.32.0            annotate_1.82.0            
##  [39] codetools_0.2-20            DelayedArray_0.30.0        
##  [41] xml2_1.3.6                  tidyselect_1.2.1           
##  [43] futile.logger_1.4.3         UCSC.utils_1.0.0           
##  [45] universalmotif_1.22.0       base64enc_0.1-3            
##  [47] BiocFileCache_2.12.0        jsonlite_1.8.8             
##  [49] multtest_2.60.0             motifStack_1.48.0          
##  [51] survival_3.6-4              tools_4.4.0                
##  [53] progress_1.2.3              TFMPvalue_0.0.9            
##  [55] Rcpp_1.0.12                 glue_1.7.0                 
##  [57] SparseArray_1.4.0           xfun_0.43                  
##  [59] dplyr_1.1.4                 HDF5Array_1.32.0           
##  [61] formatR_1.14                BiocManager_1.30.22        
##  [63] fastmap_1.1.1               rhdf5filters_1.16.0        
##  [65] fansi_1.0.6                 caTools_1.18.2             
##  [67] digest_0.6.35               R6_2.5.1                   
##  [69] colorspace_2.1-0            Cairo_1.6-2                
##  [71] GO.db_3.19.1                gtools_3.9.5               
##  [73] poweRlaw_0.80.0             jpeg_0.1-10                
##  [75] biomaRt_2.60.0              RSQLite_2.3.6              
##  [77] R.methodsS3_1.8.2           utf8_1.2.4                 
##  [79] tidyr_1.3.1                 generics_0.1.3             
##  [81] data.table_1.15.4           prettyunits_1.2.0          
##  [83] InteractionSet_1.32.0       httr_1.4.7                 
##  [85] htmlwidgets_1.6.4           S4Arrays_1.4.0             
##  [87] TFBSTools_1.42.0            regioneR_1.36.0            
##  [89] pkgconfig_2.0.3             gtable_0.3.5               
##  [91] blob_1.2.4                  htmltools_0.5.8.1          
##  [93] RBGL_1.80.0                 ProtGenerics_1.36.0        
##  [95] scales_1.3.0                png_0.1-8                  
##  [97] knitr_1.46                  lambda.r_1.2.4             
##  [99] tzdb_0.4.0                  reshape2_1.4.4             
## [101] rjson_0.2.21                curl_5.2.1                 
## [103] cachem_1.0.8                rhdf5_2.48.0               
## [105] stringr_1.5.1               BiocVersion_3.19.1         
## [107] KernSmooth_2.23-22          parallel_4.4.0             
## [109] restfulr_0.0.15             pillar_1.9.0               
## [111] grid_4.4.0                  vctrs_0.6.5                
## [113] randomForest_4.7-1.1        dbplyr_2.5.0               
## [115] xtable_1.8-4                evaluate_0.23              
## [117] readr_2.1.5                 VennDiagram_1.7.3          
## [119] cli_3.6.2                   locfit_1.5-9.9             
## [121] compiler_4.4.0              futile.options_1.0.1       
## [123] rlang_1.1.3                 crayon_1.5.2               
## [125] plyr_1.8.9                  stringi_1.8.3              
## [127] BiocParallel_1.38.0         munsell_0.5.1              
## [129] lazyeval_0.2.2              Matrix_1.7-0               
## [131] hms_1.1.3                   bit64_4.0.5                
## [133] ggplot2_3.5.1               Rhdf5lib_1.26.0            
## [135] KEGGREST_1.44.0             statmod_1.5.0              
## [137] highr_0.10                  AnnotationHub_3.12.0       
## [139] memoise_2.0.1               bslib_0.7.0                
## [141] bit_4.0.5                   splitstackshape_1.4.8      
## [143] polynom_1.4-1

References

1. Buenrostro, J. D., Giresi, P. G., Zaba, L. C., Chang, H. Y. & Greenleaf, W. J. Transposition of native chromatin for fast and sensitive epigenomic profiling of open chromatin, dna-binding proteins and nucleosome position. Nature methods 10, 1213–1218 (2013).

2. Adey, A. et al. Rapid, low-input, low-bias construction of shotgun fragment libraries by high-density in vitro transposition. Genome biology 11, R119 (2010).

3. Chen, K. et al. DANPOS: Dynamic analysis of nucleosome position and occupancy by sequencing. Genome research 23, 341–351 (2013).

4. Pique-Regi, R. et al. Accurate inference of transcription factor binding from dna sequence and chromatin accessibility data. Genome research 21, 447–455 (2011).