Skip to content

spatialInteractionNetwork

spatialInteractionNetwork

spatialInteractionNetwork(
    data,
    spatialCooccurrence="spatialCooccurrence",
    pVal=0.05,
    cmap="vlag",
    nodeColor="#22333b",
    nodeSize=None,
    alpha=0.9,
    figsize=None,
    fontSize=12,
    fontColor="white",
    subsetPhenotype=None,
    fileName="spatialInteractionNetwork.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
)

Significant cell-type interactions as a circular node-edge network.

Cell types are laid out evenly on a circle and an edge is drawn for every pair whose co-occurrence p-value is below pVal. It answers "which cell types interact at all" faster than reading a heatmap.

Reads the same uns key as sp.pl.spatialCooccurrence, averaging across images.

Parameters:

Name Type Description Default
data (AnnData | SpatialData | str, required)

The cell table. An AnnData, a path to an .h5ad file, a SpatialData object, or a path to a .zarr SpatialData store.

required
spatialCooccurrence str

Key in uns holding the result. Falls back to 'spatial_interaction'.

'spatialCooccurrence'
pVal float

An edge is drawn when the pair's p-value is below this.

0.05
cmap str

Accepted for signature compatibility with scimap; edges are drawn black.

'vlag'
nodeColor str

Node fill colour.

'#22333b'
nodeSize float

Node marker area. Defaults to 600.

None
alpha float

Edge opacity.

0.9
figsize tuple

Figure size in inches. Defaults to (6, 6).

None
fontSize int

Node label font size.

12
fontColor str

Node label colour.

'white'
subsetPhenotype str | list

Keep only these phenotypes as nodes.

None
fileName str

File name for the saved figure. The extension decides the format.

'spatialInteractionNetwork.pdf'
outputDir str

Directory to save the figure in. When None nothing is written.

None
saveDir str

Deprecated alias for outputDir, kept for scripts carried over from scimap. outputDir wins when both are given.

None
show bool

Call plt.show() before returning. Set False in scripts and notebooks that save rather than display.

True
returnData bool

Return the DataFrame behind the plot instead of drawing it.

False
returnFig bool

Return (fig, axes). With returnData as well, returns (fig, axes, plotData).

False
dpi int

Resolution of the saved figure.

300
transparent bool

Save with a transparent background.

False
sdataTable str

Which SpatialData table to read. Ignored for AnnData input, and optional when the store has exactly one table.

None

Returns:

Name Type Description
result None | DataFrame | tuple

None by default; the p-value matrix behind the edges with returnData=True; (fig, ax) with returnFig=True.

Example
adata = sp.tl.spatialCooccurrence(adata, phenotype="phenotype", permutation=1000)
sp.pl.spatialInteractionNetwork(adata, pVal=0.01)