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

fitType = local for vst function #154

Open jairaj-mathur opened 1 year ago

jairaj-mathur commented 1 year ago

Is your feature request related to a problem? Please describe. vst doent have 'local' as a fitType option

Describe the solution you'd like If vst could also have local as an option, that would be great

Describe alternatives you've considered Alternatively, I just import my code into R and do it from there

victorsanchezarevalo commented 3 months ago

Description

I am encountering consistent convergence issues when trying to fit the dispersion curve using the vst_fit function in the PyDESeq2 package. These issues occur regardless of whether I use the full design matrix or not.

Steps to Reproduce

  1. Load data into a DESeqDataSet object dds.
  2. Attempt to fit dispersion using dds.vst_fit(use_design=True) and dds.vst_fit(use_design=False).
  3. Both methods trigger a warning and fail to converge.
  4. Attempt to apply the VST transformation with dds.vst().

Expected Behavior

I expect the dispersion fitting process to converge properly so that I can proceed with applying the variance stabilizing transformation.

Actual Behavior

Both attempts to fit the dispersion with use_design=True and use_design=False result in warnings and do not converge. Subsequently, when attempting to apply the VST transformation directly using dds.vst(), another runtime error is triggered:

  1. When using use_design=True: /home/vjsanchez/miniforge3/envs/pydeseq2/lib/python3.10/site-packages/pydeseq2/dds.py:363: UserWarning: The dispersion trend curve fitting did not converge. Switching to a mean-based dispersion trend. self._fit_parametric_dispersion_trend(vst=True)

  2. When using use_design=False: Fitting dispersions... done in 20.00 seconds. /home/vjsanchez/miniforge3/envs/pydeseq2/lib/python3.10/site-packages/pydeseq2/dds.py:381: UserWarning: The dispersion trend curve fitting did not converge. Switching to a mean-based dispersion trend. self._fit_parametric_dispersion_trend(vst=True)

  3. Error upon calling dds.vst(): /home/vjsanchez/miniforge3/envs/pydeseq2/lib/python3.10/site-packages/pydeseq2/dds.py:333 in vst self.layers["vst_counts"] = self.vst_transform()

/home/vjsanchez/miniforge3/envs/pydeseq2/lib/python3.10/site-packages/pydeseq2/dds.py:435 in vst_transform raise RuntimeError("Fit the dispersion curve prior to applying VST.")

RuntimeError: Fit the dispersion curve prior to applying VST.

Additional Information

Thank you for your assistance!

vcabeli commented 3 months ago

Sorry for the delay @victorsanchezarevalo, it seems like you are indeed having problems with the parametric fit. Try using dds.vst(fit_type = 'mean')

victorsanchezarevalo commented 3 months ago

Solved, Thank you very much!