The gDNAx
package provides functionality to diagnose the presence of genomic DNA (gDNA) contamination in RNA-seq data sets, and filter out reads of potential gDNA origin.
gDNAx 1.2.1
RNA sequencing (RNA-seq) libraries may contain genomic DNA (gDNA) contamination due to an absent or inefficient gDNA digestion step (with DNase) during RNA extraction or library preparation. In fact, some protocols do not include a DNase treatment step, or they include it as optional.
While gDNA contamination is not a major issue in libraries built with poly(A) selected RNA molecules, it can remarkably affect gene expression quantification from libraries of total RNA. When present, gDNA contamination can lead to a misleading attribution of expression to unannotated regions of the genome. For this reason, it is important to check the levels of gDNA contamination during quality control before performing further analyses, specially when total RNA has been sequenced.
Here we illustrate the use of the gDNAx package for producing different diagnostics and how do they reveal different gDNA contamination levels. We use a subset of the data in (Li et al. 2022), which consists of 9 paired-end samples of total RNA-seq with increasing levels of gDNA contamination: 0% (no contamination), 1% and 10%, with 3 replicates each. The data is available through the Bioconductor experiment data package gDNAinRNAseqData, which allows one to download 9 BAM files, containing about 100,000 alignments, sampled uniformly at random from the complete BAM files.
library(gDNAinRNAseqData)
# Retrieve BAM files
bamfiles <- LiYu22subsetBAMfiles()
bamfiles
[1] "/tmp/Rtmpht4Lqi/s32gDNA0.bam" "/tmp/Rtmpht4Lqi/s33gDNA0.bam"
[3] "/tmp/Rtmpht4Lqi/s34gDNA0.bam" "/tmp/Rtmpht4Lqi/s26gDNA1.bam"
[5] "/tmp/Rtmpht4Lqi/s27gDNA1.bam" "/tmp/Rtmpht4Lqi/s28gDNA1.bam"
[7] "/tmp/Rtmpht4Lqi/s23gDNA10.bam" "/tmp/Rtmpht4Lqi/s24gDNA10.bam"
[9] "/tmp/Rtmpht4Lqi/s25gDNA10.bam"
# Retrieve information on the gDNA concentrations of each BAM file
pdat <- LiYu22phenoData(bamfiles)
pdat
gDNA
s32gDNA0 0
s33gDNA0 0
s34gDNA0 0
s26gDNA1 1
s27gDNA1 1
s28gDNA1 1
s23gDNA10 10
s24gDNA10 10
s25gDNA10 10
Diagnosing the presence of gDNA contamination requires using an annotation
of genes and transcripts. The gDNAx
package expects that we provide such an annotation using a so-called TxDb
package, either as a TxDb
object, created once such a package is loaded into
the R session, or by specifying the name of the package. The Bioconductor
website
provides a number of TxDb
packages, but if the we do not find the one we are
looking for, we can build a TxDb
object using the function makeTxDbFromGFF()
on a given GFF or
GTF file, or any of the
other makeTxDbFrom*()
functions, available in the
GenomicFeatures package.
Here we load the TxDb
package corresponding to the GENCODE annotation provided
by the UCSC Genome Browser.
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene
txdb
TxDb object:
# Db type: TxDb
# Supporting package: GenomicFeatures
# Data source: UCSC
# Genome: hg38
# Organism: Homo sapiens
# Taxonomy ID: 9606
# UCSC Table: knownGene
# UCSC Track: GENCODE V44
# Resource URL: http://genome.ucsc.edu/
# Type of Gene ID: Entrez Gene ID
# Full dataset: yes
# miRBase build ID: NA
# Nb of transcripts: 276905
# Db created by: GenomicFeatures package from Bioconductor
# Creation time: 2023-09-20 17:25:17 +0000 (Wed, 20 Sep 2023)
# GenomicFeatures version at creation time: 1.53.2
# RSQLite version at creation time: 2.3.1
# DBSCHEMAVERSION: 1.2
We can calculate diagnostics for gDNA contamination using the function
gDNAdx()
as follows.
library(gDNAx)
gdnax <- gDNAdx(bamfiles, txdb)
class(gdnax)
[1] "gDNAx"
attr(,"package")
[1] "gDNAx"
gdnax
gDNAx object
# BAM files (9): s32gDNA0.bam, ..., s25gDNA10.bam
# Library layout: paired-end, 9 (2x50nt)
# Library protocol: unstranded (9 out of 9)
# Sequences: only standard chromosomes
# Annotation pkg: TxDb.Hsapiens.UCSC.hg38.knownGene
# Alignments employed: first 100000
The previous call will show progress through its calculations unless we set
the argument verbose=FALSE
, and return an object of class gDNAx
once it has
finished. We have let the gDNAdx()
function figure out the library layout
and protocol, but if we already knew those parameters from the data, we could
set them through the arguments singleEnd
and strandMode
and speed up
calculations. Another way to speed up calculations, which may be advantageous
specially when analysing a high number of BAM files, is to use the BPPARAM
argument to set a number of parallel threads of execution; see the help page
of gDNAdx()
for full details on how to specify non-default values to all
these parameters.
Calling the plot()
function with the resulting object gDNAx
object as the
first argument will plot several diagnostics. Here below, we also use a
parameter called group
to automatically color samples, in this case, by the
gDNA contamination levels included in the experimental design of the data; see
(Li et al. 2022) for full details on it.
par(mar=c(4, 5, 2, 1))
plot(gdnax, group=pdat$gDNA, pch=19)
The previous figure contains three diagnostic plots, each one showing the following values as a function of the percentage of read alignments fully contained in intergenic regions (IGC):
These data appear to come from an unstranded library, but if they would be stranded, a fourth diagnostic plot would appear showing an estimated value of the strandedness of each sample as function of the percentage of intergenic alignments. In stranded RNA-seq data, we should expect strandedness values close to 1, which imply that most reads align to the same strand than the annotated transcripts. Lower strandedness values can be indicative of gDNA contamination because reads sequenced from DNA are expected to align in equal proportions to both strands.
Because IGC alignments mainly originate from gDNA contamination, we may expect a negative correlation between the percentage of SCJ or SCE alignments and the percentage of IGC alignments. On the other hand, INT alignments may originate either from primary unprocessed transcripts in the nucleus, or from gDNA contamination as well. Therefore, we may also expect some positive correlation between the percentages of INT and IGC alignments, as it happens in this data.
Using the function getDx()
on the gDNAx
object, we obtain all the values
used in the diagnostics.
dx <- getDx(gdnax)
dx
IGC INT SCJ SCE JNC IGCFLM SCJFLM SCEFLM
s32gDNA0 1.036524 11.75898 15.18563 40.04114 19.56452 172.053 156.033 157.708
s33gDNA0 1.125444 11.78607 15.21656 40.31236 19.55383 178.859 159.390 162.228
s34gDNA0 1.095440 12.26551 15.40036 40.19421 19.70788 169.263 156.536 153.528
s26gDNA1 1.402844 12.22650 14.78351 38.69202 18.73132 173.700 162.437 166.968
s27gDNA1 1.365428 12.45073 14.54513 38.21891 18.31765 170.785 168.054 163.834
s28gDNA1 1.503162 12.49083 14.09956 37.67457 17.96053 183.080 163.515 164.487
s23gDNA10 3.529043 13.16473 11.22648 30.99781 14.41110 173.137 163.784 167.093
s24gDNA10 3.781627 13.65285 10.85400 30.01465 13.91748 163.813 161.822 158.671
s25gDNA10 3.412804 13.51507 11.19751 30.65271 14.20691 174.596 164.927 162.389
INTFLM STRAND
s32gDNA0 154.377 NA
s33gDNA0 158.619 NA
s34gDNA0 151.075 NA
s26gDNA1 158.612 NA
s27gDNA1 158.861 NA
s28gDNA1 162.016 NA
s23gDNA10 161.926 NA
s24gDNA10 157.528 NA
s25gDNA10 157.253 NA
The column JNC
contains the percentage of alignments that include one or more
junctions, irrespective of whether those aligments are compatible with an
spliced transcript in the given annotation. The columns with the suffix FLM
contain an estimation of the fragment length mean in the alignments originating
in the corresponding region, and the column STRAND
stores the strandedness
values, which in this case are NA
because this dataset is not strand-specific.
We can directly plot the estimated fragments length distributions with the
function plotFrgLength()
.
plotFrgLength(gdnax)
Another way to represent some of diagnostic measurements is to examine the origin of the alignments per sample in percentages. Fluctuations of these proportions across samples can help quantifying the amount of gDNA contamination per sample.
plotAlnOrigins(gdnax, group=pdat$gDNA)
If we are interested in knowing exactly which annotations of intergenic and
intronic regions have been used to compute these diagnostics, we can easily
retrieve them using the functions getIgc()
and getInt()
on the output
gDNAx
object, respectively.
igcann <- getIgc(gdnax)
igcann
GRanges object with 916424 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 1-10000 *
[2] chr1 31132-31292 *
[3] chr1 31755-32840 *
[4] chr1 34109-34450 *
[5] chr1 36082-37044 *
... ... ... ...
[916420] chrM 2746-3229 *
[916421] chrM 3308-4328 *
[916422] chrM 4401-7447 *
[916423] chrM 7515-16204 *
[916424] chrM 16250-16569 *
-------
seqinfo: 25 sequences (1 circular) from hg38 genome
intann <- getInt(gdnax)
intann
GRanges object with 1487736 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 12228-12612 *
[2] chr1 12722-12974 *
[3] chr1 13053-13220 *
[4] chr1 14502-15004 *
[5] chr1 15039-15264 *
... ... ... ...
[1487732] chrY 57207675-57208210 *
[1487733] chrY 57208313-57208518 *
[1487734] chrY 57213358-57213525 *
[1487735] chrY 57213603-57213879 *
[1487736] chrY 57213965-57214349 *
-------
seqinfo: 25 sequences (1 circular) from hg38 genome
Since we have let the gDNAdx()
function to estimate strandedness, we can
examine those estimated values using the getter function strandedness()
on
the gDNAx
object.
strandedness(gdnax)
strandMode1 strandMode2 ambig Nalignments
s32gDNA0 0.4808250 0.4788154 0.04035963 66180
s33gDNA0 0.4807803 0.4786079 0.04061189 66286
s34gDNA0 0.4844482 0.4751232 0.04042862 66166
s26gDNA1 0.4849027 0.4760626 0.03903465 63687
s27gDNA1 0.4867612 0.4732038 0.04003505 62770
s28gDNA1 0.4803781 0.4793314 0.04029050 62099
s23gDNA10 0.4819399 0.4768140 0.04124613 50332
s24gDNA10 0.4781815 0.4820590 0.03975956 48743
s25gDNA10 0.4802366 0.4787125 0.04105084 49865
Using the function classifyStrandMode()
we can obtain a classification of
the most likely strand mode for each BAM file, given some default cutoff
values.
classifyStrandMode(strandedness(gdnax))
s32gDNA0 s33gDNA0 s34gDNA0 s26gDNA1 s27gDNA1 s28gDNA1 s23gDNA10 s24gDNA10
NA NA NA NA NA NA NA NA
s25gDNA10
NA
Li et al. (2022) report in their publication that “sequencing libraries were
generated using a TruSeq Stranded Total RNA Library Prep Kit”. However, we can
see that the proportion of alignments overlapping transcripts in the column
strandMode1
is very similar to the one in the column strandMode2
, which is
compatible with an unstranded library and the reason why we obtain NA
values
in the output of classifyStrandMode()
. We reach the same conclusion if we use
the RSeQC tool infer_experiment.py
(Wang, Wang, and Li 2012) and by visual inspection
of the alignment data in the Integrative Genomics Viewer (IGV)
(Robinson et al. 2011).
Following the recommendations made by Signal and Kahlke (2022),
gDNAx
attempts to use at least 200,000 alignments overlapping exonic regions
to estimate strandedness. In the subset of data used in this vignette, the
number of alignments used for that estimation is close to 60,000, which is
the total number of exonic alignments present in the BAM files.
If we are only interested in the estimation of strandedness values, we can
can also directly call strandedness()
with a character string vector of BAM
filenames and a TxDb
annotation object; see the help page of strandedness()
.
We can attempt removing read alignments from putative gDNA origin using the
function gDNAtx()
, which should be called with the gDNAx
object returned
by gDNAdx()
and a path in the filesystem where to stored the filtered
BAM files. By default, these filtered BAM files include splice-compatible
read alignments (SCJ and SCE) that are found in a genomic window enriched for
stranded alignments. For further fine tuning of this filtering strategy please
use the function filterBAMtx()
.
## fbf <- filterBAMtxFlag(isSpliceCompatibleJunction=TRUE,
## isSpliceCompatibleExonic=TRUE)
## fstats <- filterBAMtx(gdnax, path=tmpdir, txflag=fbf)
## fstats
tmpdir <- tempdir()
fstats <- gDNAtx(gdnax, path=tmpdir)
fstats
NALN NIGC NINT NSCJ NSCE NSTW NNCH
s32gDNA0 99660 NA NA 15134 39905 46336 340
s33gDNA0 99694 NA NA 15170 40189 46823 306
s34gDNA0 99686 NA NA 15352 40068 46529 314
s26gDNA1 99726 NA NA 14743 38586 45061 274
s27gDNA1 99456 NA NA 14466 38011 45083 544
s28gDNA1 99457 NA NA 14023 37470 43892 543
s23gDNA10 99007 NA NA 11115 30690 36424 993
s24gDNA10 99005 NA NA 10746 29716 35032 995
s25gDNA10 99156 NA NA 11103 30394 36039 844
The first column NALN
corresponds to the total number of read alignments
processed. Columns NIGC
to NSCE
contain the number of selected alignments
from each corresponding origin, where NA
indicates that that type of
alignment was not selected for filtering. The column NSTW
corresponds to
selected alignments occurring in stranded windows, and therefore this number
will be always equal or smaller than the number of the previous columns. The
column NNCH
corresponds to discarded read alignments ocurring in non-standard
chromosomes.
sessionInfo()
R version 4.4.1 (2024-06-14)
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_GB 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
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] gDNAx_1.2.1
[2] TxDb.Hsapiens.UCSC.hg38.knownGene_3.18.0
[3] GenomicFeatures_1.56.0
[4] AnnotationDbi_1.66.0
[5] Biobase_2.64.0
[6] Rsamtools_2.20.0
[7] Biostrings_2.72.1
[8] XVector_0.44.0
[9] GenomicRanges_1.56.1
[10] GenomeInfoDb_1.40.1
[11] IRanges_2.38.1
[12] S4Vectors_0.42.1
[13] BiocGenerics_0.50.0
[14] gDNAinRNAseqData_1.4.0
[15] knitr_1.48
[16] BiocStyle_2.32.1
loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 dplyr_1.1.4
[3] blob_1.2.4 filelock_1.0.3
[5] bitops_1.0-8 fastmap_1.2.0
[7] RCurl_1.98-1.16 BiocFileCache_2.12.0
[9] VariantAnnotation_1.50.0 GenomicAlignments_1.40.0
[11] XML_3.99-0.17 digest_0.6.36
[13] mime_0.12 lifecycle_1.0.4
[15] KEGGREST_1.44.1 RSQLite_2.3.7
[17] magrittr_2.0.3 compiler_4.4.1
[19] rlang_1.1.4 sass_0.4.9
[21] tools_4.4.1 plotrix_3.8-4
[23] utf8_1.2.4 yaml_2.3.10
[25] rtracklayer_1.64.0 S4Arrays_1.4.1
[27] bit_4.0.5 curl_5.2.1
[29] DelayedArray_0.30.1 RColorBrewer_1.1-3
[31] abind_1.4-5 BiocParallel_1.38.0
[33] withr_3.0.1 purrr_1.0.2
[35] grid_4.4.1 fansi_1.0.6
[37] ExperimentHub_2.12.0 tinytex_0.52
[39] SummarizedExperiment_1.34.0 cli_3.6.3
[41] rmarkdown_2.27 crayon_1.5.3
[43] generics_0.1.3 httr_1.4.7
[45] rjson_0.2.21 DBI_1.2.3
[47] cachem_1.1.0 zlibbioc_1.50.0
[49] parallel_4.4.1 BiocManager_1.30.23
[51] restfulr_0.0.15 matrixStats_1.3.0
[53] vctrs_0.6.5 Matrix_1.7-0
[55] jsonlite_1.8.8 bookdown_0.40
[57] bit64_4.0.5 magick_2.8.4
[59] GenomicFiles_1.40.0 jquerylib_0.1.4
[61] glue_1.7.0 codetools_0.2-20
[63] BiocVersion_3.19.1 BiocIO_1.14.0
[65] UCSC.utils_1.0.0 tibble_3.2.1
[67] pillar_1.9.0 rappdirs_0.3.3
[69] htmltools_0.5.8.1 BSgenome_1.72.0
[71] GenomeInfoDbData_1.2.12 R6_2.5.1
[73] dbplyr_2.5.0 lattice_0.22-6
[75] evaluate_0.24.0 highr_0.11
[77] AnnotationHub_3.12.0 png_0.1-8
[79] memoise_2.0.1 bslib_0.8.0
[81] Rcpp_1.0.13 SparseArray_1.4.8
[83] xfun_0.46 MatrixGenerics_1.16.0
[85] pkgconfig_2.0.3
Li, Xiangnan, Peipei Zhang, Haijian Wang, and Ying Yu. 2022. “Genes Expressed at Low Levels Raise False Discovery Rates in Rna Samples Contaminated with Genomic Dna.” BMC Genomics 23 (1): 554.
Robinson, James T, Helga Thorvaldsdóttir, Wendy Winckler, Mitchell Guttman, Eric S Lander, Gad Getz, and Jill P Mesirov. 2011. “Integrative Genomics Viewer.” Nature Biotechnology 29 (1): 24–26.
Signal, Brandon, and Tim Kahlke. 2022. “How_are_we_stranded_here: Quick Determination of Rna-Seq Strandedness.” BMC Bioinformatics 23 (1): 1–9.
Wang, Liguo, Shengqin Wang, and Wei Li. 2012. “RSeQC: Quality Control of Rna-Seq Experiments.” Bioinformatics 28 (16): 2184–5.