sparrow.tb.allocate

Contents

sparrow.tb.allocate#

sparrow.tb.allocate(sdata, labels_layer, points_layer='transcripts', output_layer='table_transcriptomics', to_coordinate_system='global', chunks=10000, name_gene_column='gene', append=False, update_shapes_layers=True, overwrite=False)#

Allocates transcripts to cells via provided labels_layer and points_layer and returns updated SpatialData object with a table layer (sdata.tables[output_layer]) holding the AnnData object with cell counts.

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

  • labels_layer (str) – The labels layer (i.e. segmentation mask) in sdata to be used to allocate the transcripts to cells.

  • points_layer (str (default: 'transcripts')) – The points layer in sdata that contains the transcripts.

  • output_layer (str (default: 'table_transcriptomics')) – The table layer in sdata in which to save the AnnData object with the transcripts counts per cell.

  • to_coordinate_system (str (default: 'global')) – The coordinate system that holds labels_layer and points_layer.

  • chunks (str | tuple[int, ...] | int | None (default: 10000)) – Chunk sizes for processing. Can be a string, integer or tuple of integers. Consider setting the chunks to a relatively high value to speed up processing (>10000, or only chunk in z-dimension if data is 3D, and one z-slice fits in memory), taking into account the available memory of your system.

  • name_gene_column (str (default: 'gene')) – Column name in the points_layer representing gene information.

  • append (bool (default: False)) – If set to True, and the labels_layer does not yet exist as a _REGION_KEY in sdata.tables[output_layer].obs, the transcripts counts obtained during the current function call will be appended (along axis=0) to any existing transcript count values. within the SpatialData object’s table attribute. If False, and overwrite is set to True any existing data in sdata.tables[output_layer] will be overwritten by the newly extracted transcripts counts.

  • 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_segmentation’.

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

Return type:

SpatialData

Returns:

: An updated SpatialData object with an AnnData table added to sdata.tables at slot output_layer.