consensusDE aims to make first pass differential expression (DE) analysis, with reporting of significance scores from multiple methods easy. It implements wrappers for Voom, DEseq2 and EdgeR and reports differential expression results seperately, as well as merging the results into a single table for determining consensus. The results of the merged table, are ordered by the summed ranks of the p-values for each algorithm.
Core functionality is simplified into two function:
buildSummarized()
generate a summarized experiment that counts reads mapped (from bam files) against a transcriptomemulti_de_pairs()
perform DE analysis (all possible pairwise comparisons)Below, we demonstrate the core functionality of consensusDE as well as how to plot results from obtained results using the diag_plots() function.
Begin by first installing and then loading the consensusDE library. To illustrate functionality of consensusDE, we will utilise data from the airway and annotation libraries as follows. Begin by installing and attaching data from these libraries:
A summarized experiment is an object format that stores all the relevant information for performing differential expression analysis. buildSummarized()
allows users to build a summarized object by simply providing 1) a table of bam files (more below on format), 2) a directory of where to locate the bam files and 3) a transcript database to map the reads to (either a gtf file or txdb). We will use bam files attached to this package (from GenomicAlignments) as an example:
# build a design table that lists the files and their grouping
file_list <- list.files(system.file("extdata", package="GenomicAlignments"),
recursive = TRUE,
pattern = "*bam$",
full = TRUE)
# Prepare a sample table to be used with buildSummarized()
# must be comprised of a minimum of two columns, named "file" and "group",
# with one additional column: "pairs" if the data is paired
sample_table <- data.frame("file" = basename(file_list),
"group" = c("treat", "untreat"))
# extract the path to the bam directory - where to search for files listed in "sample_table"
bam_dir <- as.character(gsub(basename(file_list)[1], "", file_list[1]))
The minimum information is now ready to build a summarized experiment as follows:
# NB. force_build = TRUE, is set to allow the Summarized Experiment to be built.
# This will report a Warning message that less than two replicates are present
# in the sample_table.
summarized_dm3 <- buildSummarized(sample_table = sample_table,
bam_dir = bam_dir,
tx_db = TxDb.Dmelanogaster.UCSC.dm3.ensGene,
read_format = "paired",
force_build = TRUE)
This will output a summarized object that has mapped the reads for the bam files that are listed in sample_table
, located in bam_dir
, against the transcript database provided: TxDb.Dmelanogaster.UCSC.dm3.ensGene
. Bam file format, whether “paired” or “single” end (the type of sequencing technology used) must be specified using the read_format
parameter. gtf formatted transcript databases can also be used instead of a txdb, by providing the full path to the gtf file using the gtf
parameter. To save the summarized experiment externally, for future use, specify the path to save the summarized experiment using output_log
To see details of all parameters see ?buildSummarized
.
Overview of the summarized experiment:
summarized_dm3
# class: RangedSummarizedExperiment
# dim: 15682 2
# metadata(0):
# assays(1): counts
# rownames(15682): FBgn0000003 FBgn0000008 ... FBgn0264726 FBgn0264727
# rowData names(0):
# colnames(2): sm_treated1.bam sm_untreated1.bam
# colData names(2): file group
buildSummarized()
also allows users to filter out low read counts. This can be done when building the summarized experiment, or re-running with the summarized experiment output using buildSummarized()
. See “Performing Differential Expresssion” below with filter example.
For differential expression (DE) analysis we will use the airway
data for demonstration. See ?airway
for more details for this experiment. NOTE: the summarized meta-data must include the columns “group” and “file” to build the correct models. For illustration, we sample 1000 genes from this dataset.
# for compatability, add "group" and "file" columns
colData(airway)$group <- colData(airway)$dex
colData(airway)$file <- rownames(colData(airway))
# filter low count data
airway_filter <- buildSummarized(summarized = airway,
filter = TRUE)
# for illustration, we only use sa random sample of 1000 transcripts
set.seed(1234)
airway_filter <- sample(airway_filter, 1000)
# call multi_de_pairs()
all_pairs_airway <- multi_de_pairs(summarized = airway_filter,
paired = "unpaired",
ruv_correct = FALSE)
Running multi_de_pairs()
will perform DE analysis on all possible pairs of “groups” and save these results as a simple list of “merged” - being the merged results of “deseq”, “voom” and “edger”, as well as the latter three as objects independently. To access the merged results:
# To view all the comparisons conducted:
names(all_pairs_airway$merged)
# [1] "untrt-trt"
# to access data of a particular comparison
head(all_pairs_airway$merged[["untrt-trt"]])
# ID AveExpr LogFC edger_adj_p deseq_adj_p voom_adj_p edger_rank deseq_rank voom_rank rank_sum
# 1 ENSG00000152583 7.848478 -4.579048 4.555352e-81 1.689976e-105 2.434237e-05 1 1 1 2
# 2 ENSG00000196517 6.707906 2.238648 7.174030e-29 2.375309e-40 7.700210e-05 2 2 2 4
# 3 ENSG00000123562 11.471330 -1.008375 9.124547e-14 8.201734e-31 3.724219e-04 6 3 3 9
# 4 ENSG00000250978 2.929392 -6.159170 3.441794e-28 1.985784e-18 7.780662e-04 3 6 5 9
# 5 ENSG00000103485 8.891566 1.231192 1.586426e-14 6.843112e-19 5.406701e-04 5 5 4 10
# 6 ENSG00000169738 8.158014 -2.128064 1.381426e-15 7.176291e-18 1.424488e-03 4 8 12 12
It is often useful to add additional annotated information to the output tables. This can be acheived by providing a database for annotations via ``ensembl_annotate. Annotations needs to be a Genome Wide Annotation object, e.g. org.Mm.eg.db for mouse or org.Hs.eg.db for human from BioConductor. For example, to install the database for the mouse annotation, go to http://bioconductor.org/packages/org.Mm.eg.db and follow the instructions. Ensure that after installing the database package that the library is loaded using
library(org.Mm.eg.db). When running, "'select()' returned 1:many mapping between keys and columns" will appear on the command line. This is the result of multiple mapped transcript ID to Annotations. Only the first annotation is reported. See
?multi_de_pairs``` for additional documentation.
An example of annotating the above filtered airway data is provided below:
# first ensure annotation database in installed
# load annotation library:
library(org.Hs.eg.db)
# call multi_de_pairs(),
# set ensembl_annotate argument to org.Hs.eg.db
all_pairs_airway <- multi_de_pairs(summarized = airway_filter,
paired = "unpaired",
ruv_correct = FALSE,
ensembl_annotate = org.Hs.eg.db)
multi_de_pairs
provides options to automatically write all results to output directories when a full path is provided. Which results are output depends on which directories are provided. Full paths provided to the parameters of output_voom
, output_edger
, output_deseq
and output_combined
will output Voom, EdgeR, DEseq and the merged results to the directories provided, respectively.
consensusDE also provides the option to remove batch effects through RUVseq functionality. consensusDE currently implements RUVr which models a first pass generalised linear model (GLM) using EdgeR and obtaining residuals for incorporation into the SummarizedExperiment object for inclusion in the models for DE analysis. The following example, uses RUV to identify these residuals. To view the residuals in the model see the resisuals section below in the plotting functions. Note, that if ruv_correct = TRUE
and a path to a plot_dir
is provided, diagnostic plots before and after RUV correction will be produced. The residuals can also be accessed in the summarizedExperiment as below. These are present in the “W_1” column. At present only one factor of variation is determined.
# call multi_de_pairs()
all_pairs_airway_ruv <- multi_de_pairs(summarized = airway_filter,
paired = "unpaired",
ruv_correct = TRUE)
# access the summarized experiment (now including the residuals under the "W_1" column)
colData(all_pairs_airway_ruv$summarized)
# DataFrame with 8 rows and 3 columns
# file group W_1
# <factor> <factor> <numeric>
# SRR1039508 SRR1039508 untrt -0.142570931413377
# SRR1039509 SRR1039509 trt -0.178946892813184
# SRR1039512 SRR1039512 untrt -0.0505852352323729
# SRR1039513 SRR1039513 trt -0.199848364864245
# SRR1039516 SRR1039516 untrt 0.472530975797452
# SRR1039517 SRR1039517 trt 0.703116609741865
# SRR1039520 SRR1039520 untrt -0.25051443379887
# SRR1039521 SRR1039521 trt -0.353181727417269
When performing DE analysis, a series of plots (currently 10) can be generated and saved as .pdf files in a plot directory provided to multi_de_pairs()
with the parameter: plot_dir = "/path/to/save/pdfs/
. See ?multi_de_pairs
for description.
In addition, each of the 10 plots can be plotted individually using the diag_plots
function. See ?diag_plots
for description, which provides wrappers for 10 different plots. Next we will plot each of these using the example data.
Plot the number of reads that mapped to the transcriptome of each sample. The sample numbers on the x-axis correspond to the sample row number in the summarizedExperiment built, accessible using colData(airway)
. Samples are coloured by their “group”.
Residuals for the RUV model can be plotted as follows:
This will perform an MA plot given a dataset of the appropriate structure. This will plot the Log-fold change (M) versus the average expression level (A). To use independently of multi_de_pairs()
and plot to only one comparison, constructing a list with one data.frame with the columns labelled “ID”, “AveExpr”, and “Adj_PVal” is required. The following illustrates an example for using the merged data, which needs to be put into a list and labelled appropriately. Note that this is done automatically with multi_de_pairs()
.
# 1. View all the comparisons conducted
names(all_pairs_airway$merged)
[1] "untrt-trt"
# 2. Extract the data.frame of interest of a particular comparison
comparison <- all_pairs_airway$merged[["untrt-trt"]]
# this will not work unless in a list and will stop, producing an error. E.g.
diag_plots(merged_in = comparison,
name = "untrt-trt",
ma = TRUE)
# Error message:
merged_in is not a list. If you want to plot with one comparison only,
put the single dataframe into a list as follows. my_list <- list("name"=
merged_in)
# 3. Put into a new list as instructed by the error
comparison_list <- list("untrt-trt" = comparison)
# this will not work unless the appropriate columns are labelled
# "ID", "AveExpr", and "Adj_PVal"
diag_plots(merged_in = comparison_list,
name = "untrt-trt",
ma = TRUE)
# Error message:
merged_in contains 1 slots that are not
"data.frame" objects with column names containing "ID", "AveExpr", and
"Adj_PVal".
# 3. Relabel the columns for plotting
# inspecting the column names reveals that the "Adj_PVal" column needs to be specified.
colnames(comparison_list[["untrt-trt"]])
# replace "edger_adj_p" with "Adj_PVal" to use this p-value, using the "gsub" command as follows
colnames(comparison_list[["untrt-trt"]]) <- gsub("edger_adj_p", "Adj_PVal",
colnames(comparison_list[["untrt-trt"]]))
This plot a volcano plot, which compares the Log-fold change versus significance of change -log transformed score. As above and described in the MA plot section, to use independently of multi_de_pairs()
and plot to only one comparison, constructing a list with one data.frame with the columns labelled “ID”, “AveExpr”, and “Adj_PVal” is required.
This plot the distribution of p-values for diagnostic analyses. As above and described in the MA plot section, to use independently of multi_de_pairs()
and plot to only one comparison, constructing a list with one data.frame with the columns labelled “ID”, “AveExpr”, and “Adj_PVal” is required.
The legend and labels can be turned off using legend = FALSE
and label = TRUE
for diag_plots()
. See ?diag_plots
for more details of these parameters.
When performing DE analysis, data is stored in simple list object that can be accessed. Below are the levels of data available from the output of a DE analysis. We use the all_pairs_airway
results from the above analysis to demonstrate how to locate these tables.
all_pairs_airway$merged
In addition to the list with the combined results of DESeq2, Voom and EdgeR, the full results can be accessed for each method, as well as fit tables and the contrasts performed.
all_pairs_airway$deseq
(list of the DEseq2 results)all_pairs_airway$voom
(list of the Voom results)all_pairs_airway$edger
(list of the edgeR results)Within each list the following data is accessible. Each object is list of all the comparisons performed.
all_pairs_airway$deseq$short_results
all_pairs_airway$deseq$short_results[[1]]
all_pairs_airway$deseq$full_results
all_pairs_airway$deseq$fitted
all_pairs_airway$deseq$contrasts
consensusDE
When using this package, please cite consensusDE as follows and all methods used in your analysis.
For consensus DE:
citation("consensusDE")
##
## To cite package 'consensusDE' in publications use:
##
## Ashley J. Waardenberg (2019). consensusDE: RNA-seq analysis
## using multiple algorithms. R package version 1.0.3.
##
## A BibTeX entry for LaTeX users is
##
## @Manual{,
## title = {consensusDE: RNA-seq analysis using multiple algorithms},
## author = {Ashley J. Waardenberg},
## year = {2019},
## note = {R package version 1.0.3},
## }
##
## ATTENTION: This citation information has been auto-generated from
## the package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.