#' Pipeline for edgeR analysis
#'
#' Function to perform entire edgeR analysis using edgeR-QLF. It begins with
#' a SummarizedExperiment object and ends with list of differential genes and
#' generation of diagnostic plots along the way.
#'
#' @param se SummarizedExperiment with an assay slot named counts_fil containing
#' the filtered counts and colData slot containing sample metadata.
#' @param design A design matrix specifying the experimental design. If NULL,
#' then a design matrix will be created using the values for contrast.levels
#' and block.levels.
#' @param contrast A matrix of contrasts (as created by \code{makeContrasts} in
#' the \code{limma} package specifying the comparisons to perform). If NULL,
#' then will be created from the design matrix.
#' @param block.column The column in the samples metadata dataframe specifying
#' the block/additive effect column. Ignored if design is not NULL.
#' @param norm.method Normalisation method to use - may be "TMM", "RLE",
#' "upperquartile" or "none".
#' @param adjust.method Method to be used for adjustment of nominal p-values.
#' May be one of "BH", "bonferroni", "holm", "hochberg", "hommel", "BY".
#' @param p.value Value between 0 and 1. Adjusted p-value for the differential
#' expression analysis.
#'
#' @return
#' Results of edgeR differential analysis.
#'
#' @import edgeR
#' @import SummarizedExperiment
#'
#' @export
edger_pipe <- function(se = NULL,
design = NULL,
contrast = NULL,
block.column = NULL,
norm.method = "TMM",
adjust.method = "BH",
p.value = 0.05) {
############
# Create a dge object
############
counts <- SummarizedExperiment::assays(se)$counts_fil
counts <- counts[rowSums(is.na(counts)) != ncol(counts),]
dge <- edgeR::DGEList(counts = counts,
genes = rownames(counts),
group = SummarizedExperiment::colData(se)$Contrast)
############
# Normalise libraries
############
dge <- edger_norm(dge = dge, norm.method = norm.method)
############
# Create a MDS plot
############
create_mds(dge)
############
# Create experimental design
############
if (is.null(design)) {
# Create design and contrast matrix.
cat("\nDesign matrix:\n")
design.matrix <- create_design(se = se, block.column = block.column)
cat("\n\nContrast options:\n")
contrast.matrix <- create_contrast(design = design.matrix)
} else {
cat("\nDesign matrix:\n")
design.matrix <- design
cat("\n\nContrast options:\n")
contrast.matrix <- contrast
}
############
# Perform differential analysis
############
edger_results <- run_edger(dge = dge, design = design.matrix,
contrast = contrast.matrix,
adjust.method = adjust.method,
p.value = p.value)
out <- edger_results[[2]]
for (i in 1:length(out)) {
write.table(out[[i]], row.names = F, col.names = TRUE,
quote = F, sep = "\t",
file = paste0("DEgenes_edger_", names(out)[i], ".txt"))
}
return(edger_results)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.