bulk-wgcna-analysis-with-omicverse

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Bulk WGCNA analysis with omicverse

基于omicverse的批量WGCNA分析

Overview

概述

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.
当用户需要复现
t_wgcna.ipynb
中的WGCNA工作流时,可启用此技能。它将引导你完成表达数据加载、PyWGCNA配置、加权基因共表达网络构建以及目标模块检查等步骤。

Instructions

操作步骤

  1. Prepare the environment
    • Import
      omicverse as ov
      ,
      scanpy as sc
      ,
      matplotlib.pyplot as plt
      , and
      pandas as pd
      .
    • Set plotting defaults via
      ov.plot_set()
      .
  2. Load and filter expression data
    • Read expression matrices (e.g., from
      expressionList.csv
      ).
    • Calculate median absolute deviation with
      from statsmodels import robust
      and
      gene_mad = data.apply(robust.mad)
      .
    • Keep the top variable genes (e.g.,
      data = data.T.loc[gene_mad.sort_values(ascending=False).index[:2000]]
      ).
  3. Initialise PyWGCNA
    • Create
      pyWGCNA_5xFAD = ov.bulk.pyWGCNA(name=..., species='mus musculus', geneExp=data.T, outputPath='', save=True)
      .
    • Confirm
      pyWGCNA_5xFAD.geneExpr
      looks correct before proceeding.
  4. Preprocess the dataset
    • Run
      pyWGCNA_5xFAD.preprocess()
      to drop low-expression genes and problematic samples.
  5. Construct the co-expression network
    • Evaluate soft-threshold power:
      pyWGCNA_5xFAD.calculate_soft_threshold()
      .
    • Build adjacency and TOM matrices via
      calculating_adjacency_matrix()
      and
      calculating_TOM_similarity_matrix()
      .
  6. Detect gene modules
    • Generate dendrograms and modules:
      calculate_geneTree()
      ,
      calculate_dynamicMods(kwargs_function={'cutreeHybrid': {...}})
      .
    • Derive module eigengenes with
      calculate_gene_module(kwargs_function={'moduleEigengenes': {'softPower': 8}})
      .
    • Visualise adjacency/TOM heatmaps using
      plot_matrix(save=False)
      if needed.
  7. Inspect specific modules
    • Extract genes from modules with
      get_sub_module([...], mod_type='module_color')
      .
    • Build sub-networks using
      get_sub_network(mod_list=[...], mod_type='module_color', correlation_threshold=0.2)
      and plot them via
      plot_sub_network(...)
      .
  8. Update sample metadata for downstream analyses
    • Load sample annotations
      updateSampleInfo(path='.../sampleInfo.csv', sep=',')
      .
    • Assign colour maps for metadata categories with
      setMetadataColor(...)
      .
  9. Analyse module–trait relationships
    • Run
      analyseWGCNA()
      to compute module–trait statistics.
    • Plot module eigengene heatmaps and bar charts with
      plotModuleEigenGene(module, metadata, show=True)
      and
      barplotModuleEigenGene(...)
      .
  10. Find hub genes
    • Identify top hubs per module using
      top_n_hub_genes(moduleName='lightgreen', n=10)
      .
  11. Troubleshooting tips
    • Large datasets may require increasing
      save=False
      to avoid writing many intermediate files.
    • If module detection fails, confirm enough genes remain after MAD filtering and adjust
      deepSplit
      or
      softPower
      .
    • Ensure metadata categories have assigned colours before plotting eigengene heatmaps.
  1. 环境准备
    • 导入
      omicverse as ov
      scanpy as sc
      matplotlib.pyplot as plt
      pandas as pd
      库。
    • 通过
      ov.plot_set()
      设置绘图默认参数。
  2. 加载并过滤表达数据
    • 读取表达矩阵(例如来自
      expressionList.csv
      文件)。
    • 导入
      statsmodels
      robust
      模块,通过
      gene_mad = data.apply(robust.mad)
      计算中位数绝对偏差。
    • 保留变异程度最高的基因(例如
      data = data.T.loc[gene_mad.sort_values(ascending=False).index[:2000]]
      )。
  3. 初始化PyWGCNA
    • 创建PyWGCNA实例:
      pyWGCNA_5xFAD = ov.bulk.pyWGCNA(name=..., species='mus musculus', geneExp=data.T, outputPath='', save=True)
    • 继续操作前确认
      pyWGCNA_5xFAD.geneExpr
      数据格式正确。
  4. 数据集预处理
    • 运行
      pyWGCNA_5xFAD.preprocess()
      ,剔除低表达基因和异常样本。
  5. 构建共表达网络
    • 计算软阈值:
      pyWGCNA_5xFAD.calculate_soft_threshold()
    • 通过
      calculating_adjacency_matrix()
      calculating_TOM_similarity_matrix()
      构建邻接矩阵和TOM矩阵。
  6. 检测基因模块
    • 生成树状图和模块:
      calculate_geneTree()
      calculate_dynamicMods(kwargs_function={'cutreeHybrid': {...}})
    • 通过
      calculate_gene_module(kwargs_function={'moduleEigengenes': {'softPower': 8}})
      推导模块特征基因。
    • 若需要,使用
      plot_matrix(save=False)
      可视化邻接/TOM热图。
  7. 检查特定模块
    • 通过
      get_sub_module([...], mod_type='module_color')
      提取模块中的基因。
    • 使用
      get_sub_network(mod_list=[...], mod_type='module_color', correlation_threshold=0.2)
      构建子网络,并通过
      plot_sub_network(...)
      绘制子网络图。
  8. 更新样本元数据以用于下游分析
    • 加载样本注释信息:
      updateSampleInfo(path='.../sampleInfo.csv', sep=',')
    • 通过
      setMetadataColor(...)
      为元数据类别分配颜色映射。
  9. 分析模块与性状的关联
    • 运行
      analyseWGCNA()
      计算模块与性状的统计关系。
    • 使用
      plotModuleEigenGene(module, metadata, show=True)
      barplotModuleEigenGene(...)
      绘制模块特征基因热图和柱状图。
  10. 寻找枢纽基因
    • 通过
      top_n_hub_genes(moduleName='lightgreen', n=10)
      识别每个模块中的顶级枢纽基因。
  11. 故障排除提示
    • 处理大型数据集时,可设置
      save=False
      以避免生成过多中间文件。
    • 若模块检测失败,确认MAD过滤后剩余足够数量的基因,并调整
      deepSplit
      softPower
      参数。
    • 绘制特征基因热图前,确保已为元数据类别分配颜色。

Examples

示例

  • "Build a WGCNA network on the 5xFAD dataset, visualise modules, and extract hub genes from the lightgreen module."
  • "Load sample metadata, update colours for sex and genotype, and plot module eigengene heatmaps."
  • "Create a sub-network plot for the gold module using a correlation threshold of 0.2."
  • "基于5xFAD数据集构建WGCNA网络,可视化模块并提取lightgreen模块中的枢纽基因。"
  • "加载样本元数据,更新性别和基因型的颜色配置,并绘制模块特征基因热图。"
  • "以0.2为相关阈值,绘制gold模块的子网络图。"

References

参考资料

  • Tutorial notebook:
    t_wgcna.ipynb
  • Tutorial dataset:
    data/5xFAD_paper/
  • Quick copy/paste commands:
    reference.md
  • 教程笔记本:
    t_wgcna.ipynb
  • 教程数据集:
    data/5xFAD_paper/
  • 快速复制命令:
    reference.md