Skip to content

foldChange

foldChange

foldChange(
    data,
    label="foldchange",
    pVal=0.05,
    nonsigColor="grey",
    subsetXAxis=None,
    subsetYAxis=None,
    cmap="vlag",
    log=True,
    center=0,
    method="heatmap",
    invertAxis=None,
    parallelCoordinatesColor=None,
    fileName="foldchange.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Plot cell-type abundance fold changes between groups.

Reads uns[label + "_fc"] (falling back to uns[label]), the matrix that sp.tl.foldChange writes: one row per comparison group, one column per phenotype.

method="heatmap" draws a diverging heatmap centred on center, with the colour limits made symmetric so that equal up- and down-changes read the same. method="parallel_coordinates" draws one line per phenotype across the groups.

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

The label used when the fold changes were computed. uns[label + "_fc"] is preferred, uns[label] is the fallback.

'foldchange'
pVal float

Significance threshold. Accepted for signature compatibility; the current implementation does not mask by p-value.

0.05
nonsigColor str

Colour for non-significant cells. Accepted for signature compatibility; see pVal.

'grey'
subsetXAxis list

Restrict to these columns (phenotypes).

None
subsetYAxis list

Restrict to these rows (groups).

None
cmap str

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

'vlag'
log bool

Plot log2 of the fold changes. On by default, which is almost always what you want for a ratio.

True
center float

The value the diverging colormap is centred on. 0 with log=True.

0
method str

'heatmap' or 'parallel_coordinates'.

'heatmap'
invertAxis bool

Accepted for signature compatibility with scimap; transpose the matrix yourself if you need the other orientation.

None
parallelCoordinatesColor str | list

Line colours for method='parallel_coordinates'.

None
**kwargs dict

Extra options. figsize sets the figure size in inches; it is scaled from the matrix shape when omitted.

{}
fileName str

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

'foldchange.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 fold-change matrix with returnData=True; (fig, ax) with returnFig=True.

Example
adata = sp.tl.foldChange(adata, fromGroup="control")
sp.pl.foldChange(adata, method="heatmap")
sp.pl.foldChange(adata, method="parallel_coordinates")