sparrow.tb.filter_on_size

Contents

sparrow.tb.filter_on_size#

sparrow.tb.filter_on_size(sdata, labels_layer, table_layer, output_layer, min_size=100, max_size=100000, update_shapes_layers=True, cellsize_key='shapeSize', overwrite=False)#

Returns the updated SpatialData object.

All cells with a size outside of the min and max size range are removed using the cellsize_key in .obs. Run e.g. sp.tb.preprocess_transcriptomics or sp.tb.preprocess_proteomics to obtain cell sizes.

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

  • 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] (also from the backing zarr store if it is backed).

  • table_layer (str) – The table layer in sdata.

  • output_layer (str) – The output table layer in sdata.

  • min_size (int (default: 100)) – minimum size in pixels.

  • max_size (int (default: 100000)) – maximum size in pixels.

  • update_shapes_layers (bool (default: True)) – Whether to filter the shapes layers associated with labels_layer. If set to True, cells that do not appear in resulting output_layer (with _REGION_KEY equal to labels_layer) will be removed from the shapes layers (via _INSTANCE_KEY) in the sdata object. Filtered shapes will be added to sdata with prefix ‘filtered_size’.

  • cellsize_key (default: 'shapeSize') – Column in sdata.tables[table_layer].obs containing cell sizes.

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

Return type:

SpatialData

Returns:

: The updated SpatialData object.