I've had this issue with the naming (contrast) of the deseq2 output, where the naming out the output was not reproducible. Normally the comparison would look like: variable_level2_vs_level1 ("treat_b_vs_a") But sometimes it would return as variable1 ("treat1"). Ive seen posts of this issue on other sites as well but I never found a decent solution (nor the cause).
Up untill now, it has been a very elusive issue, for I was not able to reproduce it easily. But today I managed to figure it out and have come up with a minimal reproducible code that results in the issue below.
The problem only occurs if I run a bad vegan adonis model with incorrect contrast. Maybe someone can help me better understand the root of the issue
library(vegan)
library(DESeq2)
mat <- matrix(sample(1:1000), ncol=10)
var$treat <- c(rep("a",5), rep("b",5))
var$y <- c(rep("a",10))
dds <- DESeq2::DESeqDataSetFromMatrix(mat, colData = var, design = ~ treat)
dds = DESeq(dds, test="Wald", fitType="parametric")
resultsNames(dds)
which gives treat_b_vs_a, but if I run it again after the adonis model:
adonis(mat~var$y)
dds <- DESeq2::DESeqDataSetFromMatrix(mat, colData = var, design = ~ treat)
dds = DESeq(dds, test="Wald", fitType="parametric")
resultsNames(dds)
I get treat1.
So somehow triggering an error with the contrast in adonis results in incorrect handling of the contrast by DESeq.
I think you left out one important piece of information: in your example, adonis
fails:
> adonis(mat ~ da$y)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Your y
was constant (had only one value) and could not be used. It is true that in vegan 2.5-x we do set contrasts (that's a user option), but we reset them later. However, if adonis
fails because of invalid input, this resetting does not happen.
This could be fixed so that we reset the contrasts even in failures, but the future releases do not set contrasts and therefore I have no plans to fix just this problem.