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

Fixing levels of grouping variables when splitting DimPlots #37

Closed
nikofleischer opened this issue May 13, 2022 · 7 comments
Closed

Fixing levels of grouping variables when splitting DimPlots #37

nikofleischer opened this issue May 13, 2022 · 7 comments
Assignees
Labels
bug Something isn't working Not Working As Intended This doesn't seem right

Comments

@nikofleischer
Copy link

Hey,
sorry for already another feature request, but here it comes: When splitting DimPlots using split.by the number of levels of the grouping variable for group.by gets reduced to only the levels that are actually in the cells being plotted in every split. This is very distracting for example when u split a clustering result over many subplots and the colors for the clusters change in every subplot due to some of the clusters being specific for one of the covariates split by.

Thanks a lot,
Niko

@samuel-marsh
Copy link
Owner

Hi Niko,

no worries! Just to clarify does this also occur with Seurat::DimPlot or just when using DimPlot_scCustom?

Thanks,
Sam

@samuel-marsh samuel-marsh self-assigned this May 13, 2022
@samuel-marsh samuel-marsh added the more-info-needed Further information is requested label May 13, 2022
@nikofleischer
Copy link
Author

nikofleischer commented May 13, 2022 via email

@samuel-marsh
Copy link
Owner

Ok let me take look at DimPlot code in Seurat and see if there is fix. Not remembering how the split is implemented there but I feel like this should be addressable.

@samuel-marsh samuel-marsh added bug Something isn't working Not Working As Intended This doesn't seem right labels May 13, 2022
@samuel-marsh
Copy link
Owner

Ok so I've done little testing and think Seurat is actually handling it ok but scCustomize has issue. Let me provide example to make sure what I'm testing is the same issue that you are describing.

So for this example using object from my recent paper. It has 2 conditions under meta.data Transcription, 2 conditions under meta.data method and a combined variable called Transcription_Method with 4 variables.

All 4 conidtions in Transcription Method contribute to all of the clusters.

p1 <- DimPlot(test, cols = DiscretePalette(n = 36, palette = "polychrome"))

p2 <- DimPlot(test, group.by = "Transcription_Method", cols = JCO_Four())
wrap_plots(p1 , p2)

image

Now I identify cells in one cluster to remove from only 2 of the conditions and then subset the object:

act_cells <- WhichCells(object = test, idents = "Activated")

test2 <- test
Idents(test2) <- "Transcription"

inhib_cells <- WhichCells(object = test2, idents = "INHIB")

intersect_cells <- intersect(x = act_cells, y = inhib_cells)

test_sub <- subset(test, cells = intersect_cells, invert = TRUE)

Now I plot DimPlot by Transcription Method to confirm cells are missing from 2 of the groups and then show that colors are retained across all clusters despite a missing level in 2 of the plots:

DimPlot(test_sub, split.by = "Transcription_Method", cols = DiscretePalette(n = 36, palette = "polychrome"))

DimPlot(test_sub, split.by = "Transcription_Method", cols = c("NA", "black", "NA", "NA", "NA", "NA"))

image
image

However, the error is present in scCustomize::DimPlot_scCustom:

DimPlot_scCustom(test_sub, split.by = "Transcription_Method")

image

It makes sense actually given the way I wrote the function because to avoid the shared y-axis that Seurat uses.

I will work on scCustomize fix but looks like Seurat works ok if I'm understanding the issue correctly.

If your issue is different from what I'm describing please let me know.

Done with Seurat 4.1.0 and SeuratObject 4.0.4

Best,
Sam

@nikofleischer
Copy link
Author

Yes, exactly the problem I was describing. And sorry, you were right Seurat handles this fine. Thanks so much already :)

@samuel-marsh
Copy link
Owner

Ok ya no worries. I will work on fix for DimPlot_scCustom. I think it should be relatively easy by just creating additional variable that subsets the color list per plot being created.

Best,
Sam

@samuel-marsh
Copy link
Owner

ok so that solution did work (ish) but there is far easier one just setting manual scale using named vector. Should be fixed now in the develop branch v0.7.0.9912. If bug still occurs for you with this update let me know and I'll reopen the issue.

Best,
Sam

@samuel-marsh samuel-marsh removed the more-info-needed Further information is requested label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Not Working As Intended This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants