knn_clustering
- spac.transformations.knn_clustering(adata, features, annotation, layer=None, k=50, output_annotation='knn', associated_table=None, missing_label='no_label', **kwargs)[source]
Calculate knn clusters using sklearn KNeighborsClassifier
The function will add these two attributes to adata: .obs[output_annotation]
The assigned int64 class labels by KNeighborsClassifier
- .uns[output_annotation_features]
The features used to calculate the knn clusters
- Parameters:
adata (anndata.AnnData) – The AnnData object.
features (list of str) – The variables that would be included in fitting the KNN classifier.
annotation (str) – The name of the annotation used for classifying the data
layer (str, optional) – The layer to be used.
k (int, optional) – The number of nearest neighbor to be used in creating the graph.
output_annotation (str, optional) – The name of the output layer where the clusters are stored.
associated_table (str, optional) – If set, use the corresponding key adata.obsm to calcuate the clustering. Takes priority over the layer argument.
missing_label (str or int) – The value of missing annotations in adata.obs[annotation]
- Returns:
adata is updated inplace
- Return type:
None