Question: Batch correction in DESeq2
gravatar for AB
3.8 years ago by
United States
AB70 wrote:

Hi Everyone,

I am working on RNA-Seq data. I'm using DESeq2 for my analysis. I have 20 samples from 3 batches. I am testing for 2 conditions, cond1 and cond2.

dds<-DESeqDataSetFromMatrix(countData=countTable3,colData=coldata,design = ~cond1*cond2)

When i performed PCA, I could clearly see some batch effect. I read in the forum that adding batch to the design in DESeq removes the batch effect. But I am not sure if this is the right way to go about it because I can still see the same batch effect

dds<-DESeqDataSetFromMatrix(countData=countTable3,colData=coldata,design = ~batch+cond1*cond2)

I tried using Combat but I'm unable to use combat results in DESeq. It gives me the following error.

Error in DESeqDataSet(se, design = design, ignoreRank) : 
  some values in assay are negative

I am not sure if removeBatchEffects() function can be used with DESeq. Can someone please help me out here.


ADD COMMENTlink modified 3.4 years ago by adam0 • written 3.8 years ago by AB70
Answer: Batch correction in DESeq2
gravatar for Ryan C. Thompson
3.8 years ago by
The Scripps Research Institute, La Jolla, CA
Ryan C. Thompson7.4k wrote:

Just to be clear, there's an important difference between removing a batch effect and modelling a batch effect. Including the batch in your design formula will model the batch effect in the regression step, which means that the raw data are not modified (so the batch effect is not removed), but instead the regression will estimate the size of the batch effect and subtract it out when performing all other tests. In addition, the model's residual degrees of freedom will be reduced appropriately to reflect the fact that some degrees of freedom were "spent" modelling the batch effects. This is the preferred approach for any method that is capable of using it (this includes DESeq2). You would only remove the batch effect (e.g. using limma's removeBatchEffect function) if you were going to do some kind of downstream analysis that can't model the batch effects, such as training a classifier.

I don't have experience with ComBat, but I would expect that you run it on log-transformed CPM values, while DESeq2 expects raw counts as input. I couldn't tell you how to properly use the two methods together.

ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by Ryan C. Thompson7.4k

I agree, that is the way DESeq handles batch effects. Is there a way to visualize or diagnose how the batch effects were modeled? For example, I can do plotPCA(rlog(dds)) to plot the PCA showing the batch effects. I model the effects as ~ condition + replicate and compute the results. Now I'd like some way to see how the resulting log2fc was only due to the condition and the replicate/batch effects are "separate".

I am thinking the some transform of coef(dds) provides what I am thinking of.

ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by ysdel40

You should always put the condition of interest at the end of the design formula for safety (see vignette).

You can just use plotCounts with intgroup=c("replicate","condition") to split apart replicate effects and condition effects. The batch term fit by DESeq2 will be the mean of the normalized count which are plotted.

ADD REPLYlink written 2.6 years ago by Michael Love25k

Thank you. Well, plotCounts plots the counts for a single gene, so yes, you can see the batch effects and the treatment effect in the counts. But I was thinking of a way to look at the (all/top) genes like plotPCA does and conclude aha! DESeq2 correctly modeled/removed the batch effects so the log2fc/pvalues we are getting are due to the treatment and not the batch effects.

ADD REPLYlink written 2.6 years ago by ysdel40

Batch effects are gene-specific, and DESeq2 fits gene-specific coefficients for the batch term. If you want to get an idea how much batch variability contributes to a PCA plot, I've recommended the following approach on the support site before:

variance stabilize the counts, apply limma's removeBatchEffect to assay(vsd), then use plotPCA to plot the residuals.

An example:

Make some simulated data with a batch effect:

dds <- makeExampleDESeqDataSet(betaSD=1,interceptMean=10)
dds$batch <- factor(rep(c("A","B"),each=6))

VST, remove batch effect, then plotPCA:

vsd <- vst(dds)
plotPCA(vsd, "batch")
assay(vsd) <- limma::removeBatchEffect(assay(vsd), vsd$batch)
plotPCA(vsd, "batch")
ADD REPLYlink written 2.6 years ago by Michael Love25k

Hi, Michael. Can I used the batch removed data in the DESeq2 function? If I can, how should I run it? Using vsd instead of dds?

ADD REPLYlink written 2.0 years ago by ksuasteguic0

DESeq() only takes as input the original counts, and this is on purpose. This is the optimal statistical approach. To account for batch, you put the variables at the beginning of the design, e.g. ~batch + condition 


ADD REPLYlink written 2.0 years ago by Michael Love25k

Hi Michael,

Could you please state how I can get DEG from the data where we have removed batch effect using VST.

Hoping for prompt response.


ADD REPLYlink modified 7 months ago • written 7 months ago by bansal.ankush130

See this answer directly above your comment from 17 months ago:

ADD REPLYlink written 7 months ago by Michael Love25k
Answer: Batch correction in DESeq2
gravatar for chris.gene
3.7 years ago by
chris.gene0 wrote:

I used the sva package. It defines surrogate variables which I then included in the analysis. "The sva package contains functions for removing batch effects and other unwanted variation in high-throughput experiment."


ADD COMMENTlink written 3.7 years ago by chris.gene0
Answer: Batch correction in DESeq2
gravatar for adam
3.4 years ago by
adam0 wrote:

I believe the "counts" function in DESeq2 will provide the type of normalization you you looking for.  Make sure to use the "normalized=TRUE" flag.


ADD COMMENTlink written 3.4 years ago by adam0

This is just normalization for sequencing depth. I agree with Ryan's answer here, which is to add the known batches to the design formula. (And if the batches are not known, they can be estimated using the sva or RUVseq packages.)

ADD REPLYlink written 3.4 years ago by Michael Love25k
Please log in to add an answer.


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