scib.metrics.opt_louvain

scib.metrics.opt_louvain(adata, label_key, cluster_key, function=None, resolutions=None, use_rep=None, inplace=True, plot=False, force=True, verbose=True, **kwargs)

Optimised Louvain clustering

DEPRECATED: Use cluster_optimal_resolution() instead

Louvain clustering with resolution optimised against a metric

Parameters:
  • adata – anndata object

  • label_key – name of column in adata.obs containing biological labels to be optimised against

  • cluster_key – name of column to be added to adata.obs during clustering. Will be overwritten if exists and force=True

  • function – function that computes the cost to be optimised over. Must take as arguments (adata, group1, group2, **kwargs) and returns a number for maximising

  • resolutions – list of resolutions to be optimised over. If resolutions=None, default resolutions of 20 values ranging between 0.1 and 2 will be used

  • use_rep – key of embedding to use only if adata.uns['neighbors'] is not defined, otherwise will be ignored

Returns:

Tuple of (res_max, score_max, score_all) or (res_max, score_max, score_all, clustering) if inplace=False. res_max: resolution of maximum score; score_max: maximum score; score_all: pd.DataFrame containing all scores at resolutions. Can be used to plot the score profile. clustering: only if inplace=False, return cluster assignment as pd.Series