harpy.tb.cluster_intensity_SOM

harpy.tb.cluster_intensity_SOM#

harpy.tb.cluster_intensity_SOM(sdata, mapping, image_name, labels_name, output_table_name, to_coordinate_system='global', channels=None, chunks=10000, instance_key='SOM_cluster_ID', instance_size_key='SOM_cluster_size', index_name='SOM_cluster_ID_index', overwrite=False)#

Calculates average intensity of each channel in image_name per SOM cluster as available in the labels_name, and saves it as a table element in sdata as output_table_name. Average intensity per metacluster is calculated using the mapping.

This function computes average intensity for each SOM cluster identified in the labels_name and stores the results in a new table element (output_table_name). Average intensity per metacluster is added to sdata.tables[output_table_name].uns. The intensity calculation can be subset by channels and adjusted for chunk size for efficient processing. SOM clusters can be calculated using harpy.im.flowsom.

Parameters:
  • sdata (SpatialData) – The input SpatialData object.

  • mapping (Series) – A pandas Series mapping SOM cluster IDs (index) to metacluster IDs (values).

  • image_name (str | Iterable[str]) – The image element of sdata from which the intensity is calculated.

  • labels_name (str | Iterable[str]) – The labels element in sdata that contains the SOM cluster IDs. I.e. the output_cluster_labels_name labels element obtained through harpy.im.flowsom.

  • output_table_name (str) – The output table element in sdata where results are stored.

  • to_coordinate_system (str | Iterable[str] (default: 'global')) – The coordinate system that holds image_name and labels_name. If image_name and labels_name are provided as a list, elements in to_coordinate_system are the respective coordinate systems that holds the elements in image_name and labels_name.

  • channels (int | str | Iterable[int] | Iterable[str] | None (default: None)) – Specifies the channels to be included in the intensity calculation.

  • chunks (str | int | tuple[int, ...] | None (default: 10000)) – Chunk sizes for processing. If provided as a tuple, it should contain chunk sizes for c, (z), y, x.

  • instance_key (str (default: 'SOM_cluster_ID')) – Instance key. The name of the column in AnnData table .obs that will hold the instance ids (SOM cluster IDs).

  • instance_size_key (str (default: 'SOM_cluster_size')) – The key in the AnnData table .obs that will hold the size of the instances.

  • index_name (str (default: 'SOM_cluster_ID_index')) – The name of the index of the resulting AnnData table.

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

Return type:

SpatialData

Returns:

: The input sdata with the new table element added.

Raises:
  • AssertionError – If number of provided image_name, labels_name and to_coordinate_system is not equal.

  • AssertionError – If some labels in labels_name are not found in the provided mapping pandas Series.

See also

harpy.im.flowsom

flowsom pixel clustering.