# systemPipeR: Workflows collection

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

#### Last update: 01 May, 2021

#### Package

systemPipeR 1.24.6

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 `sytemPipeR` 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. The following shows how to execute a workflow (e.g., systemPipeRNAseq.Rmd) from the command-line.

    Rscript -e "rmarkdown::render('systemPipeRNAseq.Rmd')"

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

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 Run workflow

Next, run the chosen sample workflow `systemPipeRNAseq` (.Rmd) by executing from the command-line `make -B` within the `rnaseq` directory. Alternatively, one can run the code from the provided `*.Rmd` template file from within R interactively.

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

# 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")

## 3.2 Run workflow

Next, run the chosen sample workflow `systemPipeChIPseq` (.Rmd) by executing from the command-line `make -B` within the `chipseq` directory. Alternatively, one can run the code from the provided `*.Rmd` template file from within R interactively.

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`, `BayesPeak`
5. Peak annotation with genomic context
6. Differential binding analysis
7. GO term enrichment analysis
8. Motif analysis

# 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")

## 4.2 Run workflow

Next, run the chosen sample workflow `systemPipeVARseq` (.Rmd) by executing from the command-line `make -B` within the `varseq` directory. Alternatively, one can run the code from the provided `*.Rmd` template file from within R interactively.

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

# 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")

## 5.2 Run workflow

Next, run the chosen sample workflow `systemPipeRIBOseq` (.Rmd) by executing from the command-line `make -B` within the `ribseq` directory. Alternatively, one can run the code from the provided `*.Rmd` template file from within R interactively.

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)

# 6 Version information

    sessionInfo()

    ## R version 4.0.5 (2021-03-31)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server 2012 R2 x64 (build 9600)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.1252
    ## [3] LC_MONETARY=English_United States.1252
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.1252
    ##
    ## attached base packages:
    ## [1] stats4    parallel  stats     graphics  grDevices utils     datasets
    ## [8] methods   base
    ##
    ## other attached packages:
    ##  [1] DESeq2_1.30.1               magrittr_2.0.1
    ##  [3] batchtools_0.9.15           ape_5.5
    ##  [5] ggplot2_3.3.3               systemPipeR_1.24.6
    ##  [7] ShortRead_1.48.0            GenomicAlignments_1.26.0
    ##  [9] SummarizedExperiment_1.20.0 Biobase_2.50.0
    ## [11] MatrixGenerics_1.2.1        matrixStats_0.58.0
    ## [13] BiocParallel_1.24.1         Rsamtools_2.6.0
    ## [15] Biostrings_2.58.0           XVector_0.30.0
    ## [17] GenomicRanges_1.42.0        GenomeInfoDb_1.26.7
    ## [19] IRanges_2.24.1              S4Vectors_0.28.1
    ## [21] BiocGenerics_0.36.1         BiocStyle_2.18.1
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] GOstats_2.56.0           backports_1.2.1          BiocFileCache_1.14.0
    ##   [4] systemfonts_1.0.1        GSEABase_1.52.1          splines_4.0.5
    ##   [7] digest_0.6.27            htmltools_0.5.1.1        magick_2.7.1
    ##  [10] GO.db_3.12.1             fansi_0.4.2              checkmate_2.0.0
    ##  [13] memoise_2.0.0            BSgenome_1.58.0          base64url_1.4
    ##  [16] limma_3.46.0             annotate_1.68.0          svglite_2.0.0
    ##  [19] askpass_1.1              prettyunits_1.1.1        jpeg_0.1-8.1
    ##  [22] colorspace_2.0-0         blob_1.2.1               rvest_1.0.0
    ##  [25] rappdirs_0.3.3           xfun_0.22                dplyr_1.0.5
    ##  [28] crayon_1.4.1             RCurl_1.98-1.3           jsonlite_1.7.2
    ##  [31] graph_1.68.0             genefilter_1.72.1        brew_1.0-6
    ##  [34] survival_3.2-11          VariantAnnotation_1.36.0 glue_1.4.2
    ##  [37] kableExtra_1.3.4         gtable_0.3.0             zlibbioc_1.36.0
    ##  [40] webshot_0.5.2            DelayedArray_0.16.3      V8_3.4.2
    ##  [43] Rgraphviz_2.34.0         scales_1.1.1             pheatmap_1.0.12
    ##  [46] DBI_1.1.1                edgeR_3.32.1             Rcpp_1.0.6
    ##  [49] viridisLite_0.4.0        xtable_1.8-4             progress_1.2.2
    ##  [52] bit_4.0.4                rsvg_2.1.1               AnnotationForge_1.32.0
    ##  [55] httr_1.4.2               RColorBrewer_1.1-2       ellipsis_0.3.2
    ##  [58] farver_2.1.0             pkgconfig_2.0.3          XML_3.99-0.6
    ##  [61] sass_0.3.1               dbplyr_2.1.1             locfit_1.5-9.4
    ##  [64] utf8_1.2.1               labeling_0.4.2           tidyselect_1.1.1
    ##  [67] rlang_0.4.11             AnnotationDbi_1.52.0     munsell_0.5.0
    ##  [70] tools_4.0.5              cachem_1.0.4             generics_0.1.0
    ##  [73] RSQLite_2.2.7            evaluate_0.14            stringr_1.4.0
    ##  [76] fastmap_1.1.0            yaml_2.2.1               knitr_1.33
    ##  [79] bit64_4.0.5              purrr_0.3.4              RBGL_1.66.0
    ##  [82] nlme_3.1-152             formatR_1.9              xml2_1.3.2
    ##  [85] biomaRt_2.46.3           debugme_1.1.0            compiler_4.0.5
    ##  [88] rstudioapi_0.13          curl_4.3.1               png_0.1-7
    ##  [91] geneplotter_1.68.0       tibble_3.1.1             bslib_0.2.4
    ##  [94] stringi_1.5.3            highr_0.9                GenomicFeatures_1.42.3
    ##  [97] lattice_0.20-41          Matrix_1.3-2             vctrs_0.3.8
    ## [100] pillar_1.6.0             lifecycle_1.0.0          BiocManager_1.30.12
    ## [103] jquerylib_0.1.4          data.table_1.14.0        bitops_1.0-7
    ## [106] rtracklayer_1.50.0       R6_2.5.0                 latticeExtra_0.6-29
    ## [109] hwriter_1.3.2            bookdown_0.22            codetools_0.2-18
    ## [112] assertthat_0.2.1         openssl_1.4.4            Category_2.56.0
    ## [115] rjson_0.2.20             withr_2.4.2              GenomeInfoDbData_1.2.4
    ## [118] hms_1.0.0                grid_4.0.5               DOT_0.1
    ## [121] rmarkdown_2.7

# 7 Funding

This project is funded by NSF award ABI-1661152.

# 8 References