Compute interaction matrix¶
This example shows how to compute the interaction matrix.
The interaction matrix quantifies the number of edges that nodes belonging to a given annotation shares with the other annotations. It’s a descriptive statistics of the spatial graph.
import squidpy as sq adata = sq.datasets.imc() adata
AnnData object with n_obs × n_vars = 4668 × 34 obs: 'cell type' uns: 'cell type_colors' obsm: 'spatial'
First, we need to compute a connectivity matrix from spatial coordinates. We can use
squidpy.gr.spatial_neighbors() for this purpose.
We can compute the interaction matrix with
normalized = True
if you want a row-normalized matrix. Results can be visualized with
sq.gr.interaction_matrix(adata, cluster_key="cell type") sq.pl.interaction_matrix(adata, cluster_key="cell type")
Total running time of the script: ( 0 minutes 2.204 seconds)
Estimated memory usage: 15 MB