.peptides_on_prot_sequence
- proteopy.pl.peptides_on_prot_sequence(adata, protein_id, group_by=None, ref_sequence=None, alt_pep_sequence_key=None, add_sequences=None, allow_overlaps=False, allow_multi_match=False, color_scheme=None, title=None, order=None, figsize=None, show=True, save=None, ax=None)[source]
Plot peptide coverage on a protein reference sequence.
Filters peptides belonging to the given
protein_idand draws them as broken bars on top of a grey reference bar. Extra sequences (e.g., domains or post-translational modification sites) can be overlaid via theadd_sequencesparameter.- Parameters:
adata (AnnData) – Peptide-level
AnnData.protein_id (str) – Value in
adata.var["protein_id"]to select peptides for.group_by (str | None) – Column in
adata.varused to assign peptides to colored rows. WhenNone, all peptides are placed in a single row labeledprotein_id. Peptides with a missing value in this column are not plotted.ref_sequence (str | None) –
Reference protein sequence. Resolved in this order:
FASTA annotator – if the string ends with
.fasta(case-insensitive), it is read as the path to a reference proteome FASTA file. The entry whose accession equalsprotein_idis used. The accession is the second|-delimited header field (UniProt-stylesp|P12345|NAME_HUMAN->P12345), or the full header if it has no such field.adata.var column – if the string names a column in
adata.var, the sequence stored in that column for the peptides ofprotein_idis used. All these peptides must carry the same, non-missing sequence.Amino-acid string – otherwise the string itself is used as the reference sequence.
alt_pep_sequence_key (str | None) – Column in
adata.varwhose values are used as peptide amino-acid strings. WhenNone,adata.var["peptide_id"]is used.add_sequences (dict[str, dict] | str | None) –
Additional sequences to overlay. Either:
dict – named sequences (e.g., domains). Each value must be a dict with a
"group"key and either a"seq"or"seq_coord"key. Coordinates are 0-based throughout."seq_coord"must be a half-open[start, end)tuple wherestart >= 0andend <= len(ref_sequence).GFF isoform annotator – a path ending with
.gff(case-insensitive) to a UniProt GFF download. Its “Alternative sequence” (VSP) features forprotein_idare drawn one row per isoform, marking the reference regions that the isoform replaces or deletes. A feature shared by several isoforms appears in each of their rows. The coordinates refer to the UniProt canonical sequence, soref_sequencemust be that sequence. Isoform rows are labeled as in UniProt (e.g."isoform 2"); seeorderfor their placement.
allow_overlaps (bool) – When
False, raiseValueErrorif two sequences in the same group overlap positionally.allow_multi_match (bool) – When
True, a peptide sequence matching the reference at multiple positions is shown as one bar per match, labeled"<name> (match N)". WhenFalse, aValueErroris raised for ambiguous matches.color_scheme (str | dict | list | Colormap | callable | None) – Color specification for groups. The
group_bygroups take colors in the order their rows are drawn, and theadd_sequencesgroups continue the color sequence where they end. With the default order (category order if categorical, else lexicographic) this matchesproteoform_intensities()andpeptide_intensities(), so the same proteoform gets the same color in both plots. A customorderrecolors the rows by their new positions.title (str | None) – Axes title.
order (list[str] | None) – Group rows to draw, bottom to top, directly above the reference. Groups absent from
orderare excluded. WhenNone, the peptide groups are drawn first, in the category order ofgroup_byif it is categorical (categories without peptides are dropped), else in lexicographic order of thestr-coerced values. To change it, storegroup_byas an ordered Categorical. Theadd_sequencesgroups follow above in natural order ("isoform 2"before"isoform 10"). A peptide group and anadd_sequencesgroup with the same label are drawn as separate rows; naming that label inorderselects both.figsize (tuple[float, float] | None) – Figure dimensions
(width, height)in inches.show (bool) – Call
plt.show()at the end.save (str | Path | None) – Path at which to save the figure (300 dpi,
bbox_inches="tight"). WhenNone, the figure is not saved.ax (matplotlib.axes.Axes | None) – Matplotlib Axes object to plot onto. If
None, a new figure and axes are created. The function always returns the Axes object used for plotting.
- Returns:
The Axes object used for plotting.
- Return type:
- Raises:
ValueError – If
adatais not at peptide level.ValueError – If
ref_sequenceisNone.ValueError – If no peptides match
protein_idinadata.var["protein_id"].ValueError – If
ref_sequenceis a FASTA path lackingprotein_id, or aadata.varcolumn holding missing or differing sequences forprotein_id.ValueError – If
add_sequencesis a string not ending with.gff.ValueError – If
add_sequencesis a GFF path and a substitution feature does not matchref_sequenceat its coordinates.FileNotFoundError – If
ref_sequenceis a FASTA path, oradd_sequencesa GFF path, that does not exist.ValueError – If a peptide sequence is not found in the reference.
ValueError – If a peptide matches the reference at multiple positions and
allow_multi_match=False.ValueError – If two sequences in the same group overlap and
allow_overlaps=False.KeyError – If
alt_pep_sequence_keyorgroup_byis not found inadata.var.
- Warns:
UserWarning – If
add_sequencesis a GFF path without “Alternative sequence” features forprotein_id.
Examples
Build a minimal peptide-level AnnData with two proteins.
"ELPGW"belongs to P2 and is excluded by the filter.>>> import numpy as np >>> import pandas as pd >>> import anndata as ad >>> import proteopy as pr >>> ref = "MKTAYIAKQRQISFVKSHFSRQDEEP" >>> peptides = [ ... "KTAYIAK", "QRQISFVK", "SHFSRQ", "ELPGW", ... ] >>> var = pd.DataFrame( ... { ... "peptide_id": peptides, ... "protein_id": ["P1", "P1", "P1", "P2"], ... "proteoform": ["A", "A", "B", "A"], ... }, ... index=peptides, ... ) >>> obs = pd.DataFrame( ... {"sample_id": ["S1", "S2"]}, ... index=["S1", "S2"], ... ) >>> adata = ad.AnnData( ... X=np.ones((2, 4)), ... obs=obs, ... var=var, ... )
Filter to P1; group peptides by proteoform.
>>> pr.pl.peptides_on_prot_sequence( ... adata, ... protein_id="P1", ... ref_sequence=ref, ... group_by="proteoform", ... )
The reference sequence can also be read from a reference proteome FASTA, matched by accession, or from an
adata.varcolumn.>>> pr.pl.peptides_on_prot_sequence( ... adata, ... protein_id="P1", ... ref_sequence="reference_proteome.fasta", ... ) >>> adata.var["protein_sequence"] = [ref, ref, ref, "ELPGWK"] >>> pr.pl.peptides_on_prot_sequence( ... adata, ... protein_id="P1", ... ref_sequence="protein_sequence", ... )
Mark the regions of the canonical sequence that differ in each isoform, using UniProt “Alternative sequence” features (
protein_idmust be the UniProt accession).>>> pr.pl.peptides_on_prot_sequence( ... adata, ... protein_id="O00154", ... ref_sequence="uniprot_human.fasta", ... add_sequences="uniprot_human.gff", ... )