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

Batch correction incorrectly assigns cell labels #86

Closed
Hrovatin opened this issue Oct 1, 2023 · 4 comments
Closed

Batch correction incorrectly assigns cell labels #86

Hrovatin opened this issue Oct 1, 2023 · 4 comments

Comments

@Hrovatin
Copy link
Contributor

Hrovatin commented Oct 1, 2023

I have tried to integrate some of my own data and then reproduce the example from https://scgen.readthedocs.io/en/stable/tutorials/scgen_batch_removal.html , but it seems that the latent data and the obs are not joined correctly, creating wrong cell latent embedding-label pairs.

This is the result from the tutorial, with a clear mismatch between cell type clusters and cell labels
image

I think the reason could be in https://github.com/theislab/scgen/blob/06084773e56cad0dec340138441dee47a39af752/scgen/_scgen.py#L315C16-L315C16 as you don't check that indices match, but I haven't tested it so it may be a different reason.

scGEN version: 2.1.1

ps. the tutorial also has other mistakes, like cell_type->celltype and the use_rep is missing in neighbours computation for latent

@Hrovatin Hrovatin changed the title Batch correction incorrectly mixes cell labels Batch correction incorrectly assigns cell labels Oct 1, 2023
@Hrovatin
Copy link
Contributor Author

Hrovatin commented Oct 1, 2023

Indeed, changing the above line to corrected.obsm["latent"] = all_corrected_data[corrected.obs_names,:].X fixes the issue.

I also needed to add .detach() to self.module.generative(torch.Tensor(all_corrected_data.X))["px"].cpu().detach().numpy()

image

@M0hammadL
Copy link
Member

Hi Karin

Thanks for pointing this out, could you kindly add that as a PR we can merge it then

@M0hammadL
Copy link
Member

Btw see here you can do the same thing with cpa:

https://cpa-tools.readthedocs.io/en/latest/tutorials/Batch_correction_in_expression_space.html

@Hrovatin
Copy link
Contributor Author

Hrovatin commented Oct 1, 2023

The PR is here: #87
I would just merge despite black failing as I didn't introduce any major formatting changes except the 4 lines as mentioned above

@Hrovatin Hrovatin closed this as completed Oct 1, 2023
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