#' Normalize counts using a normalization method + correction of library size
#' with dispersion correction
#' @param x matrix
#' @param method Method passed to calcNormFactors function of edgeR
#' @param round_output round output?
#' @param ... additional parameters passed to calcNormFactors of edgeR
#' @export
normalize_counts <- function(x, method=c("TMM","RLE", "upperquartile", "none"),
round_output = FALSE, ...) {
method <- match.arg(method)
my_list <- edgeR::calcNormFactors(x, method = method, ...)
my_list <- edgeR::estimateCommonDisp(my_list, verbose = FALSE)
my_list$pseudo.counts
}
# normalize_counts_matrix <- function(x, method=c("TMM","RLE", "upperquartile", "none"),
# round_output = FALSE, ...) {
# method <- match.arg(method)
# normfactors <- edgeR::calcNormFactors(x, method = method, ...)
# sizefactors <- normfactors * colSums(x, na.rm = TRUE)
# t(t(x) / sizefactors)
# }
#
# #####################
#
# mm <- calcNormFactors(x2, method="TMM")
# tmmScaleFactors <- x2$samples$lib.size * tmm$samples$norm.factors
# tmmExp <- round(t(t(tmm$counts)/tmmScaleFactors) * mean(tmmScaleFactors))
# boxplot(log2(tmmExp+1), main="TMM", las=2)
# plotMDS(tmmExp)
# plotMDS(tmmExp, dim.plot=c(1,3))
# #####################
# norm_tmm <- function(data) {
# normdat <- calcNormFactors(data,method="TMM")
# N <- normdat$samples$lib.size
# f <- normdat$samples$norm.factors
# TMM <- N*f / mean(N*f)
# norm.factor <- TMM
# scale(data$counts, center=FALSE, scale=TMM)
# }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.