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 vialabels_layer_clusters
) for each cell inlabels_layer_cells
, normalized by cell size, and optionally by quantile normalization ifq
is provided. The results are stored in a specified table layer within thesdata
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) insdata
that contain cell segmentation masks. These masks should be previously generated usingsp.im.segment
.labels_layer_clusters (
Union
[str
,Iterable
[str
]]) – The labels layer(s) insdata
that contain metacluster or cluster masks. These should be derived fromsp.im.flowsom
.output_layer (
str
) – The name of the table layer withinsdata
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 inoutput_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 specifiedoutput_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.