Skip to content

markerCorrelation

markerCorrelation

markerCorrelation(
    data,
    layer="log",
    subsetMarkers=None,
    orderRow=None,
    orderColumn=None,
    clusterRows=True,
    clusterColumns=True,
    cmap="vlag",
    figsize=None,
    overlayValues=False,
    fontSize=10,
    fontColor="black",
    fileName="markerCorrelation.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Marker-by-marker Pearson correlation across all cells, as a heatmap.

Highly correlated markers usually mean either real co-expression or a staining artefact worth investigating before phenotyping.

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

Which matrix to correlate. Defaults to 'log'; None uses .X, 'raw' uses .raw.X, any other string names a key in .layers.

'log'
subsetMarkers list

Restrict to these markers.

None
orderRow list

Explicit row order.

None
orderColumn list

Explicit column order.

None
clusterRows bool

Accepted for signature compatibility with scimap; the current implementation does not reorder rows. Use orderRow instead.

True
clusterColumns bool

Accepted for signature compatibility with scimap; the current implementation does not reorder columns. Use orderColumn instead.

True
cmap str

Matplotlib colormap. 'vlag' is accepted and mapped to 'coolwarm'.

'vlag'
figsize tuple

Figure size in inches. Scaled from the matrix shape when None.

None
overlayValues bool

Print the correlation coefficient inside each cell.

False
fontSize int

Tick label font size.

10
fontColor str

Accepted for signature compatibility with scimap; overlaid values are drawn in the default text colour.

'black'
fileName str

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

'markerCorrelation.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 marker x marker correlation matrix with returnData=True; (fig, ax) with returnFig=True.

Example
sp.pl.markerCorrelation(adata, layer="log", overlayValues=True)

corr = sp.pl.markerCorrelation(
    adata, subsetMarkers=["CD45", "CD3", "CD8", "FOXP3"], returnData=True
)