mortazavilab / PyWGCNA

PyWGCNA is a Python package designed to do Weighted Gene Correlation Network analysis (WGCNA)
https://academic.oup.com/bioinformatics/advance-article/doi/10.1093/bioinformatics/btad415/7218311
MIT License
209 stars 48 forks source link

local variable 'merge' referenced before assignment #43

Closed zEpoch closed 1 year ago

zEpoch commented 1 year ago

when running pyWGCNA_5xFAD.runWGCNA() `--------------------------------------------------------------------------- UnboundLocalError Traceback (most recent call last) Cell In [8], line 1 ----> 1 pyWGCNA_5xFAD.runWGCNA()

File /opt/software/python/lib/python3.8/site-packages/PyWGCNA/wgcna.py:353, in WGCNA.runWGCNA(self) 348 """ 349 Preprocess and find modules 350 """ 351 WGCNA.preprocess(self) --> 353 WGCNA.findModules(self) 355 return self

File /opt/software/python/lib/python3.8/site-packages/PyWGCNA/wgcna.py:337, in WGCNA.findModules(self, **kwargs) 334 self.datExpr.var['moduleLabels'] = [colorOrder.index(x) if x in colorOrder else None for x in 335 self.datExpr.var['moduleColors']] 336 # Eigengenes of the new merged modules: --> 337 self.MEs = merge['newMEs'] 339 # Recalculate MEs with color labels 340 self.datME = WGCNA.moduleEigengenes(self.datExpr.to_df(), self.datExpr.var['moduleColors'])['eigengenes']

UnboundLocalError: local variable 'merge' referenced before assignment`

nargesr commented 1 year ago

Hi,

Could you give me more information about how you got this error? for example which version of PyWGCNA did you run? did you change any default parameters? if yes, which one? What was your input?

marie-minaeva commented 1 year ago

Hey,

I encountered the same error. My PyWGCNA version is 1.16.8. Could it be due to the only 1 identified module in the network? As input, I had the preprocessed sc expression as a pd.DataFrame with genes as columns and cells as rows Code I run:

exp_mat = pd.read_csv(dataset_path, index_col=0, header=0)
network = PyWGCNA.WGCNA(name='coexpression', geneExp=exp_mat)
network.findModules()
image

And the Error I get:

Traceback (most recent call last):
  File "~/.local/lib/python3.10/site-packages/PyWGCNA/wgcna.py", line 337, in findModules
    self.MEs = merge['newMEs']
UnboundLocalError: local variable 'merge' referenced before assignment
nargesr commented 1 year ago

Hi,

The latest version is 1.2.4. Please install that one. Also, check the exact version of all the other dependencies here.

If you got the same error please send me your pickle object.

marie-minaeva commented 1 year ago

Hey! I tried with the latest version and got the same error. Here is the pickle object: coexpression.p.tar.gz

nargesr commented 1 year ago

Hi @marie-minaeva

I wasn't able to read your pickle file. please make sure that you can read it through PyWGCNA.readWGCNA() and resend it again

marie-minaeva commented 1 year ago

Hi @nargesr, Here is the new object. I additionally gzipped since GitHub doesn't allow sending .p files. Thanks! coexpression.p.gz

nargesr commented 1 year ago

Hi,

This is because you ended up with having only one modules. I'll add warning at the end to avoid this error in future and give you warning instead of that