How to change conditions in DESeq2
1
2
Entering edit mode
5.7 years ago

Hi,

I am kind of new to R so I apologize if I don't give all the info that is need. I will keep and eye on this post and add any additional info that is requested. So I have two conditions in my dataset, fed and starved. The "fed" samples are my controls and the "starved" samples are my affected. So what I want to do is do a fed vs starved comparison and I have had great success so far with DESeq2. For whatever reason, DESeq2 wants me to do a starved vs fed comparison (this is likely to be something I am missing), which is a bit annoying. I have been able to fix the problem by doing the following

    dds <- DESeq(dds)
    res2 <- results(dds, contrast = c("condition","fed","starved"))
    res2

log2 fold change (MLE): condition fed vs starved 
Wald test p-value: condition fed vs starved 
DataFrame with 13728 rows and 6 columns
              baseMean log2FoldChange     lfcSE        stat
             <numeric>      <numeric> <numeric>   <numeric>
FBgn0000008   193.7874     -0.2987684 0.2707192 -1.10361006
FBgn0000014   110.4600     -0.1016940 0.4402129 -0.23101088
FBgn0000015   164.1642     -0.1506553 0.3030172 -0.49718392
FBgn0000017  1111.0239      0.0169430 0.1874026  0.09040964
FBgn0000018   109.2123     -0.8891501 0.3812173 -2.33239674

So are you can see, the comparison is fed vs starved. If I were to run just the default this is what I get, which is not what I want.

dds <- DESeq(dds)
res <- results(dds)
res

log2 fold change (MLE): condition starved vs fed 
Wald test p-value: condition starved vs fed 
DataFrame with 13728 rows and 6 columns
              baseMean log2FoldChange     lfcSE        stat
             <numeric>      <numeric> <numeric>   <numeric>
FBgn0000008   193.7874      0.2987684 0.2707192  1.10361006
FBgn0000014   110.4600      0.1016940 0.4402129  0.23101088
FBgn0000015   164.1642      0.1506553 0.3030172  0.49718392
FBgn0000017  1111.0239     -0.0169430 0.1874026 -0.09040964
FBgn0000018   109.2123      0.8891501 0.3812173  2.33239674

So the issue I am having is when I go to make an MA-plot. So when I run the following, I have no issue. I get an MA-plot with the correct comparison fed vs starved.

plotMA(res2, ylim=c(-2,2))

There is a lot of data in the graph so I want to shrink it down. There is an option for that and this is where I start to run into my issue. So when I run the following command to get a list of coefficients, this is what I get

    resultsNames(dds)

[1] "Intercept"                "condition_starved_vs_fed"

So my little trick before will no longer work. To shrink the data I have to pick the correct coefficient for the following command to work

resLFC <- lfcShrink(dds, coef="condition_fed_vs_starved", type="apeglm")

I would like to make an MA-plot with the following command but I am unable to without the correct coefficient.

plotMA(resLFC, ylim=c(-2,2))

So my question is, how can I correct/add a coefficient so I am able to make this MA-plot? I know this is something I am doing wrong. I am just too new to R and DESeq2 to figure it out. Any help would be amazing!!

Thanks

R rna-seq • 5.3k views
ADD COMMENT
13
Entering edit mode
5.7 years ago

You have 2 options:

First option:

Do you need to use the apeGLM implementation? If you just use the default, then you can supply a contrast to lfcshrink() instead of a coefficient:

res2 <- results(dds, contrast = c('condition','fed','starved'))
resLFC <- lfcShrink(dds, contrast = c('condition','fed','starved'), res = res2, type = 'normal')

Second option:

Go back to the very beginning (prior to running DESeq() and just re-level your condition factor so that fed is the reference level, and then restart DESeq2, e.g.:

MyData$condition <- factor(MyData$condition, levels = c('fed','starved'))

...or:

MyData$condition <- factor(MyData$condition)
MyData$condition <- relevel(MyData$condition, ref = 'fed')

Edit April 21, 2020: this second method that I had suggested is now also mentioned briefly in the vignette:

Although apeglm cannot be used with contrast, we note that many designs can be easily rearranged such that what was a contrast becomes its own coefficient

Also, if you are reading this and it is after April 2020, then apeglm is now likely the default for lfcShrink() in your version of DESeq2.

Kevin

ADD COMMENT
1
Entering edit mode

Kevin! You're the man! Sorry for the late response, I was trying to get your second option to work. I really appreciate your response! I was able to get both of your options to work.

I had to play with what you wrote a bit. I had to run the following to get the data in the right order

MyData$condition <- factor(MyData$condition, levels=c("starved","fed"))

This gave me the fed vs starved condition. When I ran what you wrote I kept getting the starved vs fed, which is okay! I just had to switch things around a tiny bit. Wouldn't have got here with out you! I really appreciate you well written response.

ADD REPLY
0
Entering edit mode

Okay, no worries.

ADD REPLY

Login before adding your answer.

Traffic: 2471 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