troutpy.tl.cell_contacts_with_urna_sources

troutpy.tl.cell_contacts_with_urna_sources#

troutpy.tl.cell_contacts_with_urna_sources(sdata, spatial_key='spatial', cell_type_key='cell type', distance=50, copy=False, uns_prefix='cell_contact')#

Compute cell-type x cell-type contact-count matrices based on spatial and uRNA-mediated neighborhoods.

Three matrices are computed: "cell_body" (cells within distance of each other), "combined" (cell-body neighbors plus cells connected via an extracellular transcript whose source cell is not already a spatial neighbor of its target cell), and "urna_specific" (combined minus cell_body). They are stored in sdata["table"].uns under f"{uns_prefix}_cell_body", f"{uns_prefix}_combined", and f"{uns_prefix}_urna_specific".

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object containing sdata["table"] (AnnData with cell type annotations and spatial coordinates), sdata["target_score"] (AnnData with closest_cell and distance in .obs), and sdata["source_score"] (AnnData with closest_cell in .obs).

  • spatial_key (str, optional) – Key in sdata["table"].obsm containing spatial coordinates. Defaults to "spatial".

  • cell_type_key (str, optional) – Column in sdata["table"].obs with cell type labels. Defaults to "cell type".

  • distance (float, optional) – Radius used to define spatial neighborhoods. Defaults to 50.

  • copy (bool, optional) – If True, return the matrices. Otherwise modify sdata in place and return None. Defaults to False.

  • uns_prefix (str, optional) – Prefix for the keys under which matrices are saved in sdata["table"].uns. Defaults to "cell_contact".

Returns:

dict of pandas.DataFrame or None Dictionary with "cell_body", "combined", and "urna_specific" contact-count DataFrames (cell types x cell types) if copy=True; otherwise None.