`MAP_dispersions` of refitted genes keep the value from before outlier replacement

Aperta Adatta ai principianti
#519 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@aviralgarg05 ci sta già lavorando.

Dal 17/11/2026.

Valutazione

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

Direzione di ricerca

Parti in pydeseq2/dds.py a _refit_without_outliers (intorno alle righe 1398-1409), dove le colonne del refit vengono ricopiate indietro, e confrontalo con refitWithoutOutliers di DESeq2, che copia ogni colonna. Estendi la copia a MAP_dispersions, _genewise_converged, _MAP_converged, _LFC_converged e _outlier_genes, poi riesegui la riproduzione per confermare che MAP_dispersions di g1/g2 corrisponda a dispersions ed esegui i test di dispersione/refit.

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

Descrizione

bug

After deseq2() with refit_cooks=True, a refitted gene's MAP_dispersions is still the value from before outlier replacement, while dispersions comes from the refit: g1 has MAP_dispersions 0.59995 with and without the refit, and dispersions 0.11337 after it; DESeq2 1.50.2 reports dispMAP and dispersion of 0.11336 for g1, because refitWithoutOutliers copies every column of the refit back (mcols(object)[refitReplace, idx] <- mcols(objectSub)).
_refit_without_outliers (dds.py:1398-1409) copies _normed_means, LFC, genewise_dispersions, fitted_dispersions and dispersions, but not MAP_dispersions or the _genewise_converged, _MAP_converged, _LFC_converged and _outlier_genes columns; copying those too would fix it.

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)


counts, metadata = simulate(n_genes=100, groups=(7, 7), seed=2)
counts.loc["s0", ["g1", "g2"]] *= 20
counts.to_csv("counts.csv")
metadata.to_csv("metadata.csv")
for refit in [True, False]:
	dds = dataset(counts, metadata, refit_cooks=refit)
	dds.deseq2()
	columns = ["MAP_dispersions", "dispersions"] if refit else ["MAP_dispersions"]
	print(f"refit_cooks={refit}:", dds.var.loc[["g1", "g2", "g4"], columns].round(5).to_dict())

Expected: after the refit, MAP_dispersions equal to dispersions for g1 and g2, as in DESeq2.

Actual, with PyDESeq2 0.6.0:

refit_cooks=True: {'MAP_dispersions': {'g1': 0.59995, 'g2': 0.41028, 'g4': 0.06673}, 'dispersions': {'g1': 0.11337, 'g2': 0.07503, 'g4': 0.06673}}
refit_cooks=False: {'MAP_dispersions': {'g1': 0.59995, 'g2': 0.41028, 'g4': 0.06673}}

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)
round(as.data.frame(mcols(dds)[c("g1", "g2", "g4"), c("dispMAP", "dispersion")]), 5)
#    dispMAP dispersion
# g1 0.11336    0.11336
# g2 0.07500    0.07500
# g4 0.06669    0.06669

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.