Contents

1 Introduction

The Rfastp package provides an interface to the all-in-one preprocessing for FastQ files toolkit fastp(Chen et al. 2018).

2 Installation

Use the BiocManager package to download and install the package from Bioconductor as follows:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("Rfastp")

If required, the latest development version of the package can also be installed from GitHub.

BiocManager::install("remotes")
BiocManager::install("RockefellerUniversity/Rfastp")

Once the package is installed, load it into your R session:

library(Rfastp)

3 FastQ Quality Control with rfastp

The package contains three example fastq files, corresponding to a single-end fastq file, a pair of paired-end fastq files.

se_read1 <- system.file("extdata","Fox3_Std_small.fq.gz",package="Rfastp")
pe_read1 <- system.file("extdata","reads1.fastq.gz",package="Rfastp")
pe_read2 <- system.file("extdata","reads2.fastq.gz",package="Rfastp")
outputPrefix <- tempfile(tmpdir = tempdir())

3.1 a normal QC run for single-end fastq file.

Rfastp support multiple threads, set threads number by parameter thread.

se_json_report <- rfastp(read1 = se_read1, 
    outputFastq = paste0(outputPrefix, "_se"), thread = 4)

3.2 a normal QC run for paired-end fastq files.

pe_json_report <- rfastp(read1 = pe_read1, read2 = pe_read2,
    outputFastq = paste0(outputPrefix, "_pe"))

3.3 merge paired-end fastq files after QC.

pe_merge_json_report <- rfastp(read1 = pe_read1, read2 = pe_read2, merge = TRUE,
    outputFastq = paste0(outputPrefix, '_unpaired'),
    mergeOut = paste0(outputPrefix, "_merged.fastq.gz"))

3.4 UMI processing

3.4.1 a normal UMI processing for 10X Single-Cell library.

umi_json_report <- rfastp(read1 = pe_read1, read2 = pe_read2, 
    outputFastq = paste0(outputPrefix, '_umi1'), umi = TRUE, umiLoc = "read1",
    umiLength = 16)

3.4.2 Set a customized UMI prefix and location in sequence name.

the following example will add prefix string before the UMI sequence in the sequence name. An "_" will be added between the prefix string and UMI sequence. The UMI sequences will be inserted into the sequence name before the first space.

umi_json_report <- rfastp(read1 = pe_read1, read2 = pe_read2, 
    outputFastq = paste0(outputPrefix, '_umi2'), umi = TRUE, umiLoc = "read1",
    umiLength = 16, umiPrefix = "#", umiNoConnection = TRUE, 
    umiIgnoreSeqNameSpace = TRUE)

3.5 A QC example with customized cutoffs and adapter sequence.

Trim poor quality bases at 3’ end base by base with quality higher than 5; trim poor quality bases at 5’ end by a 29bp window with mean quality higher than 20; disable the polyG trimming, specify the adapter sequence for read1.

clipr_json_report <- rfastp(read1 = se_read1, 
    outputFastq = paste0(outputPrefix, '_clipr'),
    disableTrimPolyG = TRUE,
    cutLowQualFront = TRUE,
    cutFrontWindowSize = 29,
    cutFrontMeanQual = 20,
    cutLowQualTail = TRUE,
    cutTailWindowSize = 1,
    cutTailMeanQual = 5,
    minReadLength = 29,
    adapterSequenceRead1 = 'GTGTCAGTCACTTCCAGCGG'
)

3.6 multiple input files for read1/2 in a vector.

rfastq can accept multiple input files, and it will concatenate the input files into one and the run fastp.

pe001_read1 <- system.file("extdata","splited_001_R1.fastq.gz",
    package="Rfastp")
pe002_read1 <- system.file("extdata","splited_002_R1.fastq.gz",
    package="Rfastp")
pe003_read1 <- system.file("extdata","splited_003_R1.fastq.gz",
    package="Rfastp")
pe004_read1 <- system.file("extdata","splited_004_R1.fastq.gz",
    package="Rfastp")
inputfiles <- c(pe001_read1, pe002_read1, pe003_read1, pe004_read1)
cat_rjson_report <- rfastp(read1 = inputfiles, 
    outputFastq = paste0(outputPrefix, "_merged1"))

4 concatenate multiple fastq files.

4.1 catfastq concatenate all the input files into a new file.

pe001_read2 <- system.file("extdata","splited_001_R2.fastq.gz",
    package="Rfastp")
pe002_read2 <- system.file("extdata","splited_002_R2.fastq.gz",
    package="Rfastp")
pe003_read2 <- system.file("extdata","splited_003_R2.fastq.gz",
    package="Rfastp")
pe004_read2 <- system.file("extdata","splited_004_R2.fastq.gz",
    package="Rfastp")
inputR2files <- c(pe001_read2, pe002_read2, pe003_read2, pe004_read2)
catfastq(output = paste0(outputPrefix,"_merged2_R2.fastq.gz"), 
    inputFiles = inputR2files)

5 Generate report tables/plots

5.1 A data frame for the summary.

dfsummary <- qcSummary(pe_json_report)

5.2 a ggplot2 object of base quality plot.

p1 <- curvePlot(se_json_report)
p1

5.3 a ggplot2 object of GC Content plot.

p2 <- curvePlot(se_json_report, curve="content_curves")
p2

5.4 a data frame for the trimming summary.

dfTrim <- trimSummary(pe_json_report)

6 Miscellaneous helper functions

usage of rfastp:

?rfastp

usage of catfastq:

?catfastq

usage of qcSummary:

?qcSummary

usage of trimSummary:

?trimSummary

usage of curvePlot:

?curvePlot

7 Acknowledgments

Thank you to Ji-Dung Luo for testing/vignette review/critical feedback, Doug Barrows for critical feedback/vignette review and Ziwei Liang for their support. # Session info

sessionInfo()
## R version 4.3.0 RC (2023-04-13 r84269)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.17-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               LC_TIME=en_GB             
##  [4] LC_COLLATE=C               LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
## [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] Rfastp_1.10.0    BiocStyle_2.28.0
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.3        jsonlite_1.8.4      highr_0.10          rjson_0.2.21       
##  [5] dplyr_1.1.2         compiler_4.3.0      BiocManager_1.30.20 tidyselect_1.2.0   
##  [9] Rcpp_1.0.10         stringr_1.5.0       magick_2.7.4        jquerylib_0.1.4    
## [13] scales_1.2.1        yaml_2.3.7          fastmap_1.1.1       ggplot2_3.4.2      
## [17] R6_2.5.1            plyr_1.8.8          labeling_0.4.2      generics_0.1.3     
## [21] knitr_1.42          tibble_3.2.1        bookdown_0.33       munsell_0.5.0      
## [25] bslib_0.4.2         pillar_1.9.0        rlang_1.1.0         utf8_1.2.3         
## [29] cachem_1.0.7        stringi_1.7.12      xfun_0.39           sass_0.4.5         
## [33] cli_3.6.1           withr_2.5.0         magrittr_2.0.3      digest_0.6.31      
## [37] grid_4.3.0          lifecycle_1.0.3     vctrs_0.6.2         evaluate_0.20      
## [41] glue_1.6.2          farver_2.1.1        fansi_1.0.4         colorspace_2.1-0   
## [45] reshape2_1.4.4      rmarkdown_2.21      tools_4.3.0         pkgconfig_2.0.3    
## [49] htmltools_0.5.5

References

Chen, Shifu, Yanqing Zhou, Yaru Chen, and Jia Gu. 2018. “fastp: an ultra-fast all-in-one FASTQ preprocessor.” Bioinformatics 34 (17): i884–i890. https://doi.org/10.1093/bioinformatics/bty560.