[go: nahoru, domu]

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

Dotplot / Matrixplot Bug/Suggestion [Key Error] Because "var_group_labels" & "categories_order" using the same variable (memory), mostly happened when "swap_axes=True" #3081

Open
3 tasks done
WhatMelonGua opened this issue May 31, 2024 · 1 comment
Labels
Bug 🐛 Needs info❔ More information needed

Comments

@WhatMelonGua
Copy link
WhatMelonGua commented May 31, 2024

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

In fact, that's not a real bug report, but a suggestion about safe design to plot with scanpy.

It may happen when our celltype name is too long to show in the plotting figure.
The problem happens here:

if diff * 2 < len(group_labels[idx]):
# cut label to fit available space
group_labels[idx] = group_labels[idx][: int(diff * 2)] + "."

It cut off the string in functions dotplot/matrixplot(var_group_labels=) , as the function _plot_var_groups_brackets(group_labels=).

So, when we use code like the sample, the veryvery long labels will be cut off & we got an Error
Because Var celltype_order is a list, and function _plot_var_groups_brackets (PATH: scanpy/plotting/_baseplot_class.py) will affect the string in list,
then if affect the celltype_order itself, so

when called with the categories_order, it has been changed by _plot_var_groups_brackets, then the Error happened.

I suggest to add one copy, for parameter group_labels in function _plot_var_groups_brackets
It may help someone are not so skillful on coding, to solve the problem maybe happen.

For example: add the code group_labels = copy.deepcopy(group_labels) at the top of function _plot_var_groups_brackets

Thank you very much for your attention

Minimal code sample

adata: any anndata
markers: gene list include in var_names
group: obs key
celltype_order = ['short', 'veryveryverylong_name', 'others', ...]

sc.pl.dotplot(
	adata, markers, group, show=False, swap_axes=True,
	categories_order=celltype_order, var_group_labels=celltype_order, var_group_positions=pos_markers,
)

Error output

KeyError: "['veryvery.'] not in index"
# (in fact the 'veryvery.' comes from the 'veryveryverylong_name' in celltype_order )

Versions


@WhatMelonGua WhatMelonGua added Bug 🐛 Triage 🩺 This issue needs to be triaged by a maintainer labels May 31, 2024
@flying-sheep
Copy link
Member

I can’t reproduce this, please provide a fully reproducible example that I can just paste and execute.

@flying-sheep flying-sheep added Needs info❔ More information needed and removed Triage 🩺 This issue needs to be triaged by a maintainer labels Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Needs info❔ More information needed
Projects
None yet
Development

No branches or pull requests

2 participants