harpy.tb.cluster_intensity#
- harpy.tb.cluster_intensity(sdata, table_name, labels_name, output_table_name, cluster_key, cluster_key_uns=None, layer_mean_intensities=None, instance_size_key='shapeSize', overwrite=False)#
Calculates weighted (by instance size) average intensity per cluster.
Calculates weighted average intensity for each cluster, and stores the result in
sdata.tables[output_table_name].uns[cluster_key_uns]. The intensities insdata.tables[table_name].Xorsdata.tables[table_name].layers[layer_mean_intensities]should contain the mean (by instance size) intensities for each label inlabels_name.- Parameters:
sdata (
SpatialData) – SpatialData object.table_name (
str) – The table element containing the mean intensities per instance in ‘sdata.tables[table_name].X’ or ‘sdata.tables[table_name].layers[layer_mean_intensities]’ iflayer_mean_intensitiesis notNone; and thecluster_keyinsdata.tables[table_name].obs. Mean intensities can be calculated usingharpy.tb.allocate_intensity(..., mode="mean",...). See docstring ofharpy.pl.cluster_intensity_heatmapfor an example.labels_name (
str|Iterable[str]) – The labels element(s) ofsdataused to select the instances via theregion_keyinsdata.tables[table_name].obs. Note that ifoutput_table_nameis equal totable_nameandoverwriteisTrue, instances insdata.tables[table_name]linked to otherlabels_name(via theregion_key), will be removed fromsdata.tables[table_name]. If a list of labels elements is provided, intensities per cluster will be calculated over all labels elements, which is usefull in the multi-sample scenario.layer_mean_intensities (
str|None(default:None)) – Layer ofsdata.tables[table_name]holding the mean intensities per instance. If not specified, it is assumed ‘sdata.tables[table_name].X’ holds the mean intensity values per instance.output_table_name (
str) – The output table element insdatawhere results are stored.cluster_key (
str) – The cluster key insdata.tables[table_name].obs.cluster_key_uns (
str|None(default:None)) – The key insdata.tables[table_name].unswhere the weighted mean intensities per cluster will be stored. If not providedcluster_key_unsis set to{cluster_key}_weighted_intensity.instance_size_key (
str(default:'shapeSize')) – The key insdata.tables[table_name].obsthat holds instance size. Instance sizes will be calculated fromlabels_nameif not found in.obs.overwrite (
bool(default:False)) – IfTrue, overwrites theoutput_table_nameif it already exists insdata.
- Return type:
- Returns:
: SpatialData object with
output_table_namecontaining weighted mean intensity per cluster at.uns[cluster_key_uns].
Examples
See docstring of
harpy.pl.cluster_intensity_heatmapfor an example.See also
harpy.tb.allocate_intensitycalculates total intensity per instance per channel.
harpy.tb.preprocess_proteomicscalculates instance size and normalizes intensity by instance size.
harpy.pl.cluster_intensity_heatmapplot heatmap of mean intensity per cluster.