Genes that are all zero after outlier replacement get p-value NaN instead of 1
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- bioinformatics
Research direction
Start from _cooks_filtering in pydeseq2/ds.py (around line 515), where a flagged gene's p-value is overwritten with NaN, and compare it with cooks_outlier in pydeseq2/dds.py (lines 1043-1050), which reads replace_cooks; note that only refitted genes have their distances zeroed (dds.py:1413-1414), so new_all_zeroes_genes stays flagged. Read run_wald_test (ds.py:322-325) for the existing p-value-of-1 handling from #239, then run the reproduction script to confirm the NaN and add a regression test asserting pvalue is 1.0 for single after summary().
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 770
- Forks
- 98
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 45
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scverse/PyDESeq2
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
`lowess` returns 0 for points of an exact fit after robustness iterationsMay be free again @aviralgarg05 claimed this 15 days ago, and no pull request is open. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
scverse/PyDESeq2#520 · 1 comment ·
Maintainers usually reply within 1 day
-
`irls_solver` does not enforce `min_beta` when IRLS converges, and documents `max_beta`'s default as -30May be free again @aviralgarg05 claimed this 15 days ago, and no pull request is open. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
scverse/PyDESeq2#521 · 1 comment ·
Maintainers usually reply within 1 day
-
`MAP_dispersions` of refitted genes keep the value from before outlier replacementMay be free again @aviralgarg05 claimed this 15 days ago, and no pull request is open. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
scverse/PyDESeq2#519 · 1 comment ·
Maintainers usually reply within 1 day
All issues in scverse/PyDESeq2
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
nael5x/creative-ai#130 ·
-
Make the "%" unit spacing the same in the web and in A10Possibly taken @kragent66-glitch claimed this today. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 comment ·
-
ci severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TMHSDigital/Spackle#205 ·
Maintainers usually reply within 1 day
-
pkg:lgm type:chore upstream-gaussx
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
jejjohnson/pyrox#610 ·
Maintainers usually reply within 1 day
-
bug user-report
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day