You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add automatic K selection (CellCharter's ClusterAutoK) for the cellcharter niche flavor #1244
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.
But before that, I'd like to deprecate random_state here and take seed like the rest of the functions in squipy. And also properly handle the rngs. Because I know the initialization of kmeans changes the results a lot
Activity
selmanozleyen commentedon Aug 11, 2026
and additionally these kwargs to the cellcharter compute niche function
How does this signature look @Intron7 ?
But before that, I'd like to deprecate
random_statehere and takeseedlike the rest of the functions in squipy. And also properly handle the rngs. Because I know the initialization of kmeans changes the results a lot