Search
Question: Reordering factor levels in DESeq2 causes results error in cleanContrast
0
gravatar for Chris Stubben
23 days ago by
Salt Lake City, Utah
Chris Stubben0 wrote:

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

ADD COMMENTlink modified 23 days ago by Michael Love14k • written 23 days ago by Chris Stubben0
1
gravatar for Michael Love
23 days ago by
Michael Love14k
United States
Michael Love14k wrote:

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 COMMENTlink written 23 days ago by Michael Love14k

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 REPLYlink written 23 days ago by Chris Stubben0

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 REPLYlink written 23 days ago by Michael Love14k

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 REPLYlink written 23 days ago by Michael Love14k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 191 users visited in the last hour