lfc_shrink(coeff=...) bypasses contrast validation and silently flips LFC signs

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

阅读 ds.py:393-408 和 ds.py:465-468,追踪 lfc_shrink() 如何验证对比并更新 results_df。首先检查显式指定的 coeff 与 contrast_vector 的关系,然后添加一个使用 issue 中所述反向对比的回归测试。当不兼容的系数会引发 ValueError,且兼容的对比仍受支持时,任务即完成。

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

描述

In ds.py:393-408, contrast validation in lfc_shrink() only runs when coeff is None, and its error message prompts "please provide coeff". Passing an explicit coeff for a reversed contrast (contrast_vector = [0, -1]) skips validation and overwrites results_df["log2FoldChange"] (ds.py:465-468) with the opposite-sign coefficient while leaving stat, pvalue, and padj unchanged.

Related: #544.

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.iloc[:3, 0] = [400, 420, 450]  # KO high
counts.iloc[3:, 0] = [30, 35, 25]     # WT low
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", "KO", "WT"], n_cpus=1, quiet=True)
ds.summary()
print("Before:", round(ds.results_df.loc["g0", "log2FoldChange"], 3),
      round(ds.results_df.loc["g0", "stat"], 3))
ds.lfc_shrink(coeff="condition[T.WT]")
print("After: ", round(ds.results_df.loc["g0", "log2FoldChange"], 3),
      round(ds.results_df.loc["g0", "stat"], 3))

Expected: Raise ValueError unless contrast_vector selects the single +1 column matching coeff (and guide callers to reparameterize the design so the target effect is one column rather than passing an incompatible coeff).

Actual, with PyDESeq2 main@e1eefef (also reproduces on v0.7.0):

Before: 3.486 7.56
After:  -3.366 7.56
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 摘要。