sparrow.tb.weighted_channel_expression#
- sparrow.tb.weighted_channel_expression(sdata, table_layer_cell_clustering, table_layer_pixel_cluster_intensity, output_layer, clustering_key=ClusteringKey._METACLUSTERING_KEY, overwrite=False)#
Calculation of weighted channel expression in the context of cell clustering.
Calculates the average channel expression (via
table_layer_pixel_cluster_intensity
) for each cell weighted by pixel SOM/META cluster count (viatable_layer_cell_clustering
). Values are normalized by the size of the cell.Average marker expression for each cell weighted by pixel cluster count is added to
sdata.tables[output_layer].obs
. Mean over the obtained cell clusters (both SOM and meta clusters) of the average marker expression for each cell weighted by pixel cluster count is added tosdata.tables[output_layer].uns
.This function should be run after running
sp.tb.flowsom
andsp.tb.cluster_intensity
.- Parameters:
sdata (
SpatialData
) – The input SpatialData object containing the necessary data tables.table_layer_cell_clustering (
str
) – The name of the table layer insdata
where FlowSOM cell clustering results are stored (obtained via ‘sp.tb.flowsom’). This layer should contain the cell cluster labels derived from the FlowSOM clustering algorithm and the non-normalized pixel cluster counts in.layers[ _RAW_COUNTS_KEY ]
, as obtained after runningsp.tb.flowsom
.table_layer_pixel_cluster_intensity (
str
) – The name of the table layer insdata
containing pixel cluster intensity values as obtained by runningsp.tb.cluster_intensity
. These intensities are used to calculate the weighted expression of each channel for the cell clusters.output_layer (
str
) – The name of the output table layer insdata
where the results of the weighted channel expression computation will be stored.clustering_key (
ClusteringKey
(default:<ClusteringKey._METACLUSTERING_KEY: 'metaclustering'>
)) – Specifies the key that was used for pixel clustering, indicating whether metaclustering or SOM clustering labels were used as input for flowsom cell clustering (sp.tb.flowsom
).overwrite (
bool
(default:False
)) – If True, overwrites any existing data in theoutput_layer
if it already exists.
- Return type:
SpatialData
- Returns:
: The updated
sdata
object with the results of the weighted channel expression added to the specifiedoutput_layer
.
See also
sparrow.tb.flowsom
flowsom cell clustering
sparrow.tb.cluster_intensity
calculates average intensity SOM/meta cluster (pixel clusters).