# Batch correction in reconstructed gene space

**URL:** <https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256>\
**Category:** scvi-tools\
**Created:** [March 23, 2023, 6:40pm UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256 "2023-03-23T18:40:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![khagani](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@khagani](https://discourse.scverse.org/u/khagani)\
**Post date:** [March 23, 2023, 6:40pm UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/1 "2023-03-23T18:40:07Z")

</div>

Hi

We recently have been applying scVI for batch correction to scRNAseq data from two different batches. We see the batch correction working when visualizing the data, however, when we do the genewise comparison between batches it looks like batch effect has not been removed. I wonder if we expect to see batch effect in the reconstructed gene space?

Khagani

---

<div class="post-metadata">

**Author:** ![Justin\_Hong](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/justin_hong/32/85_2.png) [@Justin\_Hong](https://discourse.scverse.org/u/Justin_Hong)\
**Post date:** [March 23, 2023, 7:21pm UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/2 "2023-03-23T19:21:05Z")

</div>

What do you mean by genewise comparison between batches? It sounds like you are comparing the reconstructed gene counts output by `get_normalized_expression`. If this is the case, by default it uses the original batch terms when inferring the normalized gene levels, which means it will reproduce the batch effects. If you would like a view of the gene counts where they are simulated to come from the same batch, you need to use the `transform_batch` kwarg, which when set to an integer computes the normalized expression rates as if they came from the same batch.

---

<div class="post-metadata">

**Author:** ![khagani](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@khagani](https://discourse.scverse.org/u/khagani)\
**Post date:** [March 23, 2023, 8:00pm UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/3 "2023-03-23T20:00:16Z")

</div>

Hi Justin

Thanks for the quick response. I really appreciate it. Can you explain what exactly `transform_batch` doing? and how should we interpret the values we are getting from transform\_batch.

Khagani

---

<div class="post-metadata">

**Author:** ![khagani](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@khagani](https://discourse.scverse.org/u/khagani)\
**Post date:** [March 23, 2023, 8:59pm UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/4 "2023-03-23T20:59:41Z")

</div>

And also documentation is a bit confusing and out of date. We tried to use the following link but it was broken:  
[https://docs.scvi-tools.org/en/stable/user\_guide/notebooks/totalVI.html](https://docs.scvi-tools.org/en/stable/user_guide/notebooks/totalVI.html)

Would be very helpful if there was a tutorial to get the corrected data with the up to date API.

I appreciate your work and wanted to give a feedback.

Khagani

---

<div class="post-metadata">

**Author:** ![adamgayoso](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/adamgayoso/32/100_2.png) [@adamgayoso](https://discourse.scverse.org/u/adamgayoso)\
**Post date:** [March 24, 2023, 1:03am UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/5 "2023-03-24T01:03:33Z")

</div>

Hi the tutorial is here

> **[CITE-seq analysis with totalVI](https://docs.scvi-tools.org/en/stable/tutorials/notebooks/totalVI.html)**
>
> With totalVI, we can produce a joint latent representation of cells, denoised data for both protein and RNA, integrate datasets, and compute differential expression of RNA and protein. Here we demo...

If you ever have a broken link you can always revert back to `https://docs.scvi-tools.org/en/stable/`

We have a page here that we will complete describing `transform_batch`

> **[Counterfactual prediction](https://docs.scvi-tools.org/en/stable/user_guide/background/counterfactual_prediction.html)**

---

<div class="post-metadata">

**Author:** ![malonzm1](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@malonzm1](https://discourse.scverse.org/u/malonzm1)\
**Post date:** [May 9, 2024, 9:17am UTC](https://discourse.scverse.org/t/batch-correction-in-reconstructed-gene-space/1256/6 "2024-05-09T09:17:37Z")

</div>

Hi,

The link to `Counterfactual prediction` is broken (and so are all the other links). May I know what values can be assigned to `transform_batch`?

Btw, in this tutorial [Introduction to scvi-tools — scvi-tools](https://docs.scvi-tools.org/en/stable/tutorials/notebooks/quick_start/api_overview.html), why isn’t `transform_batch` mentioned?

Br,
