SpatialQuery.spatial_query.motif_enrichment_knn

spatial_query.motif_enrichment_knn(ct, motifs=None, k=30, min_support=0.5, max_dist=20, return_cellID=False)[source]

Perform motif enrichment analysis using k-nearest neighbors (KNN).

Parameters:
  • ct (str) – The cell type of the center cell.

  • motifs (str or List[str] or List[List[str]], optional) – Specified motifs to be tested. If motifs=None, find the frequent patterns as motifs within the neighborhood of center cell type.

  • k (int, default=30) – Number of nearest neighbors to consider.

  • min_support (float, default=0.5) – Threshold of frequency to consider a pattern as a frequent pattern.

  • max_dist (float, default=20) – Maximum distance for neighbors.

  • return_cellID (bool, default=False) – Indicate whether return cell IDs for each frequent pattern within the neighborhood of grid points. By defaults do not return cell ID.

Returns:

DataFrame with motif enrichment results. Columns include:
  • center: center cell type name

  • motifs: list of cell types in the motif

  • n_center_motif: number of center cells with motif in neighborhood

  • n_center: total number of center cells

  • n_motif: total number of cells with motif in neighborhood (across all cell types)

  • expectation: expected number under hypergeometric distribution

  • p-values: p-value from hypergeometric test

  • if_significant: whether the enrichment is significant (p < 0.05)

  • adj-pval: FDR-corrected p-values (only when multiple motifs tested)

  • neighbor_id: array of unique neighbor cell indices with motif types (only if return_cellID=True)

  • center_id: array of center cell indices with motif in neighborhood (only if return_cellID=True)

Return type:

pd.DataFrame