owkin / PyDESeq2

A Python implementation of the DESeq2 pipeline for bulk RNA-seq DEA.
https://pydeseq2.readthedocs.io/en/latest/
MIT License
584 stars 62 forks source link

[BUG] error when running lfc_shrink #224

Closed Joey-Xue closed 9 months ago

Joey-Xue commented 9 months ago

By following the simple workflow I get this AttributeError: `AttributeError Traceback (most recent call last) Cell In[72], line 1 ----> 1 stat_res_CD.lfc_shrink()

File ~/anaconda3/lib/python3.11/site-packages/pydeseq2/ds.py:393, in DeseqStats.lfc_shrink(self, coeff) 391 # Set priors 392 prior_no_shrink_scale = 15 --> 393 prior_var = self._fit_prior_var(coeff_idx=coeff_idx) 394 prior_scale = np.minimum(np.sqrt(prior_var), 1) 396 design_matrix = self.design_matrix.values

File ~/anaconda3/lib/python3.11/site-packages/pydeseq2/ds.py:630, in DeseqStats._fit_prior_var(self, coeff_idx, min_var, max_var) 628 keep = ~self.LFC.iloc[:, coeff_idx].isna() 629 S = self.LFC[keep].iloc[:, coeff_idx] 2 --> 630 D = self.SE[keep] 2 632 def objective(a: float) -> float: 633 # Equation to solve 634 coeff = 1 / (2 * (a + D) ** 2)

AttributeError: 'DeseqStats' object has no attribute 'SE'`

BorisMuzellec commented 9 months ago

Hi @Joey-Xue, did you run stat_res_CD.summary() or stat_res_CD.run_wald_test() before calling lfc_shrink?

SE is an estimate of the standard error of the log-fold changes that is computed when running Wald tests.

Joey-Xue commented 9 months ago

Thanks Boris, that solves my question! I wasn't aware wald test is necessary before lfc shrinkage.

BorisMuzellec commented 9 months ago

You're welcome!