This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Help with scanpy batch correction

Hello

I am a bit confused about hatch corrections. Scanpy says you can specify batch key when choosing highly variable genes. From what I understand using the batch key may help with identifying the cell types. If I have 2 conditions (control and treated) can I use condition as the batch key? If I do that and then assign the cell types can I do DE between the 2 conditions for each cell type or will it affect the results? It seems like the batch key affected the highly variable genes and PCA but it does not affect the adata.X which is used for DE.

Thank you

scanpy

1 answer

Batch correction or "blocking" for a group in gene selection helps that the clustering and visualization (UMAP, dimreductions) are dominated by celltype differences (so genes varaible between cells) rather than variable due to the group. Usually, in most cases, you want to block for any group differences during clustering and dimensionality reduction. So per-cell analysis. Later, in DE, which is per-gene you of course preserve that difference and explicitely test for the difference, adjusting for other pontential confounders, such as true batches, or other sources of unwanted variation.

Thank you. I am having trouble understanding how the batch correction would affect the DE. For example, let's pretend I did batch correction when selecting highly variable genes and then I clustered the data using the leiden algorithm. Then I did DE between the clusters and used the markers and identified the cell types. Then if I decide to do DE between the control and treated for each cell type why would the batch correction affect the data? I use scanpy and I checked that my adata.X is the same after normalizing (before selecting HVGs) and after doing the leiden clustering.

No it would not affect, because the labels control vs treated are predefined by your experimental design. Just the celltypes is what you have to figure out, and even this you could do by something like SingleR with a reference dataset so the whole clustering and UMAP thing could be replaced. But usually people do cluster-markerDE-annotation, that's fine.

Log in to answer this question.