Fastqcr
fastqcr: Quality Control of Sequencing Data
Install / Use
/learn @kassambara/FastqcrREADME
fastqcr: Quality Control of Sequencing Data
The FastQC, written by Simon Andrews at the Babraham Institute, is the most widely used sequence quality assessment tool for evaluating the raw reads from high throughput sequencing data.
It produces, for each sample, an html report and a ‘zip’ file, which contains a file called fastqc_data.txt and summary.txt.
If you have hundreds of samples, you’re not going to open up each HTML page. You need some way of looking at these data in aggregate.
The fastqcr R package provides helper functions to easily and automatically parse, aggregate and analyze FastQC reports for large numbers of samples.
Additionally, the fastqcr package provides a convenient solution for building a multi-QC report and a one-sample FastQC report with the result interpretations. The online documentation is available at: https://rpkgs.datanovia.com/fastqcr/.
Examples of QC reports, generated automatically by the fastqcr R package, include:
- Multi-QC report for multiple samples
- One sample QC report (+ interpretation)
- One sample QC report (no interpretation)

Installation and loading
- fastqcr can be installed from CRAN as follow:
install.packages("fastqcr")
- Or, install the latest version from GitHub:
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/fastqcr")
- Load fastqcr:
library("fastqcr")
Quick Start
library(fastqcr)
# Aggregating Multiple FastQC Reports into a Data Frame
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Demo QC directory containing zipped FASTQC reports
qc.dir <- system.file("fastqc_results", package = "fastqcr")
qc <- qc_aggregate(qc.dir)
qc
# Inspecting QC Problems
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# See which modules failed in the most samples
qc_fails(qc, "module")
# Or, see which samples failed the most
qc_fails(qc, "sample")
# Building Multi QC Reports
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qc_report(qc.dir, result.file = "multi-qc-report" )
# Building One-Sample QC Reports (+ Interpretation)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qc.file <- system.file("fastqc_results", "S1_fastqc.zip", package = "fastqcr")
qc_report(qc.file, result.file = "one-sample-report",
interpret = TRUE)
Main Functions
1) Installing and Running FastQC
-
fastqc_install(): Install the latest version of FastQC tool on Unix systems (MAC OSX and Linux)
-
fastqc(): Run the FastQC tool from R.
2) Aggregating and Summarizing Multiple FastQC Reports
-
qc <- qc_aggregate(): Aggregate multiple FastQC reports into a data frame.
-
summary(qc): Generates a summary of qc_aggregate.
-
qc_stats(qc): General statistics of FastQC reports.
3) Inspecting Problems
-
qc_fails(qc): Displays samples or modules that failed.
-
qc_warns(qc): Displays samples or modules that warned.
-
qc_problems(qc): Union of qc_fails() and qc_warns(). Display which samples or modules that failed or warned.
4) Importing and Plotting FastQC Reports
-
qc_read(): Read FastQC data into R.
-
qc_plot(qc): Plot FastQC data
5) Building One-Sample and Multi-QC Reports
- qc_report(): Create an HTML file containing FastQC reports of one or multiple files. Inputs can be either a directory containing multiple FastQC reports or a single sample FastQC report.
6) Others
- qc_unzip(): Unzip all zipped files in the qc.dir directory. <br/>
Installing FastQC from R
You can install automatically the FastQC tool from R as follow:
fastqc_install()
Running FastQC from R
The supported file formats by FastQC include:
- FASTQ
- gzip compressed FASTQ
Suppose that your working directory is organized as follow:
- home
- Documents
- FASTQ
- Documents
where, FASTQ is the directory containing your FASTQ files, for which you want to perform the quality control check.
To run FastQC from R, type this:
fastqc(fq.dir = "~/Documents/FASTQ", # FASTQ files directory
qc.dir = "~/Documents/FASTQC", # Results direcory
threads = 4 # Number of threads
)
FastQC Reports
For each sample, FastQC performs a series of tests called analysis modules.
These modules include:
- Basic Statistics,
- Per base sequence quality,
- Per tile sequence quality
- Per sequence quality scores,
- Per base sequence content,
- Per sequence GC content,
- Per base N content,
- Sequence Length Distribution,
- Sequence Duplication Levels,
- Overrepresented sequences,
- Adapter Content
- Kmer content
The interpretation of these modules are provided in the official documentation of the FastQC tool.
Aggregating Reports
Here, we provide an R function qc_aggregate() to walk the FastQC result directory, find all the FASTQC zipped output folders, read the fastqc_data.txt and the summary.txt files, and aggregate the information into a data frame.
In the example below, we’ll use a demo FastQC output directory available in the fastqcr package.
library(fastqcr)
# Demo QC dir
qc.dir <- system.file("fastqc_results", package = "fastqcr")
qc.dir
# [1] "/Users/kassambara/Library/R/3.6/library/fastqcr/fastqc_results"
# List of files in the directory
list.files(qc.dir)
# [1] "S1_fastqc.zip" "S2_fastqc.zip" "S3_fastqc.zip" "S4_fastqc.zip"
# [5] "S5_fastqc.zip"
The demo QC directory contains five zipped folders corresponding to the FastQC output for 5 samples.
Aggregating FastQC reports:
qc <- qc_aggregate(qc.dir)
qc
The aggregated report looks like this:
| sample | module | status | tot.seq | seq.length | pct.gc | pct.dup | | :----- | :--------------------------- | :----- | :------- | :--------- | -----: | ------: | | S2 | Per tile sequence quality | PASS | 50299587 | 35-76 | 48 | 15.70 | | S1 | Sequence Length Distribution | WARN | 50299587 | 35-76 | 48 | 17.24 | | S3 | Per sequence quality scores | PASS | 67255341 | 35-76 | 49 | 22.14 | | S3 | Per base sequence quality | PASS | 67255341 | 35-76 | 49 | 22.14 | | S2 | Per sequence GC content | WARN | 50299587 | 35-76 | 48 | 15.70 | | S5 | Sequence Duplication Levels | PASS | 65011962 | 35-76 | 48 | 18.15 | | S1 | Per base N content | PASS | 50299587 | 35-76 | 48 | 17.24 | | S5 | Basic Statistics | PASS | 65011962 | 35-76 | 48 | 18.15 | | S2 | Per sequence quality scores | PASS | 50299587 | 35-76 | 48 | 15.70 | | S1 | Per base sequence content | FAIL | 50299587 | 35-76 | 48 | 17.24 |
Column names:
- sample: sample names
- module: fastqc modules
- status: fastqc module status for each sample
- tot.seq: total sequences (i.e.: the number of reads)
- seq.length: sequence length
- pct.gc: percentage of GC content
- pct.dup: percentage of duplicate reads
The table shows, for each sample, the names of tested FastQC modules, the status of the test, as well as, some general statistics including the number of reads, the length of reads, the percentage of GC content and the percentage of duplicate reads.
</p> </div>Once you have the aggregated data you can use the dplyr package to easily inspect modules that failed or warned in samples. For example, the following R code shows samples with warnings and/or failures:
library(dplyr)
qc %>%
select(sample, module, status) %>%
filter(status %in% c("WARN", "FAIL")) %>%
arrange(sample)
# # A tibble: 15 × 3
# sample

