Skip to content

Bug when anndata with non string values in obs used to initialize wgcna object#137

Open
JShermanK1 wants to merge 10 commits intomortazavilab:mainfrom
JShermanK1:main
Open

Bug when anndata with non string values in obs used to initialize wgcna object#137
JShermanK1 wants to merge 10 commits intomortazavilab:mainfrom
JShermanK1:main

Conversation

@JShermanK1
Copy link

@JShermanK1 JShermanK1 commented Feb 27, 2025

Hello,

Thank you for all the effort in making the PyWGCNA package, I frequently find it useful. That said, I encountered an error when including a column of integer values (timepoint) in the anndata.obs that I used to initialize the WGCNA object. When WGCNA.analyzeWGCNA() is called I get an error:

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not array(['#D62628', '#D62628', '#D62628', '#D62628', '2', '4', '4', '4',
       '4', '0', '0', '0', '0', '#D62628', '3', '3', '3', '3'],
      dtype='<U11')

I found that this occurs because the use of color = np.where(color == n, self.metadataColors[m][n], color). color starts as a numpy array of int, but when some of the values are replaced with the string values of the colors from metadataColors, the entire array is coerced to str type, which causes subsequent comparisons to n (an integer) to all be false.

I also hit a snag with elif type(colorBar) == dict: which causes all metadataColors to be treated as a ScalarMappable, but once I fixed that and cleaned up a few other things, I believe I was able to get everything working the way I expect, so I made this pull request. I don't have much experience with public pull requests, so if I'm missing anything please let me know.

Best regards,
John Sherman

@gitbenlewis
Copy link
Contributor

gitbenlewis commented Mar 4, 2025

A lot of changes here, I did not clone the entire fork. But I copied the primary changes and the changes work for me.

I tested the following that worked:

  • metadata keys (column names) with dash or underscore
  • metadata with values containing dash or underscore
  • metadata containing dtype: int64

module_trait_relationships_heatmap() produced a single row for the metadata key that contained integers but I think that is the expected behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments