pycea.pl.ancestral_linkage#
- pycea.pl.ancestral_linkage(tdata, groupby=None, symmetrize=None, normalize=None, data=None, tree=None, cluster='average', cluster_mode=None, order=None, cmap=None, vmin=None, vmax=None, center=0, xticklabels=True, yticklabels=True, labelsize=None, cbar=True, ax=None, **kwargs)#
Plot ancestral linkage as a clustered heatmap.
Displays the category × category linkage computed by
pycea.tl.ancestral_linkage()as a heatmap, with rows and columns ordered by hierarchical clustering. The matrix is rebuilt from the long-form statistics table so thatsymmetrizeandnormalizecan be chosen independently of howpycea.tl.ancestral_linkage()was called.- Parameters:
tdata (
TreeData) – The TreeData object.groupby (
str|None(default:None)) – Thegroupby/key_addedused when runningpycea.tl.ancestral_linkage(); statistics are read fromtdata.uns[f"{groupby}_linkage_stats"]. IfNone, it is inferred fromtdata.uns(requires exactly one*_linkage_statsentry).symmetrize (
Literal['mean','max','min',False,None] (default:None)) – How to symmetrize the directional (source → target) matrix before plotting:'mean','max','min', orFalseto leave it asymmetric. IfNone(default), use the value recorded bypycea.tl.ancestral_linkage()intdata.uns(defaults toFalsewhen it cannot be determined).normalize (
bool|None(default:None)) – IfTrue, color by the enrichmentvalue - permuted_value(centered at 0); ifFalse, color by the raw linkagevalue. IfNone(default), use the value recorded bypycea.tl.ancestral_linkage()intdata.uns(defaults toTruewhen it cannot be determined).data (
DataFrame|None(default:None)) – Long-form statistics to plot. Usestdata.uns[f"{groupby}_linkage_stats"]ifNone.tree (
str|None(default:None)) – If the statistics are per-tree (computed withby_tree=True), the tree to plot. IfNone, values are averaged across trees.cluster (
str|None(default:'average')) – Linkage method (e.g.'ward','average') used to order rows/columns by hierarchical clustering. IfNone, the categories are left in their original order. Ignored iforderis given.cluster_mode (
Literal['similarity','dissimilarity',None] (default:None)) – Whether the matrix values are a'similarity'(larger = more related, negated to a distance before clustering) or a'dissimilarity'(larger = less related, used directly). IfNone(default), inferred from the recordedmetric:'dissimilarity'formetric='path'and'similarity'otherwise.order (
Sequence[str] |None(default:None)) – Explicit order of categories (rows and columns). Overridescluster.cmap (
str|None(default:None)) – Colormap for the heatmap. IfNone, defaults to'RdBu_r'whennormalize=True(diverging) and'viridis'whennormalize=False(sequential).vmin (
float|None(default:None)) – Lower / upper bounds of the color scale. IfNone, derived from the largest absolute off-diagonal deviation fromcenter(diverging) or from the off-diagonal min / max (sequential).vmax (
float|None(default:None)) – Lower / upper bounds of the color scale. IfNone, derived from the largest absolute off-diagonal deviation fromcenter(diverging) or from the off-diagonal min / max (sequential).center (
float|None(default:0)) – The value at which to center the colormap. As withseaborn.heatmap(), this is only applied to the diverging (normalize=True) heatmap viaTwoSlopeNorm; it is ignored for the sequential (normalize=False) heatmap. Set toNoneto disable centering.xticklabels (
bool(default:True)) – Whether to draw the column / row tick labels.yticklabels (
bool(default:True)) – Whether to draw the column / row tick labels.labelsize (
float|None(default:None)) – Font size for the tick labels.cbar (
bool(default:True)) – Whether to draw a colorbar.ax (
Axes|None(default:None)) – Axes on which to draw the plot. Creates new axes whenNone.kwargs (
Any) – Additional keyword arguments forpcolormesh().
- Return type:
- Returns:
ax - Axes containing the heatmap.