Answers.Body: <p>The batch effect is expected to be the same across all samples - therefore you want to estimate its effect across all of the samples. Just add batch as an additional parameter to the linear model (this is presuming samples sequenced in the two batches have been randomised).</p>
  <p>You can show the effect of &quot;batch effect&quot; removal with a PCA plot by plotting the residual error, e.g. in R if using DESeq:</p>
  <pre><code>mypca &lt;-  prcomp(t(assay(varianceStabilizingTransformation(dds)))
  pc.resid &lt;- resid(aov(mypca$x~batch.info))
  ggplot(pc.resid,aes(x=PC1,y=PC2) + geom_point() 
  </code></pre>
  <p>(I haven't checked the code, but it will be something like this).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-01T11:20:03.883Z
Answers.Text: Thank you for the answer Greg. Unfortunately the samples are not randomly distributed across the batches. In the tumor samples there is a suspected biological effect on top of the technical batch (different regions of the tumor were sampled). Since this is not the case for the cell lines I was hoping to use them to estimate the "pure" technical component
Answers.UserDisplayName: PPK
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-01T11:48:13.037Z
Answers.Text: Ah - unfortunate. Based on the PCA, I'm not certain I'd do anything other than treat the results with a bit more caution - your idea sounds reasonable though (if you can find a solid method)
Answers.UserDisplayName: Greg
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-01T10:57:23.417Z
Answers.LastActivityDate: 2021-06-01T10:57:23.417Z
Answers.UserDisplayName: Greg
Body: <p>I have some RNA-seq data with two very obvious batches as you can see in the PCA:<br />
  <a href="https://i.sstatic.net/Mv1r7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Mv1r7.png" alt="PCA prior to normalization" /></a></p>
  <p>The samples of interest (A - H) are from tumor tissues. In addition, there are data for two cell lines I and J. The cell lines should be the same across the batches, while for the tumor samples there may be some additional biological difference.</p>
  <p>My question is, if there is a way to use the cell line data to estimate the technical part of the batch information since there should very little biological difference here. Then I would like to use this to correct the technical aspect of the batch effect in the tumor samples.</p>
  <p>When I run normal batch correction like <code>ComBat</code> or add the batch to the DE model the batch will be estimated over all samples including biological differences.</p>
  <h2>Update</h2>
  <p>I figured I could determine which genes are differentially expressed between the batches in the cell lines only. As mentioned before, the cell lines are highly similar biologically. Thus these DE genes should represent the technical aspect of the difference.</p>
  <p>The plot below shows the PCA when after removing genes DE in the cell lines. Obviously, the differences for the cell lines are greatly reduced. Also the tumor samples are now less clearly separated.</p>
  <p><a href="https://i.sstatic.net/crxYc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/crxYc.png" alt="PCA after normalization" /></a></p>
  <p>Most of the removed genes were from shorter RNA species and a look at sequencing QC later confirmed that in fact the fragment size in the second batch was lower. Therefore I'm positive that I could identify and remove the technical component of the batch effect.</p>
  <h2>tl;dr</h2>
  <p>My data contains a strong difference between batches even for samples that are biologically the same (untreated cell lines). I looked at differentially expressed genes in the cell lines. This revealed to me that the second batch contained a lot more short RNAs due to lower fragment size of the library.</p>
  <p>In the end I'm still wondering if there is an elegant solution for this requiring less footwork</p>
  
Tags: <rna-seq><batch-effects>
Title: Batch effect correction using a subset of samples - using DE genes
ThreadText: # Batch effect correction using a subset of samples - using DE genes
  
  (Asked by: username_0 on 2021-06-01)
  
  I have some RNA-seq data with two very obvious batches as you can see in the PCA:  
  [![PCA prior to normalization](https://i.sstatic.net/Mv1r7.png)](https://i.sstatic.net/Mv1r7.png)
  
  The samples of interest (A - H) are from tumor tissues. In addition, there are data for two cell lines I and J. The cell lines should be the same across the batches, while for the tumor samples there may be some additional biological difference.
  
  My question is, if there is a way to use the cell line data to estimate the technical part of the batch information since there should very little biological difference here. Then I would like to use this to correct the technical aspect of the batch effect in the tumor samples.
  
  When I run normal batch correction like `ComBat` or add the batch to the DE model the batch will be estimated over all samples including biological differences.
  
  ## Update
  
  I figured I could determine which genes are differentially expressed between the batches in the cell lines only. As mentioned before, the cell lines are highly similar biologically. Thus these DE genes should represent the technical aspect of the difference.
  
  The plot below shows the PCA when after removing genes DE in the cell lines. Obviously, the differences for the cell lines are greatly reduced. Also the tumor samples are now less clearly separated.
  
  [![PCA after normalization](https://i.sstatic.net/crxYc.png)](https://i.sstatic.net/crxYc.png)
  
  Most of the removed genes were from shorter RNA species and a look at sequencing QC later confirmed that in fact the fragment size in the second batch was lower. Therefore I'm positive that I could identify and remove the technical component of the batch effect.
  
  ## tl;dr
  
  My data contains a strong difference between batches even for samples that are biologically the same (untreated cell lines). I looked at differentially expressed genes in the cell lines. This revealed to me that the second batch contained a lot more short RNAs due to lower fragment size of the library.
  
  In the end I'm still wondering if there is an elegant solution for this requiring less footwork
  
  **Tags:** rna-seq, batch-effects
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-01. Score: 1 | Accepted answer
  
  The batch effect is expected to be the same across all samples - therefore you want to estimate its effect across all of the samples. Just add batch as an additional parameter to the linear model (this is presuming samples sequenced in the two batches have been randomised).
  
  You can show the effect of "batch effect" removal with a PCA plot by plotting the residual error, e.g. in R if using DESeq:
  
  ```
  mypca <-  prcomp(t(assay(varianceStabilizingTransformation(dds)))
  pc.resid <- resid(aov(mypca$x~batch.info))
  ggplot(pc.resid,aes(x=PC1,y=PC2) + geom_point() 
  
  ```
  
  (I haven't checked the code, but it will be something like this).
  
  > **Comments:**
  > **username_0**: Thank you for the answer username_1. Unfortunately the samples are not randomly distributed across the batches. In the tumor samples there is a suspected biological effect on top of the technical batch (different regions of the tumor were sampled). Since this is not the case for the cell lines I was hoping to use them to estimate the "pure" technical component  
  > **username_1**: Ah - unfortunate. Based on the PCA, I'm not certain I'd do anything other than treat the results with a bit more caution - your idea sounds reasonable though (if you can find a solid method)  
  
  ---
  
  