Introduction using limma or edgeR

Introduction

In this vignette we present the basic features of Glimma. Glimma is an interactive R widget for creating plots for differential expression analysis, created using the Vega and htmlwidgets frameworks. The created plots can be embedded in R Markdown, or exported as standalone HTML documents. The data presented here is slightly modified from the RNAseq123 workflow and only a single contrast has been performed for simplicity. We can use either limma or edgeR to fit the models and they both share upstream steps in common.

To begin, the DGEList object from the workflow has been included with the package as internal data.

library(Glimma)
library(limma)
library(edgeR)

dge <- readRDS(system.file("RNAseq123/dge.rds", package = "Glimma"))

MDS Plot

The multidimensional scaling (MDS) plot is frequently used to explore differences in samples. When data has been MDS transformed, the first two dimensions explain the greatest variance between samples, and the amount of variance decreases monotonically with increasing dimension.

The Glimma MDS plot contains two main components:

  1. a plot showing two MDS dimensions, and
  2. a plot of the eigenvalues of each dimension

The Glimma MDS allows different dimensions to be plotted against each other, and for the colours of the points to be changed based on predefined factors. The grouping variables are taken from the samples component of DGEList objects used in limma and edgeR.

glimmaMDS(dge)

Interactions with the plot

In the plot above, try:

Modifications to the plot

Adjusting plot size

Usage: glimmaMDS(dge, width=1200, height=1200)

Users can specify the width and height of the MDS plot widget in pixels. The default width and height are 900 and 500 respectively.

Continuous colour schemes

Usage: glimmaMDS(dge, continuous.color=TRUE)

This argument specifies that continuous colour schemes should be used, which can be useful for colouring samples by their expression for a particular gene.

Custom experimental groups

Usage: glimmaMDS(dge, groups=[vector or data frame])

This allows the user to change the associated sample information such as experimental groups. This information is displayed in mouseover tooltips and can be used to adjust the plot using scale_by, colour_by and shape_by fields.

MA Plot

The MA plot is a visualisation that plots the log-fold-change between experimental groups (M) against the average expression across all the samples (A) for each gene.

The Glimma MA plot contains two main components:

  1. a plot of summary statistics across all genes that have been tested, and
  2. a plot of gene expression from individual samples for a given gene

The second plot shows gene expression from the last selected sample, which can be selected from the table or directly from the summary plot.

To create this plot we need to run differential expression (DE) analysis for our data using either the limma package or the edgeR package (both are shown below). First, we load in design and contrast matrices generated from the RNAseq123 workflow.

design <- readRDS(
  system.file("RNAseq123/design.rds", package = "Glimma"))
contr.matrix <- readRDS(
  system.file("RNAseq123/contr.matrix.rds", package = "Glimma"))

Using limma

We fit our DE analysis using limma to give us an object that contains test statistics for each gene.

Using edgeR

Alternatively, we can fit our DE analysis using edgeR.

The MA plot can then be created using the fitted object containing the statistics about the genes (either efit or glrt), and the dge object containing raw counts and information about the samples. We use results from limma in the following example:

Interactions with the plot

In the plot above, try:

Modifications to the plot

Adjusting plot size

Usage: glimmaMA(efit, dge=dge, width=1200, height=1200)

Users can specify the width and height of the MA plot widget in pixels. The default width and height are both 920px.

Changing DE status colouring

Usage: glimmaMA(efit, dge=dge, status.cols=c("blue", "grey", "red")

Users can customise the colours associated with the differential expression status of a gene using the status.cols argument. A vector of length three should be passed in, where each element must be a valid CSS colour string.

Changing sample colours in expression plot

Usage: glimmaMA(efit, dge=dge, sample.cols=c("yellow", "yellow", "yellow", "red", "red", "red", "purple", "purple", "purple")

Users can provide a vector of valid CSS colour strings of length ncol(dge$counts) or ncol(counts) which correspond to sample colours. The colours used in the example here reflect the sequencing lane.

Overriding counts and groups

Usage: glimmaMA(efit, counts=counts, groups=groups)

Glimma extracts counts and experimental data from the dge argument for limma and edgeR data types. However, users can optionally supply their own counts and experimental groups using the counts and groups arguments.

Transforming counts values

Usage: glimmaMA(efit, dge=dge, transform.counts="rpkm")

The transform.counts argument allows users to choose between strategies for transforming counts data displayed on the expression plot. The default argument is "logcpm" which log-transforms counts using edgeR::cpm(counts, log=TRUE). Other options are "rpkm" for edgeR::rpkm(counts), cpm for edgeR::cpm(counts) and none for no transformation.

Changing displayed columns in gene annotation The gene annotations are pulled from the DGEList object by default. This can be overwritten by providing a different table of annotations via the anno argument, the substitute annotations must have the same number of rows as the counts matrix and the genes must be in the same order as in the counts.

Some annotations may contain too many columsn to be sensibly displayed. The display.columns argument can be used to control the columns displayed in the plot. A vector of column names are to be provided for selecting the columns that will be displayed in the interactive plot.

Volcano Plot

A popular alternative to the MA plot for plotting the output of differential expression analysis the the volcano plot. This can be produced using the glimmaVolcano function and the same arguments as the glimmaMA.

glimmaVolcano(efit, dge = dge)

Saving widgets

The plots created are automatically embedded into Rmarkdown reports, but having many interactive plots can significantly slow down the page. It is instead recommended to save the plots and link to them via markdown hyperlinks. Plots can be saved either by providing the html argument a filename, or by using htmlwidgets::saveWidget, which also provides further customisation options. Let us now create a html file named “ma-plot.html” in our working directory.

htmlwidgets::saveWidget(glimmaMA(efit, dge = dge), "ma-plot.html")
# you can link to it in Rmarkdown using [MA-plot](ma-plot.html)

Session Info

sessionInfo()
#> R version 4.2.0 RC (2022-04-19 r82224)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.15-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.15-bioc/R/lib/libRlapack.so
#> 
#> 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       
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] DESeq2_1.36.0               SummarizedExperiment_1.26.0
#>  [3] Biobase_2.56.0              MatrixGenerics_1.8.0       
#>  [5] matrixStats_0.62.0          GenomicRanges_1.48.0       
#>  [7] GenomeInfoDb_1.32.0         IRanges_2.30.0             
#>  [9] S4Vectors_0.34.0            BiocGenerics_0.42.0        
#> [11] edgeR_3.38.0                limma_3.52.0               
#> [13] Glimma_2.6.0               
#> 
#> loaded via a namespace (and not attached):
#>  [1] httr_1.4.2             sass_0.4.1             bit64_4.0.5           
#>  [4] jsonlite_1.8.0         splines_4.2.0          bslib_0.3.1           
#>  [7] assertthat_0.2.1       blob_1.2.3             GenomeInfoDbData_1.2.8
#> [10] yaml_2.3.5             pillar_1.7.0           RSQLite_2.2.12        
#> [13] lattice_0.20-45        glue_1.6.2             digest_0.6.29         
#> [16] RColorBrewer_1.1-3     XVector_0.36.0         colorspace_2.0-3      
#> [19] htmltools_0.5.2        Matrix_1.4-1           pkgconfig_2.0.3       
#> [22] XML_3.99-0.9           genefilter_1.78.0      zlibbioc_1.42.0       
#> [25] purrr_0.3.4            xtable_1.8-4           scales_1.2.0          
#> [28] BiocParallel_1.30.0    tibble_3.1.6           annotate_1.74.0       
#> [31] KEGGREST_1.36.0        generics_0.1.2         ggplot2_3.3.5         
#> [34] ellipsis_0.3.2         cachem_1.0.6           cli_3.3.0             
#> [37] survival_3.3-1         magrittr_2.0.3         crayon_1.5.1          
#> [40] memoise_2.0.1          evaluate_0.15          fansi_1.0.3           
#> [43] tools_4.2.0            lifecycle_1.0.1        stringr_1.4.0         
#> [46] locfit_1.5-9.5         munsell_0.5.0          DelayedArray_0.22.0   
#> [49] AnnotationDbi_1.58.0   Biostrings_2.64.0      compiler_4.2.0        
#> [52] jquerylib_0.1.4        rlang_1.0.2            grid_4.2.0            
#> [55] RCurl_1.98-1.6         htmlwidgets_1.5.4      bitops_1.0-7          
#> [58] rmarkdown_2.14         gtable_0.3.0           DBI_1.1.2             
#> [61] R6_2.5.1               dplyr_1.0.8            knitr_1.38            
#> [64] utf8_1.2.2             fastmap_1.1.0          bit_4.0.4             
#> [67] stringi_1.7.6          parallel_4.2.0         Rcpp_1.0.8.3          
#> [70] vctrs_0.4.1            geneplotter_1.74.0     png_0.1-7             
#> [73] tidyselect_1.1.2       xfun_0.30