delnx.tl.nb_testΒΆ

delnx.tl.nb_test(adata, fit, contrast=None, reduced_design=None, multitest_method='fdr_bh', lfc_threshold=0.0, batch_size=512)[source]ΒΆ

Test for differential expression using quasi-likelihood F-test.

Parameters:
  • adata (AnnData) – AnnData object (same one passed to nb_fit()).

  • fit (NBFitResult) – Fitted model from nb_fit().

  • contrast (str | int | None (default: None)) –

    Coefficient to test. Supports shorthand:

    • Level name: "drugA" (resolved via condition_key).

    • Bracket shorthand: "treatment[drugA]" (for multi-covariate models).

    • Full patsy name: "treatment[T.drugA]" (always works).

    • Integer index or None (last coefficient).

    • None: Test last coefficient.

  • reduced_design (ndarray | None (default: None)) – Reduced design matrix for likelihood ratio test. If None, automatically created by dropping the tested coefficient.

  • multitest_method (str (default: 'fdr_bh')) – Method for multiple testing correction.

  • lfc_threshold (float (default: 0.0)) – Threshold for log2 fold change filtering.

  • batch_size (int (default: 512)) – Number of genes to process in each batch. Controls GPU memory usage for the reduced model refit.

Return type:

DataFrame

Returns:

pd.DataFrame Results with columns:

  • feature: Gene/feature names

  • log2fc: Log2 fold change

  • coef: Model coefficient

  • stat: F-statistic

  • pval: Raw p-value

  • padj: Adjusted p-value

Examples

Test for treatment effect:

>>> fit = dx.tl.nb_fit(adata, condition_key="treatment")
>>> results = dx.tl.nb_test(adata, fit)

Test specific contrast by name:

>>> results = dx.tl.nb_test(adata, fit, contrast="treatmentB")