Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate batch effect and condition effect simutaneously. #8

Open
yujias424 opened this issue May 17, 2023 · 3 comments
Open

Simulate batch effect and condition effect simutaneously. #8

yujias424 opened this issue May 17, 2023 · 3 comments

Comments

@yujias424
Copy link

Hi,

Thank you for presenting this excellent package. I wonder whether it is possible to simulate the batch effect and condition effect simultaneously. For example, if I use the ifnb reference to simulate the condition effect, can I also simulate some batch effect without providing the reference for batch effect simultaneously?

Best,
Larry

@SONGDONGYUAN1994
Copy link
Owner

SONGDONGYUAN1994 commented May 17, 2023

Hi Larry,
Thank you for being interested in our work. The short answer is "yes", and it has been tried by others (e.g., scMerge2. )

You can check the vignette scDesign3 Introduction. You will need to use the "step-by-step" strategy. The function extract_para will return the mean matrix of each gene's expected expression in each cell. Then, you can add your own batch effects on it! The only tricky thing is that you need to specify the batch effects for each gene. In our paper, we belive that gene $j$'s batch effect should be a shift of the mean; others may have different ideas, but you can always "design" this by yourself, aka, adding your artificial batch effects.

Best regards,
Dongyuan

@yujias424
Copy link
Author

Dear Dongyuan,

Thank you for your response! I ran a demo following your suggestions but not quite sure whether it is correct.

I firstly followed the step-by-step strategy to simulate two dataset A and B (run simu_new twice). And I used following code to simulate the batch effect based on a log-normal distribution,

batch_rlnorm <- rlnorm(length(rownames(example_sce)), meanlog = 0.4, sdlog = 0.4) 
effect_direction <- sample(c(-1, 1), length(rownames(example_sce)) * 1, replace = TRUE)
batch_effect <- effect_direction * batch_rlnorm

After generating the batch effect, they will be added to logcounts of dataset B via following code,

dat_withbatcheffect <- apply(logcounts(simu_sce_batch2), 2, function(x) x+batch_effect)

I wonder whether this could be regarded as a valid procedure to introduce the batch effect to one dataset.

Best Regards,
Larry

@SONGDONGYUAN1994
Copy link
Owner

Hi Larry,
Your generation of batch effects looks good. However, my suggestion is to add it on mean_mat from extract_para() before you run simu_new(). Now your batch effect is added on counts level; I would think it should be added on the expected counts level.

Best,
Dongyuan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants