# systemPipeR: Workflows collection

Author: Daniela Cassol (danielac@ucr.edu) and Thomas Girke (thomas.girke@ucr.edu)

#### Last update: 05 May, 2023

#### Package

systemPipeR 2.7.0

Note: the most recent version of this tutorial can be found here.

Note: if you use `systemPipeR` in published research, please cite: Backman, T.W.H and Girke, T. (2016). `systemPipeR`: NGS Workflow and Report Generation Environment. BMC Bioinformatics, 17: 388. 10.1186/s12859-016-1241-0.

# 1 Workflow templates

The intended way of running `systemPipeR` workflows is via `*.Rmd` files, which can be executed either line-wise in interactive mode or with a single command from R or the command-line. This way comprehensive and reproducible analysis reports can be generated in PDF or HTML format in a fully automated manner by making use of the highly functional reporting utilities available for R.

Templates for setting up custom project reports are provided as `*.Rmd` files by the helper package `systemPipeRdata` and in the vignettes subdirectory of `systemPipeR`. The corresponding HTML of these report templates are available here: `systemPipeRNAseq`, `systemPipeRIBOseq`, `systemPipeChIPseq` and `systemPipeVARseq`. To work with `*.Rmd` files efficiently, basic knowledge of `knitr` and `Latex` or `R Markdown v2` is required.

## 1.1 Directory Structure

Figure 1: systemPipeR’s preconfigured directory structure

The working environment of the sample data loaded in the previous step contains the following pre-configured directory structure. Directory names are indicated in green. Users can change this structure as needed, but need to adjust the code in their workflows accordingly.

- workflow/ (e.g. rnaseq/)
  - This is the root directory of the R session running the workflow.
  - Run script ( *.Rmd) and sample annotation (targets.txt) files are located here.
  - Note, this directory can have any name (e.g. rnaseq, varseq). Changing its name does not require any modifications in the run script(s).
  - Important subdirectories:
    - param/
      - Stores non-CWL parameter files such as: *.param, *.tmpl and *.run.sh. These files are only required for backwards compatibility to run old workflows using the previous custom command-line interface.
      - param/cwl/: This subdirectory stores all the CWL parameter files. To organize workflows, each can have its own subdirectory, where all `CWL param` and `input.yml` files need to be in the same subdirectory.
    - data/
      - FASTQ files
      - FASTA file of reference (e.g. reference genome)
      - Annotation files
      - etc.
    - results/
      - Analysis results are usually written to this directory, including: alignment, variant and peak files (BAM, VCF, BED); tabular result files; and image/plot files
      - Note, the user has the option to organize results files for a given sample and analysis step in a separate subdirectory.

The following parameter files are included in each workflow template:

1. `targets.txt`: initial one provided by user; downstream `targets_*.txt` files are generated automatically
2. `*.param/cwl`: defines parameter for input/output file operations, e.g.:
   - `hisat2-se/hisat2-mapping-se.cwl`
   - `hisat2-se/hisat2-mapping-se.yml`
3. `*_run.sh`: optional bash scripts
4. Configuration files for computer cluster environments (skip on single machines):
   - `.batchtools.conf.R`: defines the type of scheduler for `batchtools` pointing to template file of cluster, and located in user’s home directory
   - `*.tmpl`: specifies parameters of scheduler used by a system, e.g. Torque, SGE, Slurm, etc.

# 2 RNA-Seq Workflow

This workflow demonstrates how to use various utilities for building and running automated end-to-end analysis workflows for `RNA-Seq` data.

The full workflow can be found here: HTML, .Rmd, and .R.

## 2.1 Loading package and workflow template

Load the `RNA-Seq` sample workflow into your current working directory.

    library(systemPipeRdata)
    genWorkenvir(workflow = "rnaseq")
    setwd("rnaseq")

## 2.2 Create the workflow

This template provides some common steps for a `RNAseq` workflow. One can add, remove, modify workflow steps by operating on the `sal` object.

    sal <- SPRproject()
    sal <- importWF(sal, file_path = "systemPipeRNAseq.Rmd", verbose = FALSE)

Workflow includes following steps:

1. Read preprocessing
   - Quality filtering (trimming)
   - FASTQ quality report
2. Alignments: `HISAT2` (or any other RNA-Seq aligner)
3. Alignment stats
4. Read counting
5. Sample-wise correlation analysis
6. Analysis of differentially expressed genes (DEGs)
7. GO term enrichment analysis
8. Gene-wise clustering

## 2.3 Run workflow

    sal <- runWF(sal)

## 2.4 Workflow visualization

    plotWF(sal)

## 2.5 Report generation

    sal <- renderReport(sal)
    sal <- renderLogs(sal)

# 3 ChIP-Seq Workflow

This workflow demonstrates how to use various utilities for building and running automated end-to-end analysis workflows for `ChIP-Seq` data.

The full workflow can be found here: HTML, .Rmd, and .R.

## 3.1 Loading package and workflow template

Load the `ChIP-Seq` sample workflow into your current working directory.

    library(systemPipeRdata)
    genWorkenvir(workflow = "chipseq")
    setwd("chipseq")

Workflow includes following steps:

1. Read preprocessing
   - Quality filtering (trimming)
   - FASTQ quality report
2. Alignments: `Bowtie2` or `rsubread`
3. Alignment stats
4. Peak calling: `MACS2`
5. Peak annotation with genomic context
6. Differential binding analysis
7. GO term enrichment analysis
8. Motif analysis

## 3.2 Create the workflow

This template provides some common steps for a `ChIPseq` workflow. One can add, remove, modify workflow steps by operating on the `sal` object.

    sal <- SPRproject()
    sal <- importWF(sal, file_path = "systemPipeChIPseq.Rmd", verbose = FALSE)

## 3.3 Run workflow

    sal <- runWF(sal)

## 3.4 Workflow visualization

    plotWF(sal)

## 3.5 Report generation

    sal <- renderReport(sal)
    sal <- renderLogs(sal)

# 4 VAR-Seq Workflow

This workflow demonstrates how to use various utilities for building and running automated end-to-end analysis workflows for `VAR-Seq` data.

The full workflow can be found here: HTML, .Rmd, and .R.

## 4.1 Loading package and workflow template

Load the `VAR-Seq` sample workflow into your current working directory.

    library(systemPipeRdata)
    genWorkenvir(workflow = "varseq")
    setwd("varseq")

Workflow includes following steps:

1. Read preprocessing
   - Quality filtering (trimming)
   - FASTQ quality report
2. Alignments: `gsnap`, `bwa`
3. Variant calling: `VariantTools`, `GATK`, `BCFtools`
4. Variant filtering: `VariantTools` and `VariantAnnotation`
5. Variant annotation: `VariantAnnotation`
6. Combine results from many samples
7. Summary statistics of samples

## 4.2 Create the workflow

This template provides some common steps for a `VARseq` workflow. One can add, remove, modify workflow steps by operating on the `sal` object.

    sal <- SPRproject()
    sal <- importWF(sal, file_path = "systemPipeVARseq.Rmd", verbose = FALSE)

## 4.3 Run workflow

    sal <- runWF(sal)

## 4.4 Workflow visualization

    plotWF(sal)

## 4.5 Report generation

    sal <- renderReport(sal)
    sal <- renderLogs(sal)

# 5 Ribo-Seq Workflow

This workflow demonstrates how to use various utilities for building and running automated end-to-end analysis workflows for `RIBO-Seq` data.

The full workflow can be found here: HTML, .Rmd, and .R.

## 5.1 Loading package and workflow template

Load the `RIBO-Seq` sample workflow into your current working directory.

    library(systemPipeRdata)
    genWorkenvir(workflow = "riboseq")
    setwd("riboseq")

Workflow includes following steps:

1. Read preprocessing
   - Adaptor trimming and quality filtering
   - FASTQ quality report
2. Alignments: `HISAT2` (or any other RNA-Seq aligner)
3. Alignment stats
4. Compute read distribution across genomic features
5. Adding custom features to workflow (e.g. uORFs)
6. Genomic read coverage along transcripts
7. Read counting
8. Sample-wise correlation analysis
9. Analysis of differentially expressed genes (DEGs)
10. GO term enrichment analysis
11. Gene-wise clustering
12. Differential ribosome binding (translational efficiency)

This template provides some common steps for a `RIBOseq` workflow. One can add, remove, modify workflow steps by operating on the `sal` object.

    sal <- SPRproject()
    sal <- importWF(sal, file_path = "systemPipeRIBOseq.Rmd", verbose = FALSE)

## 5.2 Run workflow

    sal <- runWF(sal)

## 5.3 Workflow visualization

    plotWF(sal)

## 5.4 Report generation

    sal <- renderReport(sal)
    sal <- renderLogs(sal)

# 6 Version information

    sessionInfo()

    ## R version 4.3.0 RC (2023-04-13 r84266)
    ## Platform: x86_64-apple-darwin20 (64-bit)
    ## Running under: macOS Monterey 12.5.1
    ##
    ## Matrix products: default
    ## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib
    ## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
    ##
    ## locale:
    ## [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] stats4    stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ##  [1] magrittr_2.0.3              systemPipeR_2.7.0
    ##  [3] ShortRead_1.59.0            GenomicAlignments_1.37.0
    ##  [5] SummarizedExperiment_1.31.1 Biobase_2.61.0
    ##  [7] MatrixGenerics_1.13.0       matrixStats_0.63.0
    ##  [9] BiocParallel_1.35.1         Rsamtools_2.17.0
    ## [11] Biostrings_2.69.0           XVector_0.41.1
    ## [13] GenomicRanges_1.53.1        GenomeInfoDb_1.37.1
    ## [15] IRanges_2.35.1              S4Vectors_0.39.1
    ## [17] BiocGenerics_0.47.0         BiocStyle_2.29.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] tidyselect_1.2.0        viridisLite_0.4.2       dplyr_1.1.2
    ##  [4] farver_2.1.1            bitops_1.0-7            fastmap_1.1.1
    ##  [7] RCurl_1.98-1.12         digest_0.6.31           lifecycle_1.0.3
    ## [10] ellipsis_0.3.2          compiler_4.3.0          rlang_1.1.1
    ## [13] sass_0.4.6              tools_4.3.0             utf8_1.2.3
    ## [16] yaml_2.3.7              systemPipeRdata_2.5.0   knitr_1.42
    ## [19] S4Arrays_1.1.2          labeling_0.4.2          htmlwidgets_1.6.2
    ## [22] interp_1.1-4            DelayedArray_0.27.2     xml2_1.3.4
    ## [25] RColorBrewer_1.1-3      withr_2.5.0             hwriter_1.3.2.1
    ## [28] grid_4.3.0              fansi_1.0.4             latticeExtra_0.6-30
    ## [31] colorspace_2.1-0        ggplot2_3.4.2           scales_1.2.1
    ## [34] cli_3.6.1               rmarkdown_2.21          crayon_1.5.2
    ## [37] generics_0.1.3          remotes_2.4.2           rstudioapi_0.14
    ## [40] httr_1.4.5              cachem_1.0.8            stringr_1.5.0
    ## [43] zlibbioc_1.47.0         rvest_1.0.3             parallel_4.3.0
    ## [46] formatR_1.14            BiocManager_1.30.20     vctrs_0.6.2
    ## [49] webshot_0.5.4           Matrix_1.5-4            jsonlite_1.8.4
    ## [52] bookdown_0.33           systemfonts_1.0.4       jpeg_0.1-10
    ## [55] magick_2.7.4            crosstalk_1.2.0         jquerylib_0.1.4
    ## [58] glue_1.6.2              codetools_0.2-19        DT_0.27
    ## [61] stringi_1.7.12          gtable_0.3.3            deldir_1.0-6
    ## [64] munsell_0.5.0           tibble_3.2.1            pillar_1.9.0
    ## [67] htmltools_0.5.5         GenomeInfoDbData_1.2.10 R6_2.5.1
    ## [70] evaluate_0.20           kableExtra_1.3.4        lattice_0.21-8
    ## [73] highr_0.10              png_0.1-8               bslib_0.4.2
    ## [76] Rcpp_1.0.10             svglite_2.1.1           SparseArray_1.1.2
    ## [79] xfun_0.39               pkgconfig_2.0.3

# 7 Funding

This project is funded by NSF award ABI-1661152.

# 8 References