sparrow.tb.cell_clustering_preprocess

sparrow.tb.cell_clustering_preprocess#

sparrow.tb.cell_clustering_preprocess(sdata, labels_layer_cells, labels_layer_clusters, output_layer, q=0.999, chunks=None, overwrite=False)#

Preprocesses spatial data for cell clustering.

This function prepares a SpatialData object for cell clustering by integrating cell segmentation masks (obtained via e.g. sp.im.segment) and SOM pixel/meta cluster (obtained via e.g. sp.im.flosom). The function calculates the cluster count (clusters provided via labels_layer_clusters) for each cell in labels_layer_cells, normalized by cell size, and optionally by quantile normalization if q is provided. The results are stored in a specified table layer within the sdata object of shape (#cells, #clusters).

Parameters:
  • sdata (SpatialData) – The input SpatialData object containing the spatial proteomics data.

  • labels_layer_cells (Union[str, Iterable[str]]) – The labels layer(s) in sdata that contain cell segmentation masks. These masks should be previously generated using sp.im.segment.

  • labels_layer_clusters (Union[str, Iterable[str]]) – The labels layer(s) in sdata that contain metacluster or cluster masks. These should be derived from sp.im.flowsom.

  • output_layer (str) – The name of the table layer within sdata where the preprocessed data will be stored.

  • q (float | None (default: 0.999)) – Quantile used for normalization. If specified, each pixel SOM/meta cluster column in output_layer is normalized by this quantile. Values are multiplied by 100 after normalization.

  • chunks (Union[str, tuple[int, ...], 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.

  • overwrite (bool (default: False)) – If True, overwrites the existing data in the specified output_layer if it already exists.

Return type:

SpatialData

Returns:

: The input sdata with a table layer added (output_layer).

See also

sparrow.im.flowsom

flowsom pixel clustering.

sparrow.tb.flowsom

flowsom cell clustering.