WGCNA co-expression network: soft-threshold, module detection, eigengenes, hub genes, and trait correlation in OmicVerse.
Activate this skill for users who want to reproduce the WGCNA workflow from t_wgcna.ipynb. It guides you through loading expression data, configuring PyWGCNA, constructing weighted gene co-expression networks, and inspecting modules of interest.
omicverse as ov, scanpy as sc, matplotlib.pyplot as plt, and pandas as pd.ov.plot_set().expressionList.csv).from statsmodels import robust and gene_mad = data.apply(robust.mad).data = data.T.loc[gene_mad.sort_values(ascending=False).index[:2000]]).pyWGCNA_5xFAD = ov.bulk.pyWGCNA(name=..., species='mus musculus', geneExp=data.T, outputPath='', save=True).pyWGCNA_5xFAD.geneExpr looks correct before proceeding.pyWGCNA_5xFAD.preprocess() to drop low-expression genes and problematic samples.pyWGCNA_5xFAD.calculate_soft_threshold().calculating_adjacency_matrix() and calculating_TOM_similarity_matrix().calculate_geneTree(), calculate_dynamicMods(kwargs_function={'cutreeHybrid': {...}}).calculate_gene_module(kwargs_function={'moduleEigengenes': {'softPower': 8}}).plot_matrix(save=False) if needed.get_sub_module([...], mod_type='module_color').get_sub_network(mod_list=[...], mod_type='module_color', correlation_threshold=0.2) and plot them via plot_sub_network(...).updateSampleInfo(path='.../sampleInfo.csv', sep=',').setMetadataColor(...).analyseWGCNA() to compute module–trait statistics.plotModuleEigenGene(module, metadata, show=True) and barplotModuleEigenGene(...).top_n_hub_genes(moduleName='lightgreen', n=10).# Before WGCNA: verify enough genes remain after MAD filtering
assert data.shape[0] >= 1000, f"Only {data.shape[0]} genes after filtering — WGCNA needs >1000 for meaningful modules"
# Verify expression values are numeric and non-negative
assert data.dtypes.apply(lambda d: d.kind in 'iuf').all(), "Expression matrix contains non-numeric columns"
# Verify enough samples for network construction
assert data.shape[1] >= 6, f"Only {data.shape[1]} samples — WGCNA needs >=6 samples for reliable co-expression"
save=False to avoid writing many intermediate files.deepSplit or softPower.t_wgcna.ipynbdata/5xFAD_paper/reference.md