SpatialQuery.spatial_query_multi.compute_gene_gene_correlation
- spatial_query_multi.compute_gene_gene_correlation(ct, motif, dataset=None, genes=None, max_dist=None, k=None, min_size=0, min_nonzero=10, alpha=None)[source]
Compute gene-gene co-varying patterns between motif and center cells across multiple FOVs.
Similar to compute_gene_gene_correlation in single FOV, but: - Aggregates center-neighbor pairs across all FOVs in specified dataset - Uses FOV-specific cell type means for centering (NOT global means) - Computes correlations by accumulating statistics across FOVs
This function calculates cross correlation between gene expression in motif cells that are neighbors of the center type, motif cells that are not neighbors, and neighboring cells without nearby motif. Aggregation is performed across all FOVs in the specified dataset.
- Parameters:
ct (str) – Cell type as the center cells.
motif (str or List[str]) – Motif (names of cell types) to be analyzed.
dataset (str or List[str], optional) – Datasets to include in analysis. If None, use all datasets.
genes (str or List[str], optional) – List of genes to analyze. If None, uses intersection of genes across all FOVs.
max_dist (float, optional) – Maximum distance for considering a cell as a neighbor. Use either max_dist or k.
k (int, optional) – Number of nearest neighbors. Use either max_dist or k.
min_size (int, default=0) – Minimum neighborhood size for each center cell (only used when max_dist is specified).
min_nonzero (int, default=10) – Minimum number of non-zero expression values required for a gene to be included.
alpha (float, optional) – Significance threshold.
- Returns:
results_df – DataFrame with correlation results. Columns: gene_center, gene_motif, corr_neighbor, corr_non_neighbor, corr_center_no_motif, p_value_test1, p_value_test2, delta_corr_test1, delta_corr_test2, combined_score, adj-pval-test1, adj-pval-test2.
- Return type:
pd.DataFrame