Hi guys,

First I just want to say, I know this has been asked numerous times and in a number of places. However my confusion has increased progressively!

If someone could set the record straight, please, on how to generate a TMM normalized counts using EdgeR, I would be incredibly grateful!

This post has two answers that look like disagree with one another... https://www.biostars.org/p/317701/

The main reason I want to generate TMM matrix from my count matrix is to compare gene expression levels within samples (see the level of multiple cell-type markers within a single sample) in a bar plot, and then generate the same bar plot for every other respective sample to compare between samples.

I think using TMM normalized counts will allow me to compare between samples and within samples according to here: https://hbctraining.github.io/Training-modules/planning_successful_rnaseq/lessons/sample_level_QC.html

I plan to use something like this to generate the bar plots: https://www.biostars.org/p/340485/#341008

Any help would be appreciated.

Thank you in advance :)
The default normalization in edgeR can be broken down to two steps:


----------


1) normalization by library size. That is simply the correction for
    read depth. While this may probably be good enough when there are no
    widespread changes in library compisition (=samples are very similar
    and only very few genes are differential), this often is not good
    enough. See for an example my answer here (https://www.biostars.org/p/9465851/#9465854) using GTEx data where I
    compare pancreas and lung transcriptomes, so one would expect
    **notably** different gene expression profiles. As you'll see plain per-million scaling results in biased normalized counts while TMM manages to properly center the bulk of genes at y=0 in the MA-plot.
    

----------


2) the introduction of normalization factors that correct the library
    size-scaled values for the compositional component. This here is
    what the Trimmed Mean of M-values (TMM) does. For technical details
    see the original paper by [Robinson & Oshlack in Genome Biology from
    2010][1].


----------


Points 1) and 2) are then combined to calculate the **effective library size** which is then used to divide the raw counts by to obtain normalized counts, also often referred to as TMM-normalized counts or `cpm`.

In practice:

    #/ make the DGEList:
    y <- DGEList(...)
    
    #/ calculate TMM normalization factors:
    y <- calcNormFactors(y)
    
    #/ get the normalized counts:
    cpms <- cpm(y, log=FALSE)

The `cpm` function uses the normalization factors (given that `calcNormFactors` was run on that DGEList) internally.
If not, then `cpm` just return the plain per-million scaled factors.


  [1]: https://genomebiology.biomedcentral.com/articles/10.1186/gb-2010-11-3-r25