scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

Gene selection plot for Pearson Residuals

Open jlause opened this issue 3 years ago • 3 comments

Hi @giovp @ivirshup, (also CCing @dkobak)

as we discussed at #1715 and in https://github.com/theislab/scanpy-tutorials/pull/43, I prepared a function pearson_residuals_hvg_scatter() that wraps sc.pl.scatter() to reproduce the "gene selection plot" from the tutorial. It can be used as a sanity check for both the HVG selection and the appropriateness of the used Pearson residual null model (as explained also in the tutorial notebook).

I also added a feature to show known marker genes on the plot, change plot aesthetics and which fields are used for plotting.

Looking forward to your thoughts on this one :) Best, Jan

PS: I prepared this PR on an independent branch from #1715 - hope that is the correct way in this situation!

import scanpy as sc
sc.settings.set_figure_params(dpi=80, facecolor="white")

#run pearson residuals gene selection
adata=sc.datasets.pbmc3k()
sc.pp.filter_genes(adata, min_cells=1)
sc.experimental.pp.highly_variable_genes(adata, flavor="pearson_residuals", n_top_genes=2000)

#basic plot
sc.experimental.pl.pearson_residuals_hvg_scatter(adata)

image

#modify some aesthetics
sc.experimental.pl.pearson_residuals_hvg_scatter(adata,kwargs_sc_pl_scatter=dict(size=30))

image

#highlight some marker genes
markers = ["IL7R", "LYZ", "CD14", "MS4A1", "CD8A",  "GNLY"]
sc.experimental.pl.pearson_residuals_hvg_scatter(adata,marker_names=markers,kwargs_sc_pl_scatter=dict(size=30))

image

#use custom fields in `adata` for x and y
#(there is also a similar option to use a different field for where HVG flag is stored)
sc.experimental.pl.pearson_residuals_hvg_scatter(adata,x='means',y='variances',return_ax=True)

image

#modify axis object after `sc.pl.scatter()` ran
ax = sc.experimental.pl.pearson_residuals_hvg_scatter(adata,return_ax=True)
ax.set_title('my title')
ax.set_xlabel('my x label')
ax.set_ylabel('my y label')

image

jlause avatar Mar 15 '22 15:03 jlause

Codecov Report

Merging #2176 (e643c54) into master (d805b41) will decrease coverage by 0.22%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2176      +/-   ##
==========================================
- Coverage   71.42%   71.19%   -0.23%     
==========================================
  Files          92       95       +3     
  Lines       11286    11322      +36     
==========================================
  Hits         8061     8061              
- Misses       3225     3261      +36     
Impacted Files Coverage Δ
scanpy/experimental/__init__.py 0.00% <0.00%> (ø)
scanpy/experimental/pl/__init__.py 0.00% <0.00%> (ø)
scanpy/experimental/pl/_preprocessing.py 0.00% <0.00%> (ø)

codecov[bot] avatar Mar 15 '22 15:03 codecov[bot]

Codecov Report

Merging #2176 (86eca00) into master (d7e1302) will decrease coverage by 0.15%. The diff coverage is 19.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2176      +/-   ##
==========================================
- Coverage   71.80%   71.64%   -0.16%     
==========================================
  Files          97      100       +3     
  Lines       11522    11578      +56     
==========================================
+ Hits         8273     8295      +22     
- Misses       3249     3283      +34     
Impacted Files Coverage Δ
scanpy/experimental/pl/_preprocessing.py 14.70% <14.70%> (ø)
scanpy/experimental/__init__.py 100.00% <100.00%> (ø)
scanpy/experimental/pl/__init__.py 100.00% <100.00%> (ø)
scanpy/external/pp/_scrublet.py 84.69% <0.00%> (-6.13%) :arrow_down:
scanpy/preprocessing/_simple.py 77.91% <0.00%> (-0.25%) :arrow_down:
scanpy/__init__.py 100.00% <0.00%> (ø)
scanpy/preprocessing/_normalization.py 86.04% <0.00%> (+2.32%) :arrow_up:

codecov[bot] avatar Oct 25 '22 12:10 codecov[bot]

@jlause do you plan on tackling these to get this in?

Zethson avatar Feb 15 '23 16:02 Zethson