Genes that are all zero after outlier replacement get p-value NaN instead of 1

Aperta Adatta ai principianti
#514 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@tomaionescu ci sta già lavorando.

Dal 28/11/2026.

  • #555 di @tomaionescu — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Parti da _cooks_filtering in pydeseq2/ds.py (intorno alla riga 515), dove il p-value di un gene segnalato viene sovrascritto con NaN, e confrontalo con cooks_outlier in pydeseq2/dds.py (righe 1043-1050), che legge replace_cooks; nota che solo i geni riadattati hanno le loro distanze azzerate (dds.py:1413-1414), quindi new_all_zeroes_genes resta segnalato. Leggi run_wald_test (ds.py:322-325) per la gestione esistente del p-value pari a 1 da #239, poi esegui lo script di riproduzione per confermare il NaN e aggiungi un test di regressione che asserisce che pvalue è 1.0 per single dopo summary().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

A gene whose only positive count is replaced as a Cook's outlier becomes all zero.
run_wald_test gives it p-value 1 (ds.py:322-325), and Cook's filtering in summary() then sets that p-value to NaN; DESeq2 1.50.2 reports 1 for the same gene, since results() sets the p-value of genes that are zero after replacement (nowZero) to 1 after its Cook's filtering.
cooks_outlier reads replace_cooks (dds.py:1043-1050), where only refitted genes have their distances zeroed (dds.py:1413-1414), so a gene that is replaced but not refitted stays flagged and _cooks_filtering (ds.py:515) overwrites its p-value.
Leaving new_all_zeroes_genes out of cooks_outlier, or setting their p-values to 1 after Cook's filtering, would fix it.
Related: #239, which set these genes' p-values to 1 in run_wald_test.

Source line numbers refer to commit 2ca3b74.

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


def simulate(n_genes=200, groups=(4, 4), seed=0):
	"""Counts (samples x genes) and metadata; dispersion 0.05 + 1 / mean."""
	rng = np.random.default_rng(seed)
	group = np.repeat(np.arange(len(groups)), groups)
	base = rng.lognormal(4, 1.5, n_genes)
	lfc = rng.normal(0, 0.5, (len(groups), n_genes))
	lfc[0] = 0
	mu = base * np.exp(lfc[group])
	disp = 0.05 + 1 / base
	counts = rng.negative_binomial(1 / disp, 1 / (1 + disp * mu))
	samples = [f"s{i}" for i in range(len(group))]
	counts = pd.DataFrame(counts, index=samples, columns=[f"g{j}" for j in range(n_genes)])
	metadata = pd.DataFrame({"condition": np.array(list("ABCDEF"))[group]}, index=samples)
	return counts, metadata


def dataset(counts, metadata, **kwargs):
	return DeseqDataSet(counts=counts, metadata=metadata, n_cpus=1, quiet=True, **kwargs)


from pydeseq2.ds import DeseqStats
counts, metadata = simulate(n_genes=60, groups=(8, 8), seed=4)
counts["single"] = [0] * 15 + [100]
counts.to_csv("counts.csv")
metadata.to_csv("metadata.csv")
dds = dataset(counts, metadata)
dds.deseq2()
print("new all-zero genes:", list(dds.new_all_zeroes_genes))
ds = DeseqStats(dds, contrast=["condition", "B", "A"], n_cpus=1, quiet=True)
ds.run_wald_test()
print("pvalue after run_wald_test:", ds.p_values["single"])
ds.summary()
print("pvalue after summary:", ds.results_df.loc["single", "pvalue"])

Expected: pvalue after summary: 1.0, as in DESeq2.

Actual, with PyDESeq2 0.6.0:

new all-zero genes: ['single']
pvalue after run_wald_test: 1.0
pvalue after summary: nan

DESeq2 1.50.2 on the counts that the reproduction writes:

suppressMessages(library(DESeq2))
counts <- t(as.matrix(read.csv("counts.csv", row.names = 1, check.names = FALSE)))
coldata <- read.csv("metadata.csv", row.names = 1, stringsAsFactors = TRUE)
dds <- DESeq(DESeqDataSetFromMatrix(counts, coldata, ~condition), quiet = TRUE)
results(dds, contrast = c("condition", "B", "A"))["single", "pvalue"]
# [1] 1

Split out from #491.

Lingua principale
Python
Stelle
770
Fork
98
Merge medio
19h 55m
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scverse/PyDESeq2

Tutte le issue di scverse/PyDESeq2

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.