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

Đang mở Phù hợp với người mới
#573 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, pandas, python
Lĩnh vực
bioinformatics, data

Hướng nghiên cứu

Đọc ds.py:393-408 và ds.py:465-468 để theo dõi cách lfc_shrink() xác thực các contrast và cập nhật results_df. Trước tiên, hãy kiểm tra mối liên hệ giữa coeff được chỉ định rõ ràng và contrast_vector, sau đó thêm một bài kiểm thử hồi quy sử dụng contrast đảo ngược được mô tả trong issue. Công việc hoàn tất khi các hệ số không tương thích gây ra ValueError, còn các contrast tương thích vẫn được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
770
Fork
98
Merge trung bình
19 giờ 55 phút
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của scverse/PyDESeq2

Tất cả issue của scverse/PyDESeq2

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.