pylimma.top_table

pylimma.top_table(data, coef=None, number=10, genelist=None, adjust_method='BH', sort_by='B', resort_by=None, p_value=1.0, fc=None, lfc=0.0, confint=False, key='pylimma')[source]

Extract a table of top-ranked genes from a linear model fit.

Parameters:
  • data (AnnData or dict) – Either an AnnData object with fit results in adata.uns[key], or a dict from e_bayes().

  • coef (int, str, list, or None) – Coefficient(s) to extract. If None or multiple coefficients, returns F-statistic results. If single coefficient (int or str), returns t-statistic results for that coefficient.

  • number (int, default 10) – Maximum number of genes to return. Use np.inf for all genes.

  • genelist (DataFrame, list, or array, optional) –

    Gene annotations to include in output. If a DataFrame, columns are merged with results. If a list/array, used as gene identifiers. If None (default), uses fit[“genes”] if available.

    For AnnData input, fit[“genes”] only carries var_names; annotation columns in adata.var (e.g. symbol, chromosome) are not duplicated into the fit. Pass genelist=adata.var explicitly to merge those columns into the output table.

  • adjust_method (str, default "BH") – Multiple testing adjustment method. Options: “BH”, “bonferroni”, “holm”, “none”.

  • sort_by (str, default "B") – Column to sort by. Options: - “B” or “b”: B-statistic (log-odds of DE) - “p” or “P”: p-value - “t” or “T”: t-statistic (absolute value) - “logFC” or “log_fc”: log fold-change (absolute value) - “AveExpr” or “ave_expr”: average expression - “F”: F-statistic (for multiple coefficients) - “none”: no sorting

  • resort_by (str, optional) – Secondary sort column applied after filtering by p_value/lfc. Same options as sort_by. Useful when you want to filter by p-value but display sorted by fold-change.

  • p_value (float, default 1.0) – Adjusted p-value cutoff. Only genes with adj_p_value <= p_value are returned.

  • fc (float, optional) – Minimum fold-change required (linear scale, must be >= 1). Only genes with fold-change >= fc are returned. This is an alternative to lfc; if both are specified, fc takes precedence.

  • lfc (float, default 0.0) – Log2 fold-change cutoff. Only genes with |log_fc| >= lfc are returned. Equivalent to log2(fc).

  • confint (bool or float, default False) – If True, compute 95% confidence intervals for log fold-changes. If a float, specifies the confidence level (e.g., 0.99 for 99%). Only applies for single coefficient tests.

  • key (str, default "pylimma") – Key for fit results in adata.uns (AnnData input only).

Returns:

Table of top genes with columns: - gene: gene identifier (if available) - log_fc: log fold-change - ci_l, ci_r: confidence interval bounds (if confint=True) - ave_expr: average expression - t: moderated t-statistic - p_value: raw p-value - adj_p_value: adjusted p-value - b: B-statistic (log-odds)

For multiple coefficients (F-test): - One log_fc column per coefficient - F: F-statistic - p_value: F-test p-value - adj_p_value: adjusted p-value

Return type:

DataFrame

Notes

This function must be called after e_bayes(). The results are sorted and filtered according to the specified parameters.

Examples

>>> fit = lm_fit(expr, design)
>>> fit = e_bayes(fit)
>>> top_table(fit, coef=1, number=20)  # Top 20 genes for coefficient 1
>>> top_table(fit, coef=None)  # F-test across all coefficients
>>> top_table(fit, coef=1, confint=True)  # With 95% CI