Question: How to change conditions in DESeq2
gravatar for williamsbrian5064
5 months ago by
williamsbrian5064130 wrote:


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"))

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)

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


[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!!


rna-seq R • 389 views
ADD COMMENTlink modified 5 months ago by Kevin Blighe35k • written 5 months ago by williamsbrian5064130
gravatar for Kevin Blighe
5 months ago by
Kevin Blighe35k
Republic of Ireland
Kevin Blighe35k wrote:

You have 2 options:


Do you need to use ape's GLM 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)


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"))


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


ADD COMMENTlink modified 5 months ago • written 5 months ago by Kevin Blighe35k

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 REPLYlink written 5 months ago by williamsbrian5064130

Okay, no worries.

ADD REPLYlink modified 15 hours ago • written 5 months ago by Kevin Blighe35k
Please log in to add an answer.


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