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
217 stars 53 forks source link

ValueError in wgcna.findModules(): "Calling nonzero on 0d arrays is not allowed" #117

Closed victorsanchezarevalo closed 3 weeks ago

victorsanchezarevalo commented 3 months ago

Description:

I encountered a ValueError when running wgcna.findModules() in the PyWGCNA package. The error message suggests an issue with the use of numpy.where on a zero-dimensional array. Here are the details of the problem:

Steps to Reproduce:

  1. Run wgcna.findModules() with a specific dataset.
  2. Observe the output and error message.

wgcna.findModules() Run WGCNA... pickSoftThreshold: calculating connectivity for given powers... will use block size 1491 Power SFT.R.sq slope ... mean(k) median(k) max(k) 0 1 0.245852 -0.550696 ... 3118.490492 2868.675522 6003.385196 1 2 0.840003 -1.004286 ... 1135.820057 811.550063 3559.686787 2 3 0.840308 -1.131941 ... 557.662596 283.62912 2563.192822 3 4 0.846625 -1.18598 ... 324.106652 112.864826 1983.228952 4 5 0.818952 -1.240158 ... 208.563772 49.634045 1598.89383 5 6 0.796693 -1.291889 ... 143.431885 23.530828 1323.899871 6 7 0.797958 -1.322152 ... 103.344658 11.740467 1117.108275 7 8 0.784689 -1.360214 ... 77.087744 6.155413 956.116503 8 9 0.770516 -1.396398 ... 59.075362 3.304047 827.533549 9 10 0.769448 -1.420249 ... 46.267887 1.839607 722.791253 10 11 0.772916 -1.439936 ... 36.89603 1.059208 636.11797 11 13 0.784012 -1.457093 ... 24.507719 0.365683 501.910014 12 15 0.768855 -1.491664 ... 17.045103 0.138048 403.898136 13 17 0.760768 -1.514577 ... 12.289408 0.054256 330.121706 14 19 0.772045 -1.51046 ... 9.122662 0.022295 273.264863

[15 rows x 7 columns] No power detected to have scale free network! Found the best given power which is 4. calculating adjacency matrix ... Done..

calculating TOM similarity matrix ... Done..

Going through the merge tree... ..cutHeight not given, setting it to 0.994 ===> 99% of the (truncated) height range in dendro. Done..

Traceback (most recent call last):

Cell In[40], line 1 wgcna.findModules()

File ~/miniconda3/envs/pywgcna/lib/python3.10/site-packages/PyWGCNA/wgcna.py:335 in findModules self.datExpr.var['dynamicColors'] = WGCNA.labels2colors(labels=dynamicMods, **kwargs)

File ~/miniconda3/envs/pywgcna/lib/python3.10/site-packages/PyWGCNA/wgcna.py:1911 in labels2colors colors[np.where(not fin)[0].tolist()] = naColor

ValueError: Calling nonzero on 0d arrays is not allowed. Use np.atleast_1d(scalar).nonzero() instead. If the context of this error is of the form arr[nonzero(cond)], just use arr[cond].

Please let me know if more information is needed or if there are any workarounds available for this issue.

Thanks

Victor

nargesr commented 2 months ago

Hi @victorsanchezarevalo

Can you send me the script you used and also the version of the packages you used?

Also if you can send me the plots that were generated that would be good. PyWGCNA pickle file would be also a huge help but I completely understand if you don't want to share your data with me:)

if everything is okay, my assumption is that there is no grey module but need to check multiple things...

Best, Narges

victorsanchezarevalo commented 2 months ago

Thanks!

Could you provide me an email, please? I will send you everything including the file. Best

nargesr commented 2 months ago

Sure! here you go

nargesr@uci.edu

Shawn-Xu commented 2 months ago

I had the same error in the pyWGCNA_5xFAD.findModules() step. I just used the 5xFAD_paper demo data and run the quick start codes.

Shawn-Xu commented 2 months ago

I had the same error in the pyWGCNA_5xFAD.findModules() step. I just used the 5xFAD_paper demo data and run the quick start codes.

I rerolled the numpy version from 2.1.1 to 2.0.1. It works now. :)

nargesr commented 2 months ago

Thank you @Shawn-Xu for pointing this out.

I will release a new version that is compatible with the latest version of Numpy but that might take some time so meanwhile, if you can downgrade your Numpy that would be great

victorsanchezarevalo commented 2 months ago

Thank you very much @Shawn-Xu

nargesr commented 3 weeks ago

Hi @Shawn-Xu @victorsanchezarevalo

I released a new version (2.2.0) which should be compatible with the latest version of Numpy (2.1)

Please feel free to reopen this if you get the same error.

Best, Narges

victorsanchezarevalo commented 2 weeks ago

Thank you so much!

I have updated the package. PyWGCNA is an excellent work!

Best

Victor