opendvp.pl.feature_comparison_boxplot

opendvp.pl.feature_comparison_boxplot#

feature_comparison_boxplot(adata, features, group_by, group1=None, group2=None, zscore=True, color_dict=None, return_fig=False, ax=None, **kwargs)#

Plots boxplots of feature expression from adata.X, comparing two groups.

Features are sorted by the mean difference between the two groups.

Parameters:
  • adata (anndata.AnnData) – An AnnData object containing the expression data and observation metadata.

  • features (list[str]) – A list of feature names (from adata.var_names) to plot.

  • group_by (str) – The column name in adata.obs that contains the group labels.

  • group1 (str, optional) – The name of the first group. If None, inferred from group_by.

  • group2 (str, optional) – The name of the second group. If None, inferred from group_by.

  • zscore (bool, optional) – If True, the expression values are converted to Z-scores before plotting and sorting. Defaults to True.

  • color_dict (dict, optional) – A dictionary mapping group names to colors.

  • return_fig (bool, optional) – If True, returns the matplotlib Figure object, by default False.

  • ax (matplotlib.axes.Axes, optional) – An existing Axes object to plot on. If None, a new figure and axes are created.

  • **kwargs (Mapping[str, Any]) – Additional keyword arguments passed to seaborn.boxplot.

Returns:

The matplotlib Figure object if return_fig is True, otherwise None.

Return type:

matplotlib.figure.Figure | None

Raises:

ValueError – If validation of groups or features fails.