SpatialQuery.spatial_query.compute_gene_gene_correlation

spatial_query.compute_gene_gene_correlation(ct, motif, genes=None, max_dist=None, k=None, min_size=0, min_nonzero=10, alpha=None)[source]

Compute gene-gene cross correlation between anchor and neighboring motif cells. Only considers inter-cell-type interactions. After finding neighbors using the full motif, removes all cells of the center cell type from both neighbor and non-neighbor groups. For Pearson correlation, uses shifted correlation (subtract cell type mean) to enable comparison across different niches/motifs.

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. Center type cells are excluded from neighbor groups in all cases.

Parameters:
  • ct (str) – Cell type as the center cells.

  • motif (str or List[str]) – Motif (names of cell types) to be analyzed. Include all cell types for neighbor finding.

  • genes (str or List[str], optional) – List of genes to analyze. If None, all genes will be used.

  • 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.

Return type:

Tuple[DataFrame, dict]

Returns:

  • results_df (pd.DataFrame) – DataFrame with correlation results. Columns: gene_center, gene_motif, corr_neighbor, corr_non_neighbor, p_value_test1, delta_corr_test1, corr_center_no_motif, p_value_test2, delta_corr_test2, q_value_test1, q_value_test2, reject_test1_fdr, reject_test2_fdr, combined_score, abs_combined_score, if_significant.

  • cell_groups (dict) – Cell pairing info. Keys: ‘center_neighbor_motif_pair’ (array of [center, neighbor] index pairs), ‘non-neighbor_motif_cells’ (distant motif cell indices), ‘non_motif_center_neighbor_pair’ (pairs for centers without motif).