Reordering factor levels in DESeq2 causes results error in cleanContrast
1
0
Entering edit mode
@chris-stubben-12524
Last seen 4.1 years ago
Salt Lake City, Utah

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']!

deseq2 • 3.0k views
ADD COMMENT
1
Entering edit mode
@mikelove
Last seen 3 hours ago
United States

I'm not sure I understand the problem. You can pull out whatever comparison you like using 'contrast' and then specifying exactly what you want in the numerator and denominator of the LFC.

Regarding the error: you should not relevel the factor after running DESeq(), as the software uses the reference level of the variables to look up which coefficients were estimated. You've estimated coefficients under one setting, and then changed the level orders, so the software is confused. You should either perform re-leveling before running DESeq(), or just use 'contrast' afterward to specify explicitly what comparison you want.

ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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().

ADD REPLY

Login before adding your answer.

Traffic: 750 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6