bioalpha.singlecell.tools.louvain
- bioalpha.singlecell.tools.louvain(adata: AnnData, resolution: float = 1.0, restrict_to: Tuple[str, Sequence[str]] | None = None, random_state: None | int | RandomState = 0, key_added: str = 'louvain', adjacency: spmatrix | None = None, flavor: Literal['alpha', 'vtraag', 'igraph', 'rapids'] = 'alpha', directed: bool = True, use_weights: bool = False, partition_type: Literal['rb', 'cpm', 'rber'] = 'rb', neighbors_key: str | None = None, obsp: str | None = None, copy: bool = False, **kwargs) AnnData | None
Cluster cells into subgroups.
Cluster cells using the Louvain-alpha algorithm, an improved version of the Louvain algorithm. This requires having ran
pp.neighbors
orpp.bbknn
first.- Parameters:
adata (
AnnData
) – The annotated data matrix of shapen_obs
xn_vars
. Rows correspond to cells and columns to genes.resolution (
float
, default =1.0
) – A parameter value controlling the coarseness of the clustering. Higher values lead to more clusters. Set toNone
if overridingpartition_type
to one that doesn’t accept aresolution_parameter
.restrict_to (Optional[Tuple[
str
, Sequence[str
]]], default =None
) – Restrict the clustering to the categories within the key for sample annotation, tuple needs to contain(obs_key, list_of_categories)
.random_state (Optional[Union[
int
,RandomState
]], default =0
) – Change the initialization of the optimization.key_added (
str
, default ="louvain"
) –adata.obs
key under which to add the cluster labels.adjacency (Optional[
spmatrix
], default =None
) – Sparse adjacency matrix of the graph, defaults to neighborsconnectivities
.flavor (Literal[
"alpha"
,"vtraag"
,"igraph"
,"rapids"
], default = “alpha”) – Choose between to packages for computing the clustering."alpha"
is much the default.directed (
bool
, default =True
) – Interpret theadjacency
matrix as directed graph?use_weights (
bool
, default =False
) – Use weights from knn graph.partition_type (Optional[str], default =
rb
) – Type of partition to use. (rb
,cpm
,rber
) Only a valid argument ifflavor
is"alpha"
or"vtraag"
.neighbors_key (Optional[
str
], default =None
) – Use neighbors connectivities as adjacency. If not specified, louvain looks.obsp["connectivities"]
for connectivities (default storage place forpp.neighbors
). If specified, louvain looks.obsp[.uns[neighbors_key]["connectivities_key"]]
for connectivities.obsp (Optional[
str
], default =None
) – Use.obsp[obsp]
as adjacency. You can’t specify bothobsp
andneighbors_key
at the same time.copy (
bool
, default =False
) – Whether to copyadata
or modify it inplace.kwargs (
dict
) – Any further arguments to pass to_sctools.clustering.louvain
(which in turn passes arguments to thepartition_type
).
- Returns:
adata – If
copy=True
it returns or else adds fields toadata
:.obs[
key_added
] Array of dim (number of samples) that stores the subgroup id ("0"
,"1"
, …) for each cell..uns[
key_added
]["params"
] A dict with the values for the parametersresolution
,random_state
, andn_iterations
..uns[
key_added
]["modularity"
] The modularity score of Louvain-alpha algorithm. Only ifflavor="alpha"
- Return type:
AnnData