harpy.tb.cluster_intensity

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 in sdata.tables[table_name].X or sdata.tables[table_name].layers[layer_mean_intensities] should contain the mean (by instance size) intensities for each label in labels_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]’ if layer_mean_intensities is not None; and the cluster_key in sdata.tables[table_name].obs. Mean intensities can be calculated using harpy.tb.allocate_intensity(..., mode="mean",...). See docstring of harpy.pl.cluster_intensity_heatmap for an example.

  • labels_name (str | Iterable[str]) – The labels element(s) of sdata used to select the instances via the region_key in sdata.tables[table_name].obs. Note that if output_table_name is equal to table_name and overwrite is True, instances in sdata.tables[table_name] linked to other labels_name (via the region_key), will be removed from sdata.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 of sdata.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 in sdata where results are stored.

  • cluster_key (str) – The cluster key in sdata.tables[table_name].obs.

  • cluster_key_uns (str | None (default: None)) – The key in sdata.tables[table_name].uns where the weighted mean intensities per cluster will be stored. If not provided cluster_key_uns is set to {cluster_key}_weighted_intensity.

  • instance_size_key (str (default: 'shapeSize')) – The key in sdata.tables[table_name].obs that holds instance size. Instance sizes will be calculated from labels_name if not found in .obs.

  • overwrite (bool (default: False)) – If True, overwrites the output_table_name if it already exists in sdata.

Return type:

SpatialData

Returns:

: SpatialData object with output_table_name containing weighted mean intensity per cluster at .uns[cluster_key_uns].

Examples

See docstring of harpy.pl.cluster_intensity_heatmap for an example.

See also

harpy.tb.allocate_intensity

calculates total intensity per instance per channel.

harpy.tb.preprocess_proteomics

calculates instance size and normalizes intensity by instance size.

harpy.pl.cluster_intensity_heatmap

plot heatmap of mean intensity per cluster.