troutpy.tl.compare_intra_extra_distribution

troutpy.tl.compare_intra_extra_distribution#

troutpy.tl.compare_intra_extra_distribution(sdata, layer='transcripts', gene_key='gene', copy=False, coord_keys=None, n_bins=30)#

Compare the spatial distribution of intracellular and extracellular transcripts per gene.

For each gene, computes the centroid shift between its intracellular and extracellular transcripts, and the correlation and Jensen-Shannon divergence between their spatial density histograms. Results are stored in sdata["xrna_metadata"].var.

Parameters:
  • sdata (SpatialData) – SpatialData object containing transcript locations and metadata.

  • layer (str (default: 'transcripts')) – Key of the points element in sdata containing the transcripts.

  • gene_key (str (default: 'gene')) – Column in sdata[layer] containing gene identifiers.

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

  • coord_keys (Optional[list[str]] (default: None)) – Column names for the x and y transcript coordinates. Defaults to ["x", "y"].

  • n_bins (int (default: 30)) – Number of bins per axis for the 2D spatial density histograms.

Return type:

SpatialData | None

Returns:

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

Notes

Genes with fewer than 5 intracellular or 5 extracellular transcripts are skipped.