sparrow.tb.cluster_cleanliness

sparrow.tb.cluster_cleanliness#

sparrow.tb.cluster_cleanliness(sdata, labels_layer, table_layer, output_layer, celltypes, celltype_indexes=None, colors=None, celltype_column='annotation', overwrite=False)#

Re-calculates annotations, potentially following corrections to the list of celltypes, or after a manual update of the assigned scores per cell type via e.g. correct_marker_genes.

Celltypes can also be grouped together via the celltype_indexes parameter. Returns a SpatialData object alongside a dictionary mapping cell types to colors.

Parameters:
  • sdata (SpatialData) – Data containing spatial information.

  • labels_layer (list[str]) – The labels layer(s) of sdata used to select the cells via the _REGION_KEY in sdata.tables[table_layer].obs. Note that if output_layer is equal to table_layer and overwrite is True, cells in sdata.tables[table_layer] linked to other labels_layer (via the _REGION_KEY), will be removed from sdata.tables[table_layer]. If a list of labels layers is provided, they will therefore be scored together (e.g. multiple samples).

  • table_layer (str) – The table layer in sdata on which to perform cleaning on.

  • output_layer (str) – The output table layer in sdata to which table layer with results of cleaned annotations will be written.

  • celltypes (list[str]) – List of celltypes that you want to use for annotation, can be a subset of what is available in .obs of corresponding table.

  • celltype_indexes (Optional[dict[str, int]] (default: None)) – Dictionary with cell type as keys and indexes as values. Cell types with provided indexes will be grouped together under new cell type provided as key. E.g.: celltype_indexes = {“fibroblast”: [4,5,23,25], “stellate”: [28,29,30]} -> celltypes at index 4,5,23 and 25 in provided list of celltypes (after an alphabetic sort) will be grouped together as “fibroblast”.

  • colors (Optional[list[str]] (default: None)) – List of colors to be used for visualizing different cell types. If not provided, a default colormap will be generated.

  • celltype_column (str (default: 'annotation')) – The column name in the SpatialData object’s table that specifies the cell type annotations. The default value is _ANNOTATION_KEY.

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

Return type:

tuple[SpatialData, dict | None]

Returns:

: tuple:

  • Updated spatial data after the cleanliness analysis.

  • Dictionary with cell types as keys and their corresponding colors as values.