smorabit / hdWGCNA

High dimensional weighted gene co-expression network analysis
https://smorabit.github.io/hdWGCNA/
Other
315 stars 31 forks source link

ModuleNetworkPlot for small networks #230

Closed DelongZHOU closed 2 months ago

DelongZHOU commented 2 months ago

Hello,

I found a bug regarding ModuleNetworkPlot function:

By default the function picks 10 genes for the inner circle, 15 genes for the outer circle and 500 interactions to plot, however this poses a problem for networks with fewer genes in it.

One of my modules only has 8 genes, so the default setting failed with error: Error in (function (cond) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': subscript out of bounds

I tried setting all 3 parameters to 1 but the error persists.

Would it be possible to auto adjust these flags for these outliers or skip them so the default function would skip the problematic ones and continue on the other modules?

Thank you! Delong

smorabit commented 2 months ago

Hi,

I don't recommend having modules that are this small. In ConstructNetwork, the default value for minModuleSize is 50. I think it becomes hard to interpret the modules if they are too small.

ModuleNetworkPlot already does have a check for if the number of genes is less then n_inner + 1, then it skips that module.

DelongZHOU commented 2 months ago

Hi Sam, Hmmm, interesting. I'm not changing the minModuleSize in ConstructNetwork, and still got some modules that are smaller than 50 genes. I remember having maybe 5 modules with < 25 genes from my ~300 modules. And ModuleNetworkPlot is not checking and skipping the modules with fewer genes in my case either. I'm updating the package and I'll let you know if it's still the case!

DelongZHOU commented 2 months ago

Hi again, I've updated to hdWGCNA_0.3.00, and I can confirm that the default ConstructNetwork still produces modules with <50 genes. ModuleNetworkPlot now reduces the n_outer when there is not enough genes. However two unexpected behaviors of ModuleNetworkPlot::mods flag: 1) when provided a vector, it produces error similar to the other issue I raised: Error in if (mods == "all") { : the condition has length > 1 2) when provided just one module, it will nevertheless go through all modules

smorabit commented 2 months ago

We can actually have modules smaller than the minimum module size because by default we re-assign some genes to other modules. The co-expression network and the modules are identified in the metacell dataset, but then we compute the kMEs in the single-cell dataset. In rare cases the single cell kME is a negative value, and in this case we re-assign those gene to the module that it has the highest kME with.

For your other error I was able to resolve it, can you update hdWGCNA and try it again?

DelongZHOU commented 2 months ago

Hi Sam, I can confirm the above mentioned issues are solved! Thank you!