SpatialQuery.spatial_query.plot_gene_pair_spatial

spatial_query.plot_gene_pair_spatial(gene_pairs, gene_pair_df, ids, ct, motif, motif_ct=None, figsize=(20, 5), vmin=None, vmax=None, cmap='RdYlBu_r', save_path=None)[source]

Plot spatial expression distribution of gene pairs showing shifted expression.

For each gene pair, generates 4 panels showing: 1. Center gene expression in center cells with motif 2. Motif gene expression in neighboring motif cells 3. Center gene expression in center cells without motif 4. Motif gene expression in non-motif neighbors

Parameters:
  • gene_pairs (List[tuple]) – List of gene pairs to plot, e.g., [(‘gene1’, ‘gene2’), (‘gene3’, ‘gene4’)]. First gene in the pair is the center gene, second is the motif gene.

  • gene_pair_df (pd.DataFrame) – DataFrame containing gene pair correlation results with columns: ‘gene_center’, ‘gene_motif’, ‘combined_score’. This is typically the output from compute_gene_gene_correlation.

  • ids (dict) – Dictionary containing cell pairing information from compute_gene_gene_correlation: - ‘center_neighbor_motif_pair’: array of [center_idx, neighbor_idx] pairs - ‘non_motif_center_neighbor_pair’: array of [center_idx, neighbor_idx] pairs

  • ct (str) – Center cell type name.

  • motif (List[str]) – List of cell types in the motif.

  • motif_ct (str, optional) – Specific motif cell type to filter for plotting. If None, all motif cell types are used (suitable for compute_gene_gene_correlation results where motif types are pooled together).

  • figsize (tuple, default=(20, 5)) – Figure size for each gene pair plot (width, height).

  • vmin (float, optional) – Minimum value for color normalization. If None, automatically computed as -max(abs(shifted_expression)) to ensure symmetric colormap.

  • vmax (float, optional) – Maximum value for color normalization. If None, automatically computed as max(abs(shifted_expression)) to ensure symmetric colormap.

  • cmap (str, default='RdYlBu_r') – Colormap name.

  • save_path (str, optional) – Directory path to save figures. If None, figures are displayed but not saved. Each gene pair will be saved as ‘{save_path}/{gene1}_{gene2}_spatial.pdf’.

Returns:

Displays and optionally saves spatial expression plots for each gene pair.

Return type:

None

Example

>>> gene_pair_df, ids = sq.compute_gene_gene_correlation(
...     ct='Cardiomyocyte',
...     motif=['Fibroblast', 'Endothelial'],
...     max_dist=20
... )
>>> sq.plot_gene_pair_spatial(
...     gene_pairs=[('Ttn', 'Myh6'), ('Actn2', 'Tnni3')],
...     gene_pair_df=gene_pair_df,
...     ids=ids,
...     ct='Cardiomyocyte',
...     motif=['Fibroblast', 'Endothelial'],
...     motif_ct='Fibroblast',
...     save_path='./figures/'
... )