harpy.tb.allocate#
- harpy.tb.allocate(sdata, labels_name, points_name='transcripts', output_table_name='table_transcriptomics', to_coordinate_system='global', chunks=None, name_gene_column='gene', append=False, update_shapes_elements=False, region_key='fov_labels', instance_key='cell_ID', spatial_key='spatial', cell_index_name='cells', overwrite=False)#
Allocates transcripts to instances via provided
labels_nameandpoints_nameand returns updated SpatialData object with a table element (sdata.tables[output_table_name]) holding theanndata.AnnDataobject with transcript counts.It requires that
labels_nameandpoints_nameare registered. Relation betweento_coordinate_systemandpoints_nameshould be aspatialdata.transformations.Identitytransformation. Relation betweento_coordinate_systemandlabels_namecan be aspatialdata.transformations.Identity,spatialdata.transformations.Translation, or aspatialdata.transformation.Sequenceof translations.- Parameters:
sdata (
SpatialData) – The SpatialData object.labels_name (
str) – The labels element (i.e. segmentation mask) insdatato be used to allocate the transcripts to cells.points_name (
str(default:'transcripts')) – The points element insdatathat contains the transcripts.output_table_name (
str(default:'table_transcriptomics')) – The table element insdatain which to save the AnnData object with the transcripts counts per cell.to_coordinate_system (
str(default:'global')) – The coordinate system that holdslabels_nameandpoints_name. This should be the intrinsic coordinate system in pixels.chunks (
str|tuple[int,...] |int|None(default:None)) – Chunk size for processing. Consider setting ‘chunks’ to ‘None’ and rechunk the ‘labels_name’ to the desired chunk size on disk, e.g. withharpy.im.add_labels().name_gene_column (
str(default:'gene')) – Column name in thepoints_namerepresenting gene information.append (
bool(default:False)) – If set to True, and thelabels_namedoes not yet exist as aregion_keyinsdata.tables[output_table_name].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 insdata.tables[output_table_name]will be overwritten by the newly extracted transcripts counts.update_shapes_elements (
bool(default:False)) – Whether to filter the shapes elements associated withlabels_name. If set toTrue, cells that do not appear in resultingoutput_table_name(withregion_keyequal tolabels_name) will be removed from the shapes elements (viainstance_key) in thesdataobject. Filtered shapes will be added tosdatawith prefix ‘filtered_segmentation’. This parameter is deprecated, and will be removed in a future version.instance_key (
str(default:'cell_ID')) – Instance key. The name of the column inAnnDatatable.obsthat will hold the instance ids.region_key (
str(default:'fov_labels')) – Region key. The name of the column inAnnDatatable.obsthat will hold the name of the element(s) that are annotated by the resulting table.spatial_key (
str(default:'spatial')) – The key in theAnnDatatable.obsmthat will hold thexandycenter of the instances. This center is calculated by taking the average x,y coordinate of the transcripts found inside the cell.cell_index_name (
str(default:'cells')) – The name of the index of the resultingAnnDatatable.overwrite (
bool(default:False)) – If True, overwrites theoutput_table_nameif it already exists insdata.
- Return type:
- Returns:
: An updated SpatialData object with an AnnData table added to
sdata.tablesat slotoutput_table_name.
Example
sdata = hp.datasets.resolve_example_multiple_coordinate_systems() # Create an AnnData table with transcript count per cell with name 'my_table' sdata = hp.tb.allocate( sdata, labels_name="labels_a1_1", points_name="points_a1_1", output_table_name="my_table", to_coordinate_system="a1_1", overwrite=True, ) # Append transcript count per cell from different sample to 'my_table' sdata = hp.tb.allocate( sdata, labels_name="labels_a1_2", points_name="points_a1_2", output_table_name="my_table", to_coordinate_system="a1_2", append=True, overwrite=True, )