SpatialQuery.spatial_query_multi.differential_analysis_dist

spatial_query_multi.differential_analysis_dist(ct, datasets, motifs=None, max_dist=20, min_support=0.5, min_size=0)[source]

Perform differential analysis of spatial motif patterns between two datasets using radius-based neighborhood. Mann-Whitney U test is used to compare the support values of each motif pattern across FOVs of two datasets, and FDR correction is applied for multiple testing.

This function identifies motif patterns that are differentially enriched in the radius-based neighborhood of a center cell type between two conditions (e.g., disease vs control). It supports two modes:

  • Unbiased discovery (motifs=None): Automatically discovers frequent patterns in each FOV of both datasets, then tests for differential enrichment.

  • Hypothesis-driven (motifs specified): Tests user-specified motifs for differential enrichment, allowing validation of known or hypothesized spatial patterns.

Parameters:
  • ct (str) – Cell type of interest as center point.

  • datasets (List[str]) – List of exactly 2 dataset names to compare (e.g., [‘Disease’, ‘Control’]).

  • motifs (str or List[str] or List[List[str]], optional) –

    Optional user-specified motif(s) to test. Can be: - Single cell type: ‘CellTypeA’ - Single motif: [‘CellTypeA’, ‘CellTypeB’] - Multiple motifs: [[‘CellTypeA’], [‘CellTypeB’, ‘CellTypeC’]]

    If None, performs unbiased discovery of frequent patterns first.

  • max_dist (float, default=20) – Maximum distance for considering a cell as a neighbor.

  • min_support (float, default=0.5) – Threshold of frequency to consider a pattern as frequent (only used when motifs=None for unbiased discovery mode).

  • min_size (int, default=0) – Minimum neighborhood size for each center cell to be considered.

Returns:

Dictionary with dataset names as keys and DataFrames as values. Each DataFrame contains motif patterns significantly enriched in that dataset, with columns: itemsets (motif as tuple), support_{datasets[0]}_mean, support_{datasets[1]}_mean, adj-pval. Only patterns with adj-pval < 0.05 are included.

Return type:

dict