PyWGCNA icon indicating copy to clipboard operation
PyWGCNA copied to clipboard

Error with function analyseWGCNA()

Open GERMAN00VP opened this issue 1 year ago • 3 comments

HI I AM TRYING TO FIND THE CORRELATION OF THE MODULES OF MY WGCNA OBJECT WITH THE TRAITS OF MY METADATA , BUT I GET THE FOLLOWING ERROR, DO ANYONE KNOW HOW TO SOLVE IT? THANK YOU.

pyWGCNA_TCGA_PAAD.analyseWGCNA()

Analysing WGCNA... Calculating module trait relationship ... Done..

Adding (signed) eigengene-based connectivity (module membership) ... Done..

plotting module heatmap eigengene... Done..

plotting module barplot eigengene...

ValueError Traceback (most recent call last) Cell In[10], line 1 ----> 1 pyWGCNA_TCGA_PAAD.analyseWGCNA()

File ~/miniconda3/envs/machine_learning/lib/python3.11/site-packages/PyWGCNA/wgcna.py:447, in WGCNA.analyseWGCNA(self, order, geneList, show) 445 print(f"{OKCYAN}plotting module barplot eigengene...{ENDC}") 446 for module in modules: --> 447 self.barplotModuleEigenGene(module, metadata, colorBar=metadata[-1], show=True) 448 print("\tDone..\n") 450 if self.save:

File ~/miniconda3/envs/machine_learning/lib/python3.11/site-packages/PyWGCNA/wgcna.py:2946, in WGCNA.barplotModuleEigenGene(self, moduleName, metadata, combine, colorBar, show) 2944 df['all'] = df['all'].apply(lambda x: x[1:]) 2945 cat = pd.DataFrame(pd.unique(df['all']), columns=['all']) -> 2946 cat[metadata] = cat['all'].str.split('_', expand=True) 2947 ybar = df[['all', 'eigengeneExp']].groupby(['all']).mean()['eigengeneExp'] 2948 ebar = df[['all', 'eigengeneExp']].groupby(['all']).std()['eigengeneExp']

File ~/miniconda3/envs/machine_learning/lib/python3.11/site-packages/pandas/core/frame.py:3968, in DataFrame.setitem(self, key, value) 3966 self._setitem_frame(key, value) 3967 elif isinstance(key, (Series, np.ndarray, list, Index)): -> 3968 self._setitem_array(key, value) 3969 elif isinstance(value, DataFrame): 3970 self._set_item_frame_value(key, value) ... 402 else: 403 # Missing keys in columns are represented as -1 404 if len(columns.get_indexer_non_unique(key)[0]) != len(value.columns):

ValueError: Columns must be same length as key

GERMAN00VP avatar Jun 21 '23 10:06 GERMAN00VP

Hi,

did you add your metadata using updateSampleInfo()? can you tell me what's in the pyWGCNA_TCGA_PAAD.datExpr.obs?

nargesr avatar Jun 21 '23 18:06 nargesr

Yes I did update the sample and gene info following all the steps of the quick start tutorial up to the one wich gave me the error. I will upload a photo of the pyWGCNA_TCGA_PAAD.datExpr.obs dataframe and the sample info file so that you can explore the metadata I am using. Thank you for your time and answers.

sampleInfo.csv

image

GERMAN00VP avatar Jun 22 '23 09:06 GERMAN00VP

oh, it's probably because you have a dash in your column name like "Cluster_0" I will try to fix this problem but meanwhile, if you can change your column names to be dash-free, it will probably solve your problem for now

Thank you for catching that! I'll try to see how I can fix that :)

nargesr avatar Jun 22 '23 19:06 nargesr