scverse / scverse/scanpy

Finding a better home for cluster centroids (i.e. 🚫_tmp_cluster_pos)

Open
#938 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

We have a weird temporary global variable called sc.pl._utils._tmp_cluster_pos. We use it for storing the positions of cluster centroids (actually the centroids of any categorical variable for any sort of embedding). The weird part is that it's set in scatterplot functions (see https://github.com/theislab/scanpy/blob/master/scanpy/plotting/_anndata.py#L468 and https://github.com/theislab/scanpy/blob/master/scanpy/plotting/_tools/scatterplots.py#L809) and used only by sc.pl.paga_compare (https://github.com/theislab/scanpy/blob/master/scanpy/plotting/_tools/paga.py#L119).

First, it's not obvious where paga_compare finds centroids (it was a mystery to me until recently). Second, the current design is error-prone (see a corner case https://github.com/theislab/scanpy/issues/686). Therefore, there should be a better place to store cluster centroids :)

I'm not following the discussion about the future of AnnData, but maybe having something like adata.uns['obs_category_leiden'] and storing colors and centroids in it e.g. adata.uns['obs_category_leiden']['colors'] and adata.uns['obs_category_leiden']['centroids']['X_umap'] would be more structured.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the scatterplot code in scanpy/plotting/_anndata.py and scanpy/plotting/_tools/scatterplots.py where _tmp_cluster_pos is set, then inspect scanpy/plotting/_tools/paga.py where it is consumed. Review issue #686 for the error-prone corner case. Done means paga_compare obtains centroids from a structured, reliable location rather than the temporary global.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.