troutpy.tl.calculate_target_cells

troutpy.tl.calculate_target_cells#

troutpy.tl.calculate_target_cells(sdata, layer='transcripts', xcoord='x', ycoord='y', xcellcoord='x_centroid', ycellcoord='y_centroid', celltype_key='cell type', gene_id_key='gene', copy=False)#

Identifies the nearest cell to each transcript based on spatial coordinates and annotates the transcript data with the ID, cell type, and distance to the closest cell.

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object containing spatial and transcript data.

  • layer (str) – The layer in sdata.points containing transcript data. Default is ‘transcripts’.

  • xcoord (str) – Column name for the x-coordinate of transcripts. Default is ‘x’.

  • ycoord (str) – Column name for the y-coordinate of transcripts. Default is ‘y’.

  • xcellcoord (str) – Column name for the x-coordinate of cell centroids. Default is ‘x_centroid’.

  • ycellcoord (str) – Column name for the y-coordinate of cell centroids. Default is ‘y_centroid’.

  • celltype_key (str) – Column name in adata.obs that contains cell type annotations. Default is ‘cell type’.

  • gene_id_key (str) – Column name in sdata.points[layer] that contains gene identity. Default is ‘gene’.

  • copy (bool) – If True, returns a copy of the modified SpatialData object. Default is False.

Return type:

SpatialData | None

Returns:

Optional (SpatialData) Modified SpatialData object with updated transcript annotations if copy=True.Otherwise, updates are made in place, and None is returned.