wald_test() with greater/less/lessAbs turns NaN LFCs into stat=0.0, pvalue=0.5

Open Beginner friendly
#574 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python

Research direction

Start with wald_test() in glm.py around lines 242–259 and inspect the greater, less, and lessAbs branches. Reproduce with the all-zero gene example in the issue, then add or run a focused test confirming its statistic and p-value are NaN for those alternatives. Done when the regression is covered and the expected NaN values are returned.

Written by the indexing model from the issue text.

Description

In glm.py:242-259, wald_test() uses np.fmax/np.fmin (which ignore NaNs) instead of np.maximum/np.minimum. For any gene with LFC = NaN (e.g., an all-zero gene), alt_hypothesis in {"greater", "less", "lessAbs"} returns stat = 0.0 and pvalue = 0.5 instead of NaN (greaterAbs returns NaN via np.sign).

Related: #572, #515.

Source line numbers refer to commit e1eefef.

Reproduction
import numpy as np
import pandas as pd
from pydeseq2.dds import DeseqDataSet
from pydeseq2.ds import DeseqStats

rng = np.random.default_rng(0)
counts = pd.DataFrame(
    rng.negative_binomial(5, 0.05, (6, 20)),
    index=[f"s{i}" for i in range(6)],
    columns=[f"g{i}" for i in range(20)],
)
counts["g1"] = 0  # all-zero gene -> LFC=NaN
meta = pd.DataFrame({"condition": ["KO"] * 3 + ["WT"] * 3}, index=counts.index)

dds = DeseqDataSet(counts=counts, metadata=meta, design="~condition",
                   fit_type="mean", n_cpus=1, quiet=True)
dds.deseq2()
ds = DeseqStats(dds, contrast=["condition", "WT", "KO"],
                alt_hypothesis="greater", lfc_null=1.0, n_cpus=1, quiet=True)
ds.summary()
print(ds.results_df.loc["g1", ["log2FoldChange", "lfcSE", "stat", "pvalue"]])

Expected: stat = NaN and pvalue = NaN (using np.maximum/np.minimum).

Actual, with PyDESeq2 main@e1eefef (also reproduces on v0.7.0, and identically for less and lessAbs):

log2FoldChange    NaN
lfcSE             NaN
stat              0.0
pvalue            0.5
Name: g1, dtype: float64
Versions
pydeseq2: 0.7.0 (main@e1eefef)
python: 3.12.14
numpy: 2.5.5
pandas: 3.1.2
scipy: 1.18.1
Dominant language
Python
Stars
770
Forks
98
Avg merge
19h 55m
Merged PRs (30d)
45

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from scverse/PyDESeq2

All issues in scverse/PyDESeq2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.