I recently updated to R version 3.4.2 and noticed that DESeq2 results now returns an error if I relevel the factors.
library(DESeq2) cnts <- matrix(rnbinom(n=1000, mu=100, size=1/0.5), ncol=10) samp <- data.frame( cond=factor(rep(c("a", "b"), each=5))) dds <- DESeqDataSetFromMatrix(cnts, samp, ~ cond) dds <- DESeq(dds) dds$cond # [1] a a a a a b b b b b # Levels: a b ## works res <- results(dds, c("cond", "a", "b")) dds$cond <- factor(dds$cond, levels = c("b","a")) dds$cond # [1] a a a a a b b b b b #Levels: b a # Error results(dds, c("cond", "a", "b")) # Error in cleanContrast(object, contrast, expanded = isExpanded, listValues = listValues, : as b is the reference level, was expecting cond_a_vs_b to be present in 'resultsNames(object)'
ps. Trying to submit this question, why do I get Language "ca" is not one of the supported languages ['en']!
It's not very clear in the Note on Factor Levels in the DESeq2 vignette that you should not reorder factors after running DESeq2. I will only reorder factors in sample tables from now on.
It occurs in the vignette before one has run DESeq(), so I guess it was implied, but I can certainly make it explicit by adding a sentence to the vignette. Thanks for your suggestion.
I've added a sentence to this section of the vignette to make it clear that one shouldn't change factor levels during or after running DESeq().