sc.pl.dotplot(..., categories_order=[...]) doesn't handle not providing all categories
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
Minimal code sample (that we can copy&paste without having any data)
import scanpy as sc
pbmc = sc.datasets.pbmc3k_processed()
cats = pbmc.obs["louvain"].cat.categories
genes = list(pbmc.uns["rank_genes_groups"]["names"][0])
# this works:
sc.pl.dotplot(pbmc, genes, groupby="louvain", categories_order=cats[::-1])
# this errors:
sc.pl.dotplot(pbmc, genes, groupby="louvain", categories_order=cats[:3])
ERROR: Please check that the categories given by the `order` parameter match the categories that want to be reordered.
Mismatch: {'Dendritic cells', 'Megakaryocytes', 'NK cells', 'FCGR3A+ Monocytes', 'CD8 T cells'}
Given order categories: Index(['CD4 T cells', 'CD14+ Monocytes', 'B cells'], dtype='object')
louvain categories: ['CD4 T cells', 'CD14+ Monocytes', 'B cells', 'CD8 T cells', 'NK cells', 'FCGR3A+ Monocytes', 'Dendritic cells', 'Megakaryocytes']
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-580bb69f9615> in <module>
----> 1 sc.pl.dotplot(pbmc, genes, groupby="louvain", categories_order=cats[:3])
~/github/scanpy/scanpy/plotting/_dotplot.py in dotplot(adata, var_names, groupby, use_raw, log, num_categories, expression_cutoff, mean_only_expressed, cmap, dot_max, dot_min, standard_scale, smallest_dot, title, colorbar_title, size_title, figsize, dendrogram, gene_symbols, var_group_positions, var_group_labels, var_group_rotation, layer, swap_axes, dot_color_df, show, save, ax, return_fig, vmin, vmax, vcenter, norm, **kwds)
982 return dp
983 else:
--> 984 dp.make_figure()
985 savefig_or_show(DotPlot.DEFAULT_SAVE_PREFIX, show=show, save=save)
986 show = settings.autoshow if show is None else show
~/github/scanpy/scanpy/plotting/_baseplot_class.py in make_figure(self)
606 mainplot_height = len(self.categories) * category_height
607 mainplot_width = (
--> 608 len(self.var_names) * category_width + self.group_extra_size
609 )
610 if self.are_axes_swapped:
AttributeError: 'DotPlot' object has no attribute 'group_extra_size'
First, what's up with the printed error?
Second, I think subsetting the groups and specifying the order can be done at the same time. This is the behaviour of the groups kwarg for variable axis of sc.pl.rank_genes_groups. This is also the behaviour of var_names.
I'd noticed some related behaviour I can't quite remember while fixing up #1529. Noticed this specific case while looking at #1914.
Versions
-----
anndata 0.7.7.dev4+g49739eb
scanpy 1.9.0.dev7+g092376d2
sinfo 0.3.1
-----
PIL 8.2.0
anndata 0.7.7.dev4+g49739eb
anyio NA
appnope 0.1.0
argon2 20.1.0
asciitree NA
attr 20.3.0
babel 2.8.0
backcall 0.2.0
beta_ufunc NA
binom_ufunc NA
brotli 1.0.9
certifi 2020.06.20
cffi 1.14.0
chardet 3.0.4
cloudpickle 1.6.0
colorama 0.4.4
cycler 0.10.0
cython_runtime NA
dask 2021.05.0
dateutil 2.8.1
decorator 4.4.2
fasteners NA
fsspec 2021.06.0
google NA
h5py 3.2.1
idna 2.10
igraph 0.9.6
ipykernel 5.5.4
ipython_genutils 0.2.0
ipywidgets 7.5.1
jedi 0.17.2
jinja2 2.11.2
joblib 1.0.1
json5 NA
jsonschema 3.2.0
jupyter_server 1.8.0
jupyterlab_server 2.6.0
kiwisolver 1.2.0
leidenalg 0.8.3
llvmlite 0.36.0
louvain 0.7.0
markupsafe 1.1.1
matplotlib 3.4.2
monotonic NA
mpl_toolkits NA
msgpack 1.0.0
natsort 7.1.1
nbclassic NA
nbformat 5.1.2
nbinom_ufunc NA
numba 0.53.1
numcodecs 0.8.0
numexpr 2.7.2
numpy 1.21.0
packaging 20.9
pandas 1.2.4
parso 0.7.1
pexpect 4.8.0
pickleshare 0.7.5
pkg_resources NA
prometheus_client NA
prompt_toolkit 3.0.18
psutil 5.8.0
ptyprocess 0.6.0
pvectorc NA
pycparser 2.20
pygments 2.7.0
pyparsing 2.4.7
pyrsistent NA
pytoml NA
pytz 2020.1
requests 2.25.1
scanpy 1.9.0.dev7+g092376d2
scipy 1.7.0
send2trash NA
setuptools_scm NA
sinfo 0.3.1
sitecustomize NA
six 1.15.0
sklearn 0.24.2
snappy NA
sniffio 1.2.0
socks 1.7.1
sparse 0.12.0+21.gc96cc1a
sphinxcontrib NA
statsmodels 0.12.2
storemagic NA
tables 3.6.1
tblib 1.6.0
terminado 0.8.3
texttable 1.6.3
tlz 0.11.1
toolz 0.11.1
tornado 6.1
tqdm 4.61.1
traitlets 5.0.5
typing_extensions NA
urllib3 1.26.4
wcwidth 0.2.5
websocket 1.1.0
yaml 5.3.1
zappy NA
zarr 2.8.3
zmq 19.0.2
-----
IPython 7.23.1
jupyter_client 6.1.12
jupyter_core 4.7.1
jupyterlab 3.0.16
notebook 6.4.0
-----
Python 3.8.10 (default, May 4 2021, 03:05:50) [Clang 12.0.0 (clang-1200.0.32.29)]
macOS-10.16-x86_64-i386-64bit
16 logical CPU cores, i386
-----
Session information updated at 2021-07-01 15:01
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at sc.pl.dotplot in scanpy/plotting/_dotplot.py and follow the DotPlot setup into scanpy/plotting/_baseplot_class.py, where the traceback occurs. Reproduce the cats[:3] example, then verify that supplying a partial categories_order subsets and orders the displayed groups without the reported AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100