scverse / scverse/squidpy

Add automatic K selection (CellCharter's ClusterAutoK) for the cellcharter niche flavor

Open
#1,244 1 comment 1 reaction 1 assignee View on GitHub

@selmanozleyen is already working on this.

Since Jul 19, 2026.

Dominant language
Python
Stars
598
Forks
121
Avg merge
3d 11h
Merged PRs (30d)
3

Description

Context

sq.gr.calculate_niche(flavor="cellcharter", ...) fits a GMM with a fixed, user-supplied n_components. CellCharter's own ClusterAutoK instead searches a range of K, refits the model max_runs times per K, scores stability via Fowlkes-Mallows similarity between labelings at K/K-1/K+1, and picks the K with highest stability (best_k, plus a peaks attribute for runner-up candidates). Squidpy's _get_GMM_clusters currently skips this -- its own docstring notes it's "simplified... without stability analysis."

Proposal

Port ClusterAutoK-style automatic K selection, with an input signature that mirrors CellCharter's own API rather than a magic-string trigger -- i.e. take a n_clusters range plus the same knobs CellCharter exposes (max_runs, convergence_tol, similarity_function, model_params), so behavior and defaults line up with the original.

Open question: integrate this as an option inside calculate_niche vs. a separate standalone function (e.g. sq.gr.cluster_auto_k) that returns best_k/stability curve/peaks, to be fed into calculate_niche afterward. Leaning toward separate/composable, since it's a stochastic multi-run search (many GMM refits across a K range) rather than a single deterministic fit, and bolting it into calculate_niche's already-branchy per-flavor validation adds complexity. Not settled yet -- needs discussion.

Dependency

Blocked on / should follow #1192 (refactor of calculate_niche into separate functions) -- final placement of auto-K selection depends on how that refactor shakes out.

cc: @sarajimenez

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.