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
194 stars 47 forks source link

Error in analyseWGCNA()---color #41

Closed ZivTQ closed 1 year ago

ZivTQ commented 1 year ago

Hi When I run pywgcna.analyseWGCNA(), I got this error: -> 4439 colors = mcolors.to_rgba_array(c) ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not array(['darkviolet', 'darkviolet', 'darkvio

However, the file of sample info and color setting was same with the files in Quick start. How can I solve this problem?

Thank you so much!

nargesr commented 1 year ago

Hi,

please make sure you have the latest version and if you still got that error would you mind sharing with me your picke file and the script you used?

ZivTQ commented 1 year ago

Hi,

please make sure you have the latest version and if you still got that error would you mind sharing with me your picke file and the script you used?

Hi I have installed pYWGCNA1.2.3. Previous error have solved. The data link mentioned in https://github.com/mortazavilab/PyWGCNA/issues/39#issuecomment-1546492332

Thank you so much

nargesr commented 1 year ago

Hi,

For pywgcna.analyseWGCNA(), you need to add your data trait and colormap like the tutorials.

I don't have your data trait and the script you used. would you mind giving me some insight of those things?

Thanks

ZivTQ commented 1 year ago

Hi, thanks for response the trait data was arranged like tutorials. a dataframe like this:

sample_id group oocyte1 oocyte oocyte2 oocyte oocyte3 oocyte pronuclear1 pronuclear pronuclear2 pronuclear pronuclear3 pronuclear zygote1 zygote zygote2 zygote 2_cell1 2_cell 2_cell2 2_cell 2_cell3 2_cell 4_cell1 4_cell 4_cell2 4_cell 4_cell3 4_cell 4_cell4 4_cell 8_cell1 8_cell 8_cell2 8_cell 8_cell3 8_cell 8_cell4 8_cell 8_cell5 8_cell 8_cell6 8_cell 8_cell7 8_cell 8_cell8 8_cell 8_cell9 8_cell 8_cell10 8_cell 8_cell11 8_cell morula1 morula morula2 morula morula3 morula

The color set was copy from the tutorials.

test.setMetadataColor('stage', ['oocyte': 'darkviolet',
                                'pronuclear': 'deeppink',
                                'zygote': 'thistle',
                                '2cell': 'plum',
                               '4cell': 'violet',
                                '8cell': 'purple',
                                'morula':'red'])

Thank you

nargesr commented 1 year ago

Again, I was able to run PyWGNA without any problem!

I attached my script below. Please read the tutorials more carefully :) i.e. your color map should be a dictionary, not a list. Or the name of the color map should match to the one the column names but in your case, your column name is group but you specify stage in the setMetadataColor() function.

import PyWGCNA
import pandas as pd

tpm = pd.read_csv('GSE44183_human_expression_mat.txt', sep='\t', index_col=0).T

test = PyWGCNA.WGCNA(name='test',
                     species='mus musculus', 
                     geneExp=tpm, 
                     outputPath='',
                     save=True)

test.preprocess()
test.findModules()

sampleInfo = test.datExpr.obs.copy(deep=True)
sampleInfo['group'] = sampleInfo.index.tolist()
sampleInfo.group[sampleInfo.group.str.contains('oocyte')] = 'oocyte'
sampleInfo.group[sampleInfo.group.str.contains('pronuclear')] = 'pronuclear'
sampleInfo.group[sampleInfo.group.str.contains('zygote')] = 'zygote'
sampleInfo.group[sampleInfo.group.str.contains('2 cell')] = '2 cell'
sampleInfo.group[sampleInfo.group.str.contains('4 cell')] = '4 cell'
sampleInfo.group[sampleInfo.group.str.contains('8 cell')] = '8 cell'
sampleInfo.group[sampleInfo.group.str.contains('morula')] = 'morula'

test.updateSampleInfo(sampleInfo=sampleInfo)

test.setMetadataColor('group', {'oocyte': 'darkviolet',
                                'pronuclear': 'deeppink',
                                'zygote': 'thistle',
                                '2 cell': 'plum',
                               '4 cell': 'violet',
                                '8 cell': 'purple',
                                'morula':'red'})

test.analyseWGCNA()