Skip to content

spatialProximityScore

spatialProximityScore

spatialProximityScore(
    data,
    label="spatial_pscore",
    plotScore="both",
    orderXAxis=None,
    color="grey",
    figsize=None,
    fileName="spatial_pscore.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Proximity volume and density scores, as a bar chart.

Reads the summary table that sp.tl.spatialProximityScore writes to uns[label] — one row per image, with a proximity volume (what fraction of all cells are in the interaction zone) and a proximity density (how enriched that zone is for the pair of interest).

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
label str

Key in uns holding the proximity summary.

'spatial_pscore'
plotScore str

'both', or the name of a single score column to plot. Accepted for signature compatibility; the current implementation plots every column of the summary table.

'both'
orderXAxis list

Explicit row order.

None
color str

Bar colour.

'grey'
figsize tuple

Figure size in inches. Scaled from the number of rows when None.

None
fileName str

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

'spatial_pscore.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 summary table with returnData=True; (fig, ax) with returnFig=True.

Example
adata = sp.tl.spatialProximityScore(adata, proximity=["Treg", "ECAD+"])
sp.pl.spatialProximityScore(adata)