.n_proteins_per_sample

proteopy.pl.n_proteins_per_sample(adata, *, layer=None, zero_to_na=False, level=None, percentage=False, ascending=None, order_by=None, order=None, group_by=None, print_stats=False, figsize=(6.0, 4.0), color_scheme=None, title=None, ylabel=None, xlabel_rotation=90, order_by_label_rotation=0, show=True, ax=None, save=None)

Plot the number of detected proteins per sample.

For each sample (observation), counts the number of proteins with non-missing values.

Unless order or ascending imposes an order, bars follow the default order of adata.obs["sample_id"]: its category order when the column is a Categorical, otherwise its values sorted lexicographically. The same rule orders the groups of group_by and the blocks of order_by. Store an annotation as an ordered Categorical to control the order:

adata.obs["sample_id"] = pd.Categorical(
    adata.obs["sample_id"],
    categories=["s1", "s2", "s10"],
    ordered=True,
)

Categories that no observation matches are dropped, since an empty group has no bar to draw.

Parameters:
  • adata (AnnData) – AnnData object in proteodata format.

  • layer (str or None, optional) – Key in adata.layers; when set, uses that layer instead of .X.

  • zero_to_na (bool, optional) – If True, zeros in the matrix are treated as missing values.

  • percentage (bool, optional) – Display y-axis values as a percentage of total variables instead of raw counts.

  • ascending (bool or None, optional) – Sort samples by detected counts. True places lower counts to the left, False higher counts to the left. With order_by the sort applies within each group. None imposes no count order, so the default order below applies. Ignored, with a warning, when order or group_by is set.

  • order_by (str or None, optional) – Column in adata.obs used for grouping and colouring bars. Samples with a missing value in this column are drawn in a trailing "NA" block.

  • order (Sequence[str] or None, optional) – Ordering and subsetting of the x-axis: the listed values are drawn, in the given sequence, and everything else is excluded — from the statistics as well as the plot. Without group_by or order_by the values are adata.obs["sample_id"] entries; with either of them they are values of that column.

  • group_by (str or None, optional) – Column in adata.obs used to summarise observations into groups. When provided, a mean +/- std bar chart is shown. Mutually exclusive with order_by. Observations with a missing value in this column are dropped.

  • print_stats (bool, optional) – Print summary statistics as a DataFrame.

  • figsize (tuple of float, optional) – Figure size (width, height) in inches passed to matplotlib.pyplot.subplots().

  • color_scheme (str | dict | Sequence | Colormap | Callable | None) – Colour mapping for groups. Accepts a named Matplotlib colormap, a single colour, a list/tuple of colours, a dict mapping labels to colours, a Colormap, or a callable.

  • title (str or None, optional) – Plot title.

  • ylabel (str or None, optional) – Label for the y-axis.

  • xlabel_rotation (float, optional) – Rotation in degrees applied to x-axis tick labels.

  • order_by_label_rotation (float, optional) – Rotation in degrees applied to group labels drawn above the plot.

  • show (bool, optional) – Call matplotlib.pyplot.show() when True.

  • ax (Axes or None, optional) – Matplotlib Axes to plot onto. If None, a new figure and axes are created.

  • save (str or Path or None, optional) – File path to save the figure.

Returns:

The Matplotlib Axes object used for plotting.

Return type:

Axes

Examples

>>> import proteopy as pr

Protein-level data:

>>> adata = pr.datasets.karayel_2020()
>>> pr.pl.n_proteins_per_sample(adata)

Peptide-level data (aggregated to proteins):

>>> adata = pr.datasets.williams_2018()
>>> pr.pl.n_proteins_per_sample(adata)

Show mean +/- std per group:

>>> pr.pl.n_proteins_per_sample(
...     adata,
...     group_by="tissue",
... )
Note:

This function is a partial of n_var_per_sample, with the following arguments fixed: level=’protein’.