Contents

1 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 techniques1.

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 guidelines1. In addition, it has functions to preprocess ATACseq data for subsequent peak calling.

2 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 different 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(BiocInstaller)
biocLite(c("ATACseqQC", "ChIPpeakAnno", "MotifDb",
           "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))

2.1 Check alignment metrics and mapping quality

bamQC(bamfile, outPath=NULL)
## $totalQNAMEs
## [1] 44357
## 
## $duplicateRate
## [1] 0.03002908
## 
## $mitochondriaRate
## [1] 0
## 
## $properPairRate
## [1] 0.9815136
## 
## $unmappedRate
## [1] 0
## 
## $hasUnmappedMateRate
## [1] 0
## 
## $notPassingQualityControlsRate
## [1] 0
## 
## $MAPQ
##    mapq  Freq
## 1    21    44
## 2    22    12
## 3    23   536
## 4    24   606
## 5    25    14
## 6    26    10
## 7    27     4
## 8    30  1682
## 9    31   780
## 10   32   238
## 11   34   244
## 12   35   118
## 13   36    44
## 14   37    62
## 15   38    64
## 16   39    34
## 17   40  2076
## 18   42 82146
## 
## $idxstats
##    seqnames seqlength mapped unmapped
## 1      chr1 249250621  88714        0
## 2      chr2 243199373      0        0
## 3      chr3 198022430      0        0
## 4      chr4 191154276      0        0
## 5      chr5 180915260      0        0
## 6      chr6 171115067      0        0
## 7      chr7 159138663      0        0
## 8      chr8 146364022      0        0
## 9      chr9 141213431      0        0
## 10    chr10 135534747      0        0
## 11    chr11 135006516      0        0
## 12    chr12 133851895      0        0
## 13    chr13 115169878      0        0
## 14    chr14 107349540      0        0
## 15    chr15 102531392      0        0
## 16    chr16  90354753      0        0
## 17    chr17  81195210      0        0
## 18    chr18  78077248      0        0
## 19    chr19  59128983      0        0
## 20    chr20  63025520      0        0
## 21    chr21  48129895      0        0
## 22    chr22  51304566      0        0
## 23     chrX 155270560      0        0
## 24     chrY  59373566      0        0
## 25     chrM     16571      0        0

2.2 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)

2.3 Nucleosome positioning

2.3.1 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 bp2.

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 -5bp1.

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

## bamfile tags to be read in
tags <- c("AS", "XN", "XM", "XO", "XG", "NM", "MD", "YS", "YT")
## files will be output into outPath
outPath <- "splited"
dir.create(outPath)
## shift the coordinates of 5'ends of alignments in the bam file
library(BSgenome.Hsapiens.UCSC.hg19)
seqlev <- "chr1" ## subsample data for quick run
which <- as(seqinfo(Hsapiens)[seqlev], "GRanges")
gal <- readBamFile(bamfile, tag=tags, which=which, asMates=TRUE)
gal1 <- shiftGAlignmentsList(gal)
shiftedBamfile <- file.path(outPath, "shifted.bam")
export(gal1, shiftedBamfile)

2.3.2 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 scores3.

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 trees will be set to 2 times of square root of the training set size.

library(phastCons100way.UCSC.hg19)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txs <- transcripts(TxDb.Hsapiens.UCSC.hg19.knownGene)
## run program for chromosome 1 only
txs <- txs[seqnames(txs) %in% "chr1"]
genome <- Hsapiens
## split the reads into NucleosomeFree, mononucleosome, 
## dinucleosome and trinucleosome.
objs <- splitGAlignmentsByCut(gal1, txs=txs, genome=genome,
                              conservation=phastCons100way.UCSC.hg19)

Save the binned alignments into bam files.

null <- writeListOfGAlignments(objs, outPath)
## list the files generated by splitBam.
dir(outPath)
##  [1] "NucleosomeFree.bam"     "NucleosomeFree.bam.bai"
##  [3] "dinucleosome.bam"       "dinucleosome.bam.bai"  
##  [5] "inter1.bam"             "inter1.bam.bai"        
##  [7] "inter2.bam"             "inter2.bam.bai"        
##  [9] "inter3.bam"             "inter3.bam.bai"        
## [11] "mononucleosome.bam"     "mononucleosome.bam.bai"
## [13] "others.bam"             "others.bam.bai"        
## [15] "shifted.bam"            "shifted.bam.bai"       
## [17] "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 bams 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.

2.3.3 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(seqinfo(Hsapiens)["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 
##                      32850                       2259 
##   splited/dinucleosome.bam  splited/trinucleosome.bam 
##                       2116                        478
## 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")