harpy.tb.flowsom#
- harpy.tb.flowsom(sdata, cells_labels_name, cluster_labels_name, output_table_name, q=0.999, chunks=None, n_clusters=20, index_names_var=None, index_positions_var=None, random_state=100, region_key='fov_labels', instance_key='cell_ID', cell_index_name='cells', instance_size_key='shapeSize', raw_counts_key='raw_counts', overwrite=False, **kwargs)#
Run FlowSOM cell clustering on pixel-cluster-derived cell features.
Prepare the data obtained from pixel clustering for cell clustering (see
cell_clustering_preprocess()) and execute FlowSOM on the resulting table element (output_table_name) of the SpatialData object.This function applies the FlowSOM clustering algorithm (via
flowsom.FlowSOM) on spatial data contained in a SpatialData object. The algorithm organizes data into self-organizing maps and then clusters these maps, grouping them inton_clusters. The results of this clustering are added to a table element in thesdataobject.Typically, one would first process
sdataviapixel_clustering_preprocess()andflowsom()before using this function.- Parameters:
sdata (
SpatialData) – The input SpatialData object.cells_labels_name (
str|Iterable[str]) – The labels element(s) insdatathat contain cell segmentation masks. These masks should be previously generated usingsegment(). If a list of labels elements is provided, they will be clustered together (e.g. multiple samples).cluster_labels_name (
str|Iterable[str]) – The labels element(s) insdatathat contain metacluster or SOM cluster masks. These should be obtained viaflowsom().output_table_name (
str) – The output table element insdatawhere results of the clustering and metaclustering will be stored.q (
float|None(default:0.999)) – Quantile used for normalization. If specified, each pixel SOM/meta cluster column inoutput_table_nameis normalized by this quantile prior to FlowSOM clustering. Values are multiplied by 100 after normalization.chunks (
str|int|tuple[int,...] |None(default:None)) – Chunk sizes for processing the data. If provided as a tuple, it should detail chunk sizes for each dimension(z),y,x.n_clusters (
int(default:20)) – The number of metaclusters to form from the self-organizing maps.index_names_var (
Iterable[str] |None(default:None)) – Specifies the variable names to be used fromsdata.tables[output_table_name].varfor clustering. IfNone,index_positions_varis used if notNone.index_positions_var (
Iterable[int] |None(default:None)) – Specifies the positions of variables to be used fromsdata.tables[output_table_name].var. Used ifindex_names_varisNone.random_state (
int(default:100)) – A random state for reproducibility of the clustering.instance_key (
str(default:'cell_ID')) – Instance key. The name of the column inAnnDatatable.obsthat will hold the instance ids.region_key (
str(default:'fov_labels')) – Region key. The name of the column inAnnDatatable.obsthat will hold the name of the element(s) that are annotated by the resulting table.cell_index_name (
str(default:'cells')) – The name of the index of the resultingAnnDatatable.instance_size_key (
str(default:'shapeSize')) – The key in theAnnDatatable.obsthat will hold the size of the instances (obtained fromcells_labels_name).raw_counts_key (
str(default:'raw_counts')) – Name of theAnnDatalayer where the non-preprocessed counts will be stored.overwrite (
bool(default:False)) – If True, overwrites the existing data inoutput_table_nameif it already exists.**kwargs – Additional keyword arguments passed to
flowsom.FlowSOM.
- Return type:
tuple[SpatialData,FlowSOM]- Returns:
: tuple:
The updated
sdatawith the clustering results added.An instance of
flowsom.FlowSOMcontaining the trained FlowSOM model.
See also
flowsom()FlowSOM pixel clustering.
cell_clustering_preprocess()Prepare data for cell clustering.