1 Data Visualization with systemPipeR

systemPipeTools package extends the widely used systemPipeR (SPR) (H Backman and Girke 2016) workflow environment with enhanced toolkit for data visualization, including utilities to automate the analysis of differentially expressed genes (DEGs). systemPipeTools provides functions for data transformation and data exploration via scatterplots, hierarchical clustering heatMaps, principal component analysis, multidimensional scaling, generalized principal components, t-Distributed Stochastic Neighbor embedding (t-SNE), and MA and volcano plots. All these utilities can be integrated with the modular design of the systemPipeR environment that allows users to easily substitute any of these features and/or custom with alternatives.

1.1 Installation

systemPipeTools environment can be installed from the R console using the BiocManager::install command. The associated package systemPipeR can be installed the same way. The latter provides core functionalities for defining workflows, interacting with command-line software, and executing both R and/or command-line software, as well as generating publication-quality analysis reports.

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

1.1.1 Loading package and documentation

library("systemPipeTools")  # Loads the package
library(help = "systemPipeTools")  # Lists package info
vignette("systemPipeTools")  # Opens vignette

1.2 Metadata and Reads Counting Information

The first step is importing the targets file and raw reads counting table. - The targets file defines all FASTQ files and sample comparisons of the analysis workflow. - The raw reads counting table represents all the reads that map to gene (row) for each sample (columns).

## Targets file
targetspath <- system.file("extdata", "targets.txt", package = "systemPipeR")
targets <- read.delim(targetspath, comment = "#")
cmp <- systemPipeR::readComp(file = targetspath, format = "matrix", delim = "-")
## Count table file
countMatrixPath <- system.file("extdata", "countDFeByg.xls", package = "systemPipeR")
countMatrix <- read.delim(countMatrixPath, row.names = 1)
showDT(countMatrix)

1.3 Data Transformation

For gene differential expression, raw counts are required, however for data visualization or clustering, it can be useful to work with transformed count data. exploreDDS function is convenience wrapper to transform raw read counts using the DESeq2 package transformations methods. The input file has to contain all the genes, not just differentially expressed ones. Supported methods include variance stabilizing transformation (vst) (Anders and Huber (2010)), and regularized-logarithm transformation or rlog (Love, Huber, and Anders (2014)).

exploredds <- exploreDDS(countMatrix, targets, cmp = cmp[[1]], preFilter = NULL,
    transformationMethod = "rlog")
exploredds
## class: DESeqTransform 
## dim: 116 18 
## metadata(1): version
## assays(1): ''
## rownames(116): AT1G01010 AT1G01020 ... ATMG00180 ATMG00200
## rowData names(51): baseMean baseVar ... dispFit rlogIntercept
## colnames(18): M1A M1B ... V12A V12B
## colData names(2): condition sizeFactor

Users are strongly encouraged to consult the DESeq2 vignette for more detailed information on this topic and how to properly run DESeq2 on datasets with more complex experimental designs.

1.4 Scatterplot

To decide which transformation to choose, we can visualize the transformation effect comparing two samples or a grid of all samples, as follows:

exploreDDSplot(countMatrix, targets, cmp = cmp[[1]], preFilter = NULL, samples = c("M12A",
    "M12A", "A12A", "A12A"), scattermatrix = TRUE)

The scatterplots are created using the log2 transform normalized reads count, variance stabilizing transformation (VST) (Anders and Huber (2010)), and regularized-logarithm transformation or rlog (Love, Huber, and Anders (2014)).

1.5 Hierarchical Clustering Dendrogram

The following computes the sample-wise correlation coefficients using the stats::cor() function from the transformed expression values. After transformation to a distance matrix, hierarchical clustering is performed with the stats::hclust function and the result is plotted as a dendrogram, as follows:

hclustplot(exploredds, method = "spearman")

The function provides the utility to save the plot automatically.

1.6 Hierarchical Clustering HeatMap

This function performs hierarchical clustering on the transformed expression matrix generated within the DESeq2 package. It uses, by default, a Pearson correlation-based distance measure and complete linkage for cluster join. If samples selected in the clust argument, it will be applied the stats::dist() function to the transformed count matrix to get sample-to-sample distances. Also, it is possible to generate the pheatmap or plotly plot format.

## Samples plot
heatMaplot(exploredds, clust = "samples", plotly = FALSE)

If ind selected in the clust argument, it is necessary to provide the list of differentially expressed genes for the exploredds subset.

## Individuals genes identified in DEG analysis DEG analysis with `systemPipeR`
degseqDF <- systemPipeR::run_DESeq2(countDF = countMatrix, targets = targets, cmp = cmp[[1]],
    independent = FALSE)
DEG_list <- systemPipeR::filterDEGs(degDF = degseqDF, filter = c(Fold = 2, FDR = 10))

### Plot
heatMaplot(exploredds, clust = "ind", DEGlist = unique(as.character(unlist(DEG_list[[1]]))))

The function provides the utility to save the plot automatically.

1.7 Principal Component Analysis

This function plots a Principal Component Analysis (PCA) from transformed expression matrix. This plot shows samples variation based on the expression values and identifies batch effects.

PCAplot(exploredds, plotly = FALSE)
## using ntop=500 top features by variance

The function provides the utility to save the plot automatically.

1.8 Multidimensional scaling with MDSplot

This function computes and plots multidimensional scaling analysis for dimension reduction of count expression matrix. Internally, it is applied the stats::dist() function to the transformed count matrix to get sample-to-sample distances.

MDSplot(exploredds, plotly = FALSE)

The function provides the utility to save the plot automatically.

1.9 Dimension Reduction with GLMplot

This function computes and plots generalized principal components analysis for dimension reduction of count expression matrix.

exploredds_r <- exploreDDS(countMatrix, targets, cmp = cmp[[1]], preFilter = NULL,
    transformationMethod = "raw")
GLMplot(exploredds_r, plotly = FALSE)

The function provides the utility to save the plot automatically.

1.10 MA plot

This function plots log2 fold changes (y-axis) versus the mean of normalized counts (on the x-axis). Statistically significant features are colored.

MAplot(degseqDF, comparison = "M12-A12", filter = c(Fold = 1, FDR = 20), genes = "ATCG00280")

The function provides the utility to save the plot automatically.

1.11 t-Distributed Stochastic Neighbor embedding with tSNEplot

This function computes and plots t-Distributed Stochastic Neighbor embedding (t-SNE) analysis for unsupervised nonlinear dimensionality reduction of count expression matrix. Internally, it is applied the Rtsne::Rtsne() (Krijthe 2015) function, using the exact t-SNE computing with theta=0.0.

tSNEplot(countMatrix, targets, perplexity = 5)

1.12 Volcano plot

A simple function that shows statistical significance (p-value) versus magnitude of change (log2 fold change).

volcanoplot(degseqDF, comparison = "M12-A12", filter = c(Fold = 1, FDR = 20), genes = "ATCG00280")

2 Version information

sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-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] DESeq2_1.42.0               systemPipeR_2.8.0          
##  [3] ShortRead_1.60.0            GenomicAlignments_1.38.0   
##  [5] SummarizedExperiment_1.32.0 Biobase_2.62.0             
##  [7] MatrixGenerics_1.14.0       matrixStats_1.0.0          
##  [9] BiocParallel_1.36.0         Rsamtools_2.18.0           
## [11] Biostrings_2.70.0           XVector_0.42.0             
## [13] GenomicRanges_1.54.0        GenomeInfoDb_1.38.0        
## [15] IRanges_2.36.0              S4Vectors_0.40.0           
## [17] BiocGenerics_0.48.0         systemPipeTools_1.10.0     
## [19] BiocStyle_2.30.0           
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-7            deldir_1.0-9            formatR_1.14           
##  [4] rlang_1.1.1             magrittr_2.0.3          compiler_4.3.1         
##  [7] png_0.1-8               vctrs_0.6.4             stringr_1.5.0          
## [10] pkgconfig_2.0.3         crayon_1.5.2            fastmap_1.1.1          
## [13] magick_2.8.1            ellipsis_0.3.2          labeling_0.4.3         
## [16] utf8_1.2.4              rmarkdown_2.25          purrr_1.0.2            
## [19] xfun_0.40               zlibbioc_1.48.0         cachem_1.0.8           
## [22] aplot_0.2.2             jsonlite_1.8.7          DelayedArray_0.28.0    
## [25] reshape_0.8.9           jpeg_0.1-10             parallel_4.3.1         
## [28] R6_2.5.1                stringi_1.7.12          bslib_0.5.1            
## [31] RColorBrewer_1.1-3      GGally_2.1.2            jquerylib_0.1.4        
## [34] Rcpp_1.0.11             bookdown_0.36           knitr_1.44             
## [37] glmpca_0.2.0            Matrix_1.6-1.1          tidyselect_1.2.0       
## [40] abind_1.4-5             yaml_2.3.7              codetools_0.2-19       
## [43] hwriter_1.3.2.1         lattice_0.22-5          tibble_3.2.1           
## [46] plyr_1.8.9              withr_2.5.1             treeio_1.26.0          
## [49] evaluate_0.22           Rtsne_0.16              gridGraphics_0.5-1     
## [52] pillar_1.9.0            BiocManager_1.30.22     ggtree_3.10.0          
## [55] DT_0.30                 ggfun_0.1.3             plotly_4.10.3          
## [58] generics_0.1.3          RCurl_1.98-1.12         ggplot2_3.4.4          
## [61] munsell_0.5.0           scales_1.2.1            tidytree_0.4.5         
## [64] glue_1.6.2              pheatmap_1.0.12         lazyeval_0.2.2         
## [67] tools_4.3.1             interp_1.1-4            data.table_1.14.8      
## [70] locfit_1.5-9.8          fs_1.6.3                grid_4.3.1             
## [73] tidyr_1.3.0             ape_5.7-1               crosstalk_1.2.0        
## [76] latticeExtra_0.6-30     colorspace_2.1-0        nlme_3.1-163           
## [79] GenomeInfoDbData_1.2.11 patchwork_1.1.3         cli_3.6.1              
## [82] fansi_1.0.5             S4Arrays_1.2.0          viridisLite_0.4.2      
## [85] dplyr_1.1.3             gtable_0.3.4            yulab.utils_0.1.0      
## [88] sass_0.4.7              digest_0.6.33           SparseArray_1.2.0      
## [91] ggrepel_0.9.4           ggplotify_0.1.2         farver_2.1.1           
## [94] htmlwidgets_1.6.2       memoise_2.0.1           htmltools_0.5.6.1      
## [97] lifecycle_1.0.3         httr_1.4.7              MASS_7.3-60

3 Funding

This project is funded by NSF award ABI-1661152.

References

Anders, Simon, and Wolfgang Huber. 2010. “Differential Expression Analysis for Sequence Count Data.” Genome Biol. 11 (10): R106.

H Backman, Tyler W, and Thomas Girke. 2016. “systemPipeR: NGS workflow and report generation environment.” BMC Bioinformatics 17 (1): 388. https://doi.org/10.1186/s12859-016-1241-0.

Krijthe, Jesse H. 2015. Rtsne: T-Distributed Stochastic Neighbor Embedding Using Barnes-Hut Implementation. https://github.com/jkrijthe/Rtsne.

Love, Michael, Wolfgang Huber, and Simon Anders. 2014. “Moderated Estimation of Fold Change and Dispersion for RNA-seq Data with DESeq2.” Genome Biol. 15 (12): 550. https://doi.org/10.1186/s13059-014-0550-8.