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

Adding Alpha/Transparency to FeaturePlot #21

Closed
jkaiser87 opened this issue Jan 11, 2022 · 6 comments
Closed

Adding Alpha/Transparency to FeaturePlot #21

jkaiser87 opened this issue Jan 11, 2022 · 6 comments
Assignees
Labels
enhancement Enhance existing function/feature

Comments

@jkaiser87
Copy link

jkaiser87 commented Jan 11, 2022

Hey Samuel, thank you so much for putting together this tool, I am exploring it at the moment and am already super happy with it!

As you noted in the vignette, the FeaturePlot from Seurat makes it sometwhat difficult to interpret the gene expression in a way as the non-expressing cells are sometimes plotted on top of the expressing cells, your solution to by default order them imho makes a lot of sense! However, in this case, you might also be over-emphasizing certain areas in the case that there are more non-expressing cells but the few expressing cells are placed on top?

For this reason, I was wondering if it would be possible to implement the alpha parameter to the function, as it would allow to "see through" the expressors and would additionally highlight areas of high expression.

I have searched this in the Seurat github aswell and it doesn't seem that they are implementing it, but I found this code snippet that makes it somewhat work: plot$layers[[1]]$aes_params$alpha <- 0.6 (my main issue is that this will only affect the last column if split by sample e.g.)

Thanks again for all the work you put into this and for sharing it!
Best, Julia

@samuel-marsh samuel-marsh added the enhancement Enhance existing function/feature label Jan 11, 2022
@samuel-marsh samuel-marsh self-assigned this Jan 11, 2022
@samuel-marsh
Copy link
Owner

Hi Julia,

Thanks so much and so glad you are enjoying the package!! I think in this case the easiest thing might be if I test whether a potential PR to Seurat would work and the devs would be open to it. Since FeaturePlot_scCustom relies heavily on standard FeaturePlot it might be easiest this way. I can play around on my Seurat fork and see what things look like and I can submit PR to Seurat if it works. I'll report back here and let you know how it goes.

While not perfect solution using the Nebulosa-based plotting features I've included could help overcome some of this issue of potential masking. https://samuel-marsh.github.io/scCustomize/articles/Gene_Expression_Plotting.html#density-plots.
Given two regions that appear identical based on expressing cells in front a region with more non-expressors behind the expressing points would have lower density.

Best,
Sam

@jkaiser87
Copy link
Author

Thanks for looking into this, I understand that it would be easiest to implement this in the original Seurat option. The last I've found in their github was an issue from 2019 addressing this which resulted in the order option but no alpha add-on. I think on larger datasets this could massively improve the visualization, so any update that you see would be easy to implement would be amazing!

I am playing around with the Nebulosa-based feature as you have described in your vignette and agree that this could be an interesting option! Just for my understanding, what would the "density" refer to? I have some genes that would be above 1 (1.5 eg), so its probably not referring to density = % of gene expression in the area compared to max expression? Also, it seems that splitting into samples isn't possible in the provided function, and in the original version might result in the density of ALL samples being overlayed on top of each facet instead of being calculated for each column specifically, which would raise the same issue as the featureplot without alpha?

Either way, just wanted to thank you again for your input into this and am looking forward to any potential updates or ideas you might have :)

@samuel-marsh
Copy link
Owner

Ya I'll keep looking into it. And just to confirm as well what you are describing is only changing the transparency of the expressing points not the points below the na_cutoff correct? Using code you provided above you're right only works on final plot (due to patchwork) but it also changes transparency of both the expressing and non-expressing cells.

In terms of Nebulosa, no it's a density metric you can see Nebulosa paper here for more info:
https://academic.oup.com/bioinformatics/article-abstract/37/16/2485/6103785?redirectedFrom=fulltext

In terms of splitting you are right currently that isn't supported by Nebulosa and yes you are right there I forgot about the splitting issue. I looked into it when I created the function and it would require Nebulosa to add that feature so that kernel density was calculated independently for each sample (currently just calculates across all cells).

Best,
Sam

@jkaiser87
Copy link
Author

I think one could argue for both ways that the non-expressing cells should be either transparent (then it would be easier to assess how many cells generally are in each cluster etc) or non-transparent (then the expression of the expression cells will be highlighted more), so imho either way would benefit the visualization! I don't know if one would be easier to implement over the other, or if someone else has a strong opinion for one or the other, but for my specific case both would work well.

Thanks again, best,
Julia

@samuel-marsh
Copy link
Owner

Ya it's definitely tricky. FeaturePlot may not be best implementation either because especially with UMAP dim reduction it;s extremely common for the density of points to be really high so when dealing with large datasets it's quite tricky.

I'm currently working on adding this type of plot as addition column annotation on Clustered_DotPlot. It adds more info than simply percent expressing because knowing the number of total cells and percent expressing is important context.
https://twitter.com/galicae/status/1473313355918159872?s=20

Best,
Sam

@samuel-marsh
Copy link
Owner

Hey Julia,

So I've just implemented a solution to control one or both of the alpha values for the expressing and non-expressing points. The new parameters are alpha_exp and alpha_na_exp. All you need to do is provide an alpha value (0-1) and the provided expression color scale and/or na_color will be updated to reflect that alpha. Hope this helps! :) Live in dev branch currently >v0.7.0.0020. Will likely merge into master soon. Let me know if you have any issues using new parameters and I can reopen issue.

Best,
Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhance existing function/feature
Projects
None yet
Development

No branches or pull requests

2 participants