SpatialQuery.spatial_query_multi.motif_enrichment_knn
- spatial_query_multi.motif_enrichment_knn(ct, motifs=None, dataset=None, k=30, min_support=0.5, max_dist=20, return_cellID=False)[source]
Perform motif enrichment analysis using k-nearest neighbors (KNN) in multiple fields of view.
- 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 in each fov.
dataset (str or List[str], optional) – Datasets for searching for frequent patterns and performing enrichment analysis. Use all datasets if dataset=None.
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 center cell type and center cells. By defaults do not return cell ID.
- Returns:
- If return_cellID is False:
- pd.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
expectation: expected number under hypergeometric distribution
p-values: p-value from hypergeometric test
adj-pval: FDR-corrected p-values (when multiple motifs tested)
if_significant: whether the enrichment is significant
- If return_cellID is True:
- Tuple containing:
pd.DataFrame: enrichment results as described above
Dict: cell IDs of motifs in center cell’s neighborhood Format: {‘motif_str’: {‘dataset_name’: [cell_ids]}}
Dict: cell IDs of center cells with motif in neighborhood Format: {‘motif_str’: {‘dataset_name’: [cell_ids]}}
- Return type:
Union[pd.DataFrame, Tuple[pd.DataFrame, Dict, Dict]]