alphapepttools.pl.rank_median_plot

alphapepttools.pl.rank_median_plot#

alphapepttools.pl.rank_median_plot(data, ax, layer='X', color='blue', color_map_column=None, color_column=None, palette=None, color_dict=None, legend=None, scatter_kwargs=None)#

Rank plot showing median intensities across samples.

Computes the median intensity for each feature (protein/peptide) across all samples, ranks them from highest to lowest, and creates a scatter plot with rank on the x-axis and median intensity on the y-axis (log-scale). Useful for visualizing the dynamic range of detected features and identifying highly abundant vs low-abundance features.

Parameters:
  • data (AnnData | DataFrame) – AnnData or DataFrame containing intensity values.

  • ax (Axes) – Matplotlib axes object to plot on.

  • layer (str (default: 'X')) – The AnnData layer to use for calculating median intensities. Default is “X”.

  • color (str (default: 'blue')) – Single color for all points. Overridden by color_map_column or color_column.

  • color_map_column (str | None (default: None)) – Column in data.var (for AnnData) to use for color encoding. Values are mapped to colors using the palette or color_dict. Overrides the color parameter.

  • color_column (str | None (default: None)) – Column in data.var (for AnnData) containing actual color values (hex, RGBA, etc.). Overrides both color and color_map_column parameters.

  • palette (list[str | tuple] | None (default: None)) – List of colors to use for color encoding. If None, a default palette is used.

  • color_dict (dict[str, str | tuple] | None (default: None)) – Dictionary mapping category values to specific colors. If provided, palette is ignored.

  • legend (str | Legend | None (default: None)) – Legend specification. Use “auto” to automatically create a legend from color_map_column.

  • scatter_kwargs (dict | None (default: None)) – Additional keyword arguments passed to matplotlib scatter function (e.g., alpha, s).

Return type:

None

Examples

Basic rank plot with single color:

fig, ax = plt.subplots()
apt.pl.rank_median_plot(
    data=adata,
    ax=ax,
    color=BaseColors.get("blue"),
    scatter_kwargs={"alpha": 0.7},
)

Color by protein category:

fig, ax = plt.subplots()
apt.pl.rank_median_plot(
    data=adata,
    ax=ax,
    color_map_column="protein_type",
    color_dict={"protein_type_A": "red", "protein_type_B": "green", "protein_type_C": "blue"},
    legend="auto",
    scatter_kwargs={"s": 20},
)

Notes

  • The y-axis is automatically set to log scale

  • Features are ranked from highest to lowest median intensity

  • For AnnData objects, var annotations can be used for coloring via color_map_column

  • This is a convenience wrapper around the scatter() method with automatic data preparation