harpy.tb.filter_on_size

Contents

harpy.tb.filter_on_size#

harpy.tb.filter_on_size(sdata, labels_name, table_name, output_table_name, min_size=100, max_size=100000, update_shapes_elements=True, instance_size_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 instance_size_key in .obs. Run e.g. preprocess_transcriptomics() or preprocess_proteomics() to obtain cell sizes.

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

  • labels_name (list[str]) – The labels element(s) of sdata used to select the cells 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, cells in sdata.tables[table_name] linked to other labels_name (via the region key), will be removed from sdata.tables[table_name] (also from the backing zarr store if it is backed).

  • table_name (str) – The table element in sdata.

  • output_table_name (str) – The output table element in sdata.

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

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

  • update_shapes_elements (bool (default: True)) – Whether to filter the shapes elements associated with labels_name. If set to True, cells that do not appear in resulting output_table_name (with region key equal to labels_name) will be removed from the shapes elements (via instance key) in the sdata object. Filtered shapes will be added to sdata with prefix ‘filtered_size’. This parameter is deprecated, and will be removed in a future version.

  • instance_size_key (str (default: 'shapeSize')) – Column in sdata.tables[table_name].obs containing instance sizes.

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

Return type:

SpatialData

Returns:

: The updated SpatialData object.