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

未关闭 适合新手
#574 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, python

调研方向

从 glm.py 第242–259行附近的 wald_test() 开始,检查 greater、less 和 lessAbs 分支。使用 issue 中全零基因的示例重现问题,然后添加或运行一个有针对性的测试,确认这些备择假设对应的统计量和 p 值为 NaN。回归问题得到覆盖且返回预期的 NaN 值后,即完成。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Python
星标
770
派生
98
平均合并
19 小时 55 分钟
30 天内合并 PR
45

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

scverse/PyDESeq2 的其他 Issue

查看 scverse/PyDESeq2 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。