satijalab / sctransform

R package for modeling single cell UMI expression data using regularized negative binomial regression
GNU General Public License v3.0
203 stars 33 forks source link

How to deal with nested effects in scTransform. #152

Closed AnthoOzier closed 1 year ago

AnthoOzier commented 1 year ago

Hello,

I have a dataset with 2 conditions (say male and female) and several replicate per condition. I say that the condition effect and the replicate effect are nested because each replicate bellongs to one condition only.

When I apply SCTransform(x, vars.to.regress = c("replicate")), the normalization is done replicate per replicate and the scale.data for each replicate is centered on zero, which is almost what I want. But it results in erasing the condition effect that I want to study with Differential Expression Analysis tools, because both conditions are centered in zero due to the nested effects.

Usually, to correct the data per replicate without erasing the condition effect in a linear framework, I would add the previously computed condition mean to each centered replicate, so that each replicate is centered on its corresponding condition mean.

I have two questions : Is it a correct use of vars.to.regress ?
Do you think it is possible to perform a similar reasonning using SCTransform ?

Thanks, Anthony

saketkc commented 1 year ago

Can you provide more details on what you mean by "erasing the condition effect"? Post SCTransform, the DE should be run on the data slot (and not the scale.data slot which stores the pearson residuals post regressing the covariates you pass through vars.to.regress). If you run a GLM based DE tool on the corrected counts, you can account for other covariates.