File: dgelist.R

package info (click to toggle)
r-bioc-tximeta 1.16.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 860 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#' Make a DGEList from tximeta output
#'
#' A simple wrapper function for constructing a DGEList for use with edgeR.
#' See vignette for an example. Requires installation of the edgeR
#' package from Bioconductor.
#'
#' @param se a SummarizedExperiment produced by tximeta
#'
#' @return a DGEList
#'
#' @export
makeDGEList <- function(se) {
  if (!requireNamespace("edgeR", quietly=TRUE)) {
    stop("this function requires the edgeR package is installed")
  }
  cts <- assays(se)[["counts"]]
  normMat <- assays(se)[["length"]]
  normMat <- normMat / exp(rowMeans(log(normMat)))
  o <- log(edgeR::calcNormFactors(cts/normMat)) + log(colSums(cts/normMat))
  y <- edgeR::DGEList(cts, samples=as.data.frame(colData(se)),
                      genes=as.data.frame(rowData(se)))
  y <- edgeR::scaleOffset(y, t(t(log(normMat)) + o))
  y
}