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)#
Find the nearest cell to each transcript and annotate it with that cell’s ID, type, and distance.
- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object containing spatial and transcript data.
layer (str, optional) – The layer in
sdata.pointscontaining transcript data. Defaults to"transcripts".xcoord (str, optional) – Column name for the x-coordinate of transcripts. Defaults to
"x".ycoord (str, optional) – Column name for the y-coordinate of transcripts. Defaults to
"y".xcellcoord (str, optional) – Column name for the x-coordinate of cell centroids. Defaults to
"x_centroid".ycellcoord (str, optional) – Column name for the y-coordinate of cell centroids. Defaults to
"y_centroid".celltype_key (str, optional) – Column name in
adata.obsthat contains cell type annotations. Defaults to"cell type".gene_id_key (str, optional) – Column name in
sdata.points[layer]that contains gene identity. Defaults to"gene".copy (bool, optional) – If
True, returns a copy of the modified SpatialData object. Defaults toFalse.
- Return type:
- Returns:
spatialdata.SpatialData or None Modified SpatialData object with updated transcript annotations if
copy=True; otherwise updates are made in place andNoneis returned.