owkin / PyDESeq2

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

[BUG] tuple index out of range #259

Closed jsgounot closed 5 months ago

jsgounot commented 5 months ago

Hi,

I got this error when calling dds.deseq2 on my data:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[15], line 1
----> 1 dds.deseq2()

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/pydeseq2/dds.py:453, in DeseqDataSet.deseq2(self)
    448 self.calculate_cooks()
    450 if self.refit_cooks:
    451     # Replace outlier counts, and refit dispersions and LFCs
    452     # for genes that had outliers replaced
--> 453     self.refit()

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/pydeseq2/dds.py:871, in DeseqDataSet.refit(self)
    864     print(
    865         f"Replacing {sum(self.varm['replaced']) } outlier genes.\n",
    866         file=sys.stderr,
    867     )
    869 if sum(self.varm["replaced"]) > 0:
    870     # Refit dispersions and LFCs for genes that had outliers replaced
--> 871     self._refit_without_outliers()
    872 else:
    873     # Store the fact that no sample was refitted
    874     self.varm["refitted"] = np.full(
    875         self.n_vars,
    876         False,
    877     )

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/pydeseq2/dds.py:1063, in DeseqDataSet._refit_without_outliers(self)
   1061     sub_dds.uns["mean_disp"] = self.uns["mean_disp"]
   1062 sub_dds.varm["_normed_means"] = sub_dds.layers["normed_counts"].mean(0)
-> 1063 sub_dds.varm["fitted_dispersions"] = sub_dds.disp_function(
   1064     sub_dds.varm["_normed_means"]
   1065 )
   1067 # Estimate MAP dispersions.
   1068 # Note: the prior variance is not recomputed.
   1069 sub_dds.uns["_squared_logres"] = self.uns["_squared_logres"]

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:199, in AlignedActualMixin.__setitem__(self, key, value)
    198 def __setitem__(self, key: str, value: V):
--> 199     value = self._validate_value(value, key)
    200     self._data[key] = value

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:268, in AxisArraysBase._validate_value(self, val, key)
    266         msg = "Index.equals and pd.testing.assert_index_equal disagree"
    267         raise AssertionError(msg)
--> 268 return super()._validate_value(val, key)

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:72, in AlignedMapping._validate_value(self, val, key)
     65     warn_once(
     66         "Support for Awkward Arrays is currently experimental. "
     67         "Behavior may change in the future. Please report any issues you may encounter!",
     68         ExperimentalFeatureWarning,
     69         # stacklevel=3,
     70     )
     71 for i, axis in enumerate(self.axes):
---> 72     if self.parent.shape[axis] == dim_len(val, i):
     73         continue
     74     right_shape = tuple(self.parent.shape[a] for a in self.axes)

File ~/anaconda3/envs/pydeseq2/lib/python3.12/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
    905 if not args:
    906     raise TypeError(f'{funcname} requires at least '
    907                     '1 positional argument')
--> 909 return dispatch(args[0].__class__)(*args, **kw)

File ~/anaconda3/envs/pydeseq2/lib/python3.12/site-packages/anndata/utils.py:109, in dim_len(x, axis)
    102 @singledispatch
    103 def dim_len(x, axis):
    104     """\
    105     Return the size of an array in dimension `axis`.
    106 
    107     Returns None if `x` is an awkward array with variable length in the requested dimension.
    108     """
--> 109     return x.shape[axis]

IndexError: tuple index out of range

Install with conda Pandas version is 2.2.1 PyDeSeq2 version is 0.4.7

I don't have this error when running the same function on the test data from the tutorial.

Any idea how to resolve this?

Thanks, JSG

BorisMuzellec commented 5 months ago

Hi @jsgounot, this bug is probably the one that we're currently fixing in #253 (the same as #251 and #249). I'll try to merge this PR and make a new package release soon.

BorisMuzellec commented 5 months ago

Fixed in #253

jspaezp commented 5 months ago

@BorisMuzellec Thanks a lot for fixing the bug! What version will have this fix incorporated?

BorisMuzellec commented 5 months ago

@jspaezp v0.4.8 is now available

jspaezp commented 5 months ago

you rock, thanks a lot!