troutpy.tl.in_out_correlation

troutpy.tl.in_out_correlation#

troutpy.tl.in_out_correlation(sdata, extracellular_layer='segmentation_free_table', cellular_layer='table', n_neighbors=5, copy=None)#

Compute the correlation between intracellular and extracellular gene expression.

For each cell, extracellular expression is aggregated as the mean over its n_neighbors nearest extracellular bins, then correlated (Spearman) against the cell’s intracellular expression for each shared gene. Results are stored in sdata["xrna_metadata"].var["in_out_spearmanR"] and sdata["xrna_metadata"].var["in_out_pvalue"].

Parameters:
  • sdata (SpatialData) – SpatialData object containing both the extracellular and cellular AnnData tables.

  • extracellular_layer (str (default: 'segmentation_free_table')) – Key of the extracellular AnnData table in sdata.

  • cellular_layer (str (default: 'table')) – Key of the cellular AnnData table in sdata.

  • n_neighbors (int (default: 5)) – Number of nearest extracellular bins to aggregate per cell.

  • copy (Optional[bool] (default: None)) – If True, return a modified copy of sdata. Otherwise modify in place.

Return type:

SpatialData | None

Returns:

If copy=True, a modified copy of sdata. Otherwise None, modifying sdata in place.