Hello!
I ran into trouble when having multiple wgcna experiments in one object where the modules (from GetModules()) are all the same across different ConstructNetwork() runs, leading to errors in PlotDendrogram() as the colors do not match. I believe this is the bug and fix.
Describe the bug
ConstructNetwork() saves $wgcna_modules from the wgcna experiment that is named in active_wgcna rather than the one specified by the wgcna_name parameter in the function.
Existing code
# set the modules df in the Seurat object
mods <- GetNetworkData(seurat_obj)$colors
seurat_obj <- SetModules(
seurat_obj, modules = data.frame(
"gene_name" = names(mods),
"module" = factor(mods, levels=unique(mods)),
"color" = mods
), wgcna_name
)
Suggested fix
# set the modules df in the Seurat object
mods <- GetNetworkData(seurat_obj, wgcna_name)$colors #added wgcna_name
seurat_obj <- SetModules(
seurat_obj, modules = data.frame(
"gene_name" = names(mods),
"module" = factor(mods, levels=unique(mods)),
"color" = mods
), wgcna_name
)