spatial_cluster
Short Description
sm.tl.spatial_cluster
: This function clusters cells based on their spatial
neighborhood matrices, which can be derived from analyses such as sm.tl.spatial_expression
,
sm.tl.spatial_count
, or sm.tl.spatial_lda
. By leveraging various clustering algorithms,
including k-means, phenograph, and leiden, it enables the identification of spatially
coherent cell groups or microenvironments within tissue sections.
Function
spatial_cluster(adata, df_name='spatial_count', method='kmeans', k=10, n_pcs=None, resolution=1, phenograph_clustering_metric='euclidean', nearest_neighbors=30, random_state=0, label=None, verbose=True, output_dir=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
Annotated data matrix or path to an AnnData object, containing spatial gene expression data. |
required |
df_name |
str
|
Specifies the label of the spatial analysis results to use for clustering. Default options are 'spatial_count' and 'spatial_expression'. |
'spatial_count'
|
method |
str
|
The clustering method to apply. Supported methods include 'kmeans', 'phenograph', and 'leiden'. |
'kmeans'
|
k |
int
|
Number of clusters to form when using K-Means clustering. Applies only if method='kmeans'. |
10
|
n_pcs |
int
|
Number of principal components to use in 'leiden' clustering. If None, all components are used. |
None
|
resolution |
float
|
Controls the granularity of clustering. Higher values lead to more clusters. Applies to 'leiden' and 'phenograph'. |
1
|
phenograph_clustering_metric |
str
|
The metric for defining nearest neighbors in 'phenograph' clustering. Choices include 'euclidean', 'manhattan', 'cosine', etc. |
'euclidean'
|
nearest_neighbors |
int
|
Number of nearest neighbors to consider in the graph construction step, for 'leiden' and 'phenograph'. |
30
|
random_state |
int
|
Seed for random number generation, ensuring reproducible results. |
0
|
label |
str
|
Custom label for storing results in |
None
|
verbose |
bool
|
If set to |
True
|
output_dir |
str
|
Directory path for saving output files. If None, results are not saved to disk. |
None
|
Returns:
Name | Type | Description |
---|---|---|
adata |
AnnData
|
The input |
Example
1 2 3 4 5 6 7 8 |
|
Source code in scimap/tools/spatial_cluster.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|