.pairwise_peptide_correlations_heatmap
- proteopy.pl.pairwise_peptide_correlations_heatmap(adata, protein, *, corr_key='pairwise_peptide_correlations', margin_color='proteoform_id', method='average', cluster=True, linkage=None, color_scheme=None, cmap='coolwarm', xticklabels='auto', yticklabels='auto', figsize=(8.0, 8.0), show=True, save=None)[source]
Peptide-correlation heatmap for a single protein.
Draw a protein’s peptide Pearson correlations as a heatmap, optionally with hierarchical clustering. Correlations are read from
adata.uns[corr_key], computed byproteopy.tl.pairwise_peptide_correlations(). By default, margin annotations show COPF proteoform assignments fromadata.var["proteoform_id"].- Parameters:
adata (AnnData) – Peptide-level
AnnDatawith pairwise peptide correlations in.uns[corr_key]and margin annotations in.var.protein (str) –
protein_idof the protein to plot.corr_key (str) – Key in
adata.unsholding the long-form pairwise correlations (columnspepA,pepB,PCC; indexed byprotein_id).margin_color (str | list[str]) – Columns in
adata.varshown as annotation strips, in the given order. The default usesproteoform_idwritten byproteopy.tl.peptide_clusters_from_dendograms(). Legends follow category order, otherwise lexicographic order; use an orderedpandas.Categoricalto customize it. Missing annotations appear in light gray.method (str) – Linkage method handed to
scipy.cluster.hierarchy.linkage()when the tree is recomputed from1 - correlation.cluster (bool) – Cluster peptides and draw dendrograms on both axes. When
False, order peptides lexicographically unlessadata.var["peptide_id"]is categorical, in which case its category order is used.linkage (numpy.ndarray | None) – Precomputed SciPy linkage matrix of shape
(n_peptides - 1, 4). When provided it is used for both axes, shadowing the default1 - correlationcomputation. Leaf indices refer to the peptides in the default order described undercluster.color_scheme (Any) – Palette for margin annotations: a colormap name or object, color, color list, category-to-color dict, or callable. A single palette is shared across strips. For multiple strips, a list of palettes must match
margin_colorin length and order; nest color lists to supply one per strip.Noneassigns colors that do not overlap between strips.cmap (str) – Continuous colormap for the heatmap body.
xticklabels (bool | str) – Peptide tick labels on each axis.
"auto"labels as many peptides as fit without overlapping;Truelabels every peptide (enlargefigsizefor large proteins);Falsehides the labels.yticklabels (bool | str) – Peptide tick labels on each axis.
"auto"labels as many peptides as fit without overlapping;Truelabels every peptide (enlargefigsizefor large proteins);Falsehides the labels.figsize (tuple[float, float]) – Matplotlib figure size in inches.
show (bool) – Display the figure with
matplotlib.pyplot.show().save (str | Path | None) – File path to save the figure.
Noneskips saving.
- Returns:
Creates its own figure with
seaborn.clustermap().- Return type:
None
- Raises:
ValueError – If
proteinis unknown,corr_keyis missing, the protein has no pairwise correlations, the table holds several correlations per peptide pair (e.g. per-batch results),margin_coloris empty or repeats a column,linkagedoes not match the number of peptides, a per-stripcolor_schemelist has the wrong length, or clustering is requested on a matrix containing missing values.KeyError – If a
margin_colorcolumn is not present inadata.var.TypeError – If
method,cluster,margin_colororsavehas the wrong type.
- Warns:
UserWarning – If peptides in
adata.uns[corr_key]are no longer inadata.var(filtered after the correlations were computed; they are left out), if NaN correlations are treated asr = 0for clustering, or ifadatahas fewer than 3 samples.
Examples
>>> import anndata as ad >>> import numpy as np >>> import pandas as pd >>> import proteopy as pr >>> samples = ["s1", "s2", "s3", "s4"] >>> peptides = ["pep1", "pep2", "pep3", "pep4"] >>> adata = ad.AnnData( ... X=np.array( ... [[1, 2, 4, 5], [2, 3, 3, 4], ... [3, 4, 2, 3], [4, 5, 1, 2]], ... dtype=float, ... ), ... obs=pd.DataFrame({"sample_id": samples}, index=samples), ... var=pd.DataFrame( ... {"peptide_id": peptides, "protein_id": "P1"}, ... index=peptides, ... ), ... ) >>> pr.tl.pairwise_peptide_correlations(adata) >>> pr.tl.peptide_dendograms_by_correlation(adata) >>> pr.tl.peptide_clusters_from_dendograms( ... adata, ... n_clusters=2, ... min_peptides_per_cluster=2, ... ) >>> pr.pl.pairwise_peptide_correlations_heatmap( ... adata, protein="P1", show=False, ... )
Compare proteoforms with illustrative peptide membrane positions. The categorical annotation controls the membrane-position legend order; each strip uses its own palette:
>>> adata.var["membrano_pos"] = pd.Categorical( ... ["trans", "cytosol", "extra", "trans"], ... categories=["trans", "cytosol", "extra"], ... ordered=True, ... ) >>> pr.pl.pairwise_peptide_correlations_heatmap( ... adata, ... protein="P1", ... margin_color=["proteoform_id", "membrano_pos"], ... color_scheme=["Set2", "Dark2"], ... show=False, ... )