harpy.tb.add_table

Contents

harpy.tb.add_table#

harpy.tb.add_table(sdata, adata, output_table_name, region, instance_key='cell_ID', region_key='fov_labels', overwrite=False)#

Add an AnnData object as a table element to a SpatialData object.

This function stores the provided AnnData object in sdata.tables[output_table_name]. When region is provided, the table is parsed as a SpatialData table and linked to one or more spatial elements via region_key and instance_key. If region is None, the AnnData object is added as a regular table without region annotations.

If sdata is backed by a zarr store, the resulting table element is also written to that store.

Parameters:
  • sdata (SpatialData) – The SpatialData object to which the new table element will be added.

  • adata (AnnData) – The AnnData object to add. If region is not None, adata.obs must contain the columns specified by region_key and instance_key.

  • output_table_name (str) – Name of the output table element in sdata.tables.

  • region (list[str] | None) – Regions annotated by the table. Typically this is the list of unique values in adata.obs[region_key]. Set to None if the table should not annotate any spatial element.

  • instance_key (str (default: 'cell_ID')) – Name of the column in adata.obs that stores instance ids. Ignored if region is None.

  • region_key (str (default: 'fov_labels')) – Name of the column in adata.obs that stores the region labels annotated by the table. Ignored if region is None.

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

Return type:

SpatialData

Returns:

: The updated SpatialData object.