sinfonia.utils.get_N_clusters

sinfonia.utils.get_N_clusters(adata, n_cluster, cluster_method='louvain', range_min=0, range_max=3, max_steps=30, tolerance=0)

Tune the resolution parameter in clustering to make the number of clusters and the specified number as close as possible.

Parameters
  • adata – AnnData object of shape n_obs × n_vars. Rows correspond to cells and columns to genes.

  • n_cluster – Specified number of clusters.

  • cluster_method – Method (louvain or leiden) used for clustering. By default, cluster_method=’louvain’.

  • range_min – Minimum clustering resolution for the binary search.

  • range_max – Maximum clustering resolution for the binary search.

  • max_steps – Maximum number of steps for the binary search.

  • tolerance – Tolerance of the difference between the number of clusters and the specified number.

Returns

AnnData object with clustering assignments in adata.obs:

  • adata.obs[‘louvain’] - Louvain clustering assignments if cluster_method=’louvain’.

  • adata.obs[‘leiden’] - Leiden clustering assignments if cluster_method=’leiden’.

Return type

adata