.differential_abundance_df
- proteopy.get.differential_abundance_df(adata, keys=None, key_group=None, min_logfc=None, max_logfc=None, max_pval=None, sort_by=None)[source]
Retrieve differential abundance results from
.varmas a long-format DataFrame.Merges one or more test result DataFrames stored in
adata.varminto a single tidy DataFrame with an added column identifying the source test.- Parameters:
adata (
AnnData) – Annotated data object containing differential abundance results in.varm.keys (str | Sequence[str] | None) – One or more keys in
adata.varmcorresponding to differential abundance test results (e.g.,"ttest_two_sample_treated-control"or"welch_A-vs-rest"). Mutually exclusive withkey_group.key_group (str | None) – Alternative to
keys. A key group identifier (e.g.,"welch_one_vs_rest") that selects all.varmkeys belonging to that group. Usetests()to see available key groups. Mutually exclusive withkeys.min_logfc (float | None) – If provided, filter to rows where
logfc >= min_logfc.max_logfc (float | None) – If provided, filter to rows where
logfc <= max_logfc.max_pval (float | None) – If provided, filter to rows where adjusted p-value <=
max_pval. Usespval_adjcolumn if present, otherwise falls back topval.sort_by (str | None) – Column name to sort by in descending order (e.g.,
"logfc").
- Returns:
Long-format DataFrame with columns:
var_id: Variable identifier (fromadata.var_names).test_type: The statistical test method (e.g.,"welch").group_by: The.obscolumn used for grouping.design: Underscore-separated design identifier (e.g.,"A_vs_rest").design_label: Human-readable description of what the test compares.mean1: Mean expression in group 1.mean2: Mean expression in group 2.logfc: Log fold change.tstat: t-statistic.pval: Raw p-value.pval_adj: Adjusted p-value.is_diff_abundant: Boolean indicating significance.
- Return type:
- Raises:
ValueError – If both
keysandkey_groupare provided, or if neither is provided.TypeError – If
keysis neither a string nor a sequence of strings.KeyError – If any specified key is not found in
adata.varm, or ifkey_groupdoes not match any test group.
Examples
>>> import proteopy as pp >>> # Using explicit keys >>> df = pp.get.differential_abundance_df( ... adata, ... keys=["welch_treated-control", "welch_A-vs-rest"], ... ) >>> sig_proteins = df[df["is_diff_abundant"]] >>> >>> # Using key_group to select all tests in a group >>> df = pp.get.differential_abundance_df( ... adata, ... key_group="welch_one_vs_rest", ... )