opendvp.plotting.upset#
- upset(adata, groupby, min_presence_fraction=0.7, sort_by='cardinality', return_fig=False, ax=None, **kwargs)#
Generate an UpSet plot from an AnnData object based on variable presence across groups.
Expected input is a non-imputed adata object.
Variables that are completely NaN across all samples are excluded. Variables that do not pass min_presence_fraction of the selected group are removed. e.g if 0.5, if only 40% of samples have a valid value that variable is not counted for that group. The final UpSet plot shows presence/absence of variables across the specified groups.
Parameters:#
- adataAnnData
Annotated data matrix with observations (samples) as rows and variables as columns.
- groupbystr
Column name in
adata.obs
used to group samples before computing presence.- min_presence_fractionfloat, optional
Minimum fraction of samples (within a group) where a variable must be present for that group to consider the variable as “present”. Value between 0.0 and 1.0. Default is 0.7.
- sort_bystr, optional
Sorter for UpSet plot: cardinality, degree, -cardinality, -degree. Default is “cardinality”.
- return_figbool, optional
Whether to return the matplotlib Figure object. Default is False.
- **kwargs
Additional keyword arguments passed to UpSet.
Returns:#
- matplotlib.figure.Figure or None
The matplotlib Figure object containing the UpSet plot, or None if not requested.
Example:#
>>> upset(adata, groupby="condition", threshold=1000, min_presence_fraction=0.2)