troutpy.tl.assess_diffusion

troutpy.tl.assess_diffusion#

troutpy.tl.assess_diffusion(sdata, gene_key='gene', distance_key='distance_to_source', filters=None, min_transcripts=15, copy=False)#

Fit a 2D Rayleigh diffusion model to transcript distances from their source cell.

For each gene, fits a Rayleigh distribution to the distances of its transcripts from their assigned source cell (sdata["source_score"].obs[distance_key]) and evaluates the fit against the empirical distribution. Results are stored as new columns in sdata["xrna_metadata"].var.

Parameters:
  • sdata (SpatialData) – SpatialData object with "source_score" and "transcripts" tables.

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

  • distance_key (str (default: 'distance_to_source')) – Column in sdata["source_score"].obs containing the distance of each transcript from its source cell.

  • filters (Optional[dict] (default: None)) – Optional filters applied to sdata["transcripts"] before matching against source_score. Each entry maps a column name to either a value to match, or a (value, False) tuple to exclude transcripts equal to that value, e.g. {"extracellular": True, "enrichment_class": ("High Density", False)}.

  • min_transcripts (int (default: 15)) – Minimum number of transcripts required for a gene to be fitted.

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

Returns:

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

Notes

Adds the columns ks_stat, ks_pval, lr_stat, mean_displacement, n_transcripts, sigma_est and -log_ks_pval to sdata["xrna_metadata"].var for genes that pass min_transcripts.