WGCNA 分析


2021.9.28 参考了生信技能树的教程
第一次学习WGCNA 分析(这个属于单细胞高级分析)
还有细节未探究,WGCNA+GO+KEGG功能注释

参考:
https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/
https://cloud.tencent.com/developer/article/1516749
https://zhuanlan.zhihu.com/p/388190968
https://www.jianshu.com/p/817d492d4904
https://mp.weixin.qq.com/s?__biz=MzAxMDkxODM1Ng==&mid=2247491248&idx=1&sn=afb11345a1e89cd57ace7dcf827dddbf&scene=21#wechat_redirect

#应用场景:
1.找到模块的核心基因

2.利用关系预测基因功能

#一般流程:
image.png
得到模块之后的分析有:
1.模块的功能富集

2.模块与性状之间的相关性

3.模块与样本间的相关系数

#主要函数:

### 计算邻接矩阵
adjacency = adjacency(dataExpr, power = power)

### 把邻接矩阵转换为拓扑重叠矩阵,以降低噪音和假相关,获得距离矩阵。
TOM = TOMsimilarity(adjacency)
dissTOM = 1-TOM

### 层级聚类计算基因之间的距离树 
geneTree = hclust(as.dist(dissTOM), method = "average")

### 模块合并
# We like large modules, so we set the minimum module size relatively high:
minModuleSize = 30
# Module identification using dynamic tree cut:
dynamicMods = cutreeDynamic(dendro = geneTree, distM = dissTOM,
                            deepSplit = 2, pamRespectsDendro = FALSE,
                            minClusterSize = minModuleSize)
# Convert numeric lables into colors
dynamicColors = labels2colors(dynamicMods)

### 通过计算模块的代表性模式和模块之间的定量相似性评估,合并表达图谱相似
的模块
MEList = moduleEigengenes(datExpr, colors = dynamicColors)
MEs = MEList$eigengenes
# Calculate dissimilarity of module eigengenes
MEDiss = 1-cor(MEs)
# Cluster module eigengenes
METree = hclust(as.dist(MEDiss), method = "average")
MEDissThres = 0.25

# Call an automatic merging function
merge = mergeCloseModules(datExpr, dynamicColors, cutHeight = MEDissThres, verbose = 3)
# The merged module colors
mergedColors = merge$colors;
# Eigengenes of the new merged

#基本概念

  • Module
    模块(module):表达模式相似的基因分为一类,这样的一类基因成为模块;
  • Eigengene
    Eigengene(eigen + gene):基因和样本构成的矩阵,https://en.wiktionary.org/wiki/eigengene
  • Adjacency Matrix
    邻近矩阵:是图的一种存储形式,用一个一维数组存放图中所有顶点数据;用一个二维数组存放顶点间关系(边或弧)的数据,这个二维数组称为邻接矩阵;在WGCNA分析里面指的是基因与基因之间的相关性系数矩阵。 如果用了阈值来判断基因相关与否,那么这个邻近矩阵就是0/1矩阵,只记录基因相关与否。但是WGCNA没有用阈值来卡基因的相关性,而是记录了所有基因之间的相关性。
  • Topological Overlap Matrix (TOM)
    利用上面的邻近矩阵,又计算了一个新的邻近矩阵。一般来说,TOM就是WGCNA分析的最终结果,后续的只是对TOM的下游注释。

#原理解析:
image.png
#Soft Threshold ?Hard Threshold?
网络中基因与基因之间是否连边取决于这两个基因是否发生显著共表达:nodes represent genes and nodes are connected if the corresponding genes are significantly co-expressed across appropriately chosen tissue samples

皮尔森相关系数(Pearson) correlation coefficient:It is standard to use the (Pearson) correlation coefficient as a co-expression measure, e.g., the absolute value of Pearson correlation is often used in a gene expression cluster analysis.

那么现在问题来了:我得到了两个基因的相关系数值之后,如何决定这两个基因在构建网络时是否连边呢?

1,定义一个阈值,比如有统计学意义的r>0.9,那么就连边;否则,就不连边。这个办法就是‘hard’ threshold,也即不加权(unweighted)。
2,真实网络与随机网络的特征差异
真实的生物学网络比如:
image.png

human disease network,
gene co-expression networks,
protein-protein interaction networks,
cell-cell interaction networks,
the world wide web and social interaction networks。

  • 真实网络服从幂率分布(power law) p(k)~ k−γ,即无标度网络(Scale-free networks)
    image.png

  • 随机网络一般服从泊松(Poisson)分布
    image.png

这两个网络分布的特点是:真实网络中绝大部分点的度都很低,只有少数的点(即常说的hub节点)度很高,而随机网络中绝大部分的点的度都处于上图中的峰值处,即度相似。

无标度网络节点的度分布特征使得它有一个很大的特点,那就是稳健性:随机去除网络中的一个节点,网络还能依然保持(绝大多数节点的度很低)。但是它也有脆弱的一面:那就是去除网络中的hub节点,网络就散了。但是hub节点只是网络中极少数的几个节点,被攻击的概率非常小。

基于以上,即‘hard’ threshold的缺点和应用于真实网络造成的信息丢失(参考文献中有说明)等原因,官网教程中的作者提出了一种方法即用‘soft’ thresholding 来权衡网络中的连边。

就是将相关系数的值[0,1]通过一个换算映射到[0,1],也即加权(weighted)的思想:

image.png

那么这里的参数β就是软阈值。


#如何选取Soft Threshold?
image.png
左图的纵坐标scale-free fit index,即signed R2,代表对应的网络中log(k)与log(p(k))相关系数的平方乘以一个方向向量,由slope决定(The sign of the scale-free model fitting index R2 is determined by minus the sign of the slope),拟合的线性方程为下图,来源于WNCGCNA包中的源代码:
相关系数的平方越高,说明该网络越逼近无标度网络的分布。相关参考文献中有大量数据证明当signed R2 大于0.85时,网络就已经符合无标度网络的分布。
因此,WGCNA包中计算SoftThreshold的函数pickSoftThreshold中RsquaredCut 默认值为 0.85,最佳的powers值保存在sft$powerEstimate。上图中,作者重新设定了一个阈值cex1=0.9,因此你会看到图片作图中有一条红色的横线,表示第一个signed R2达到这条红线时的最佳powers值,此图中是6。

右图的纵轴代表对应的网络中所有基因连接数(即节点的度)的均值。

image.png

这张图有三个部分:

1,聚类树:那么你对聚类方法又了解多少?
2,Dynamic Tree Cut:根据某一height,聚类树分成了多少类(也即模块)
3,Merged dynamic:合并后的聚类模块,那么又是根据什么指标要将Dynamic Tree Cut中的类别进行合并得到新的聚类模块呢?
根据最佳软阈值和表达谱数据首先计算得到一个邻接矩阵adjacency,然后将邻接矩阵转换为TOM矩阵再计算一个距离矩阵dissTOM,这个距离矩阵就是后面用来画聚类树的图。

  • 层次聚类

We now use hierarchical clustering to produce a hierarchical clustering tree (dendrogram) of genes. Note that we use the function hclust that provides a much faster hierarchical clustering routine than the standard hclust function.

geneTree = hclust(as.dist(dissTOM), method = "average");

采用的聚类方法为平均距离(method = “average”),
image.png
图片中,每一个树枝代表一个gene,纵坐标的Heigth为聚类距离。

设定一个聚类距离阈值,就可以将gene聚成module,这里又有很多方法设定这个阈值。而官网教程成给定的是dynamicTreeCut包中的函数cutreeDynamic,并且设定了最小模块中包含的基因个数为30个基因。

# We like large modules, so we set the minimum module size relatively high:
minModuleSize = 30;

# Module identification using dynamic tree cut:
dynamicMods = cutreeDynamic(dendro = geneTree, distM = dissTOM,
                deepSplit = 2, pamRespectsDendro = FALSE,
                minClusterSize = minModuleSize);

table(dynamicMods)

为了定量每一个模块的共表达相似性,这里计算了每一个模块的eigengenes,即每个模块的特征值。

# Calculate eigengenes
MEList = moduleEigengenes(datExpr, colors = dynamicColors)
MEs
### 如何在WGCNA分析中进行基因富集分析 #### 使用R语言中的`WGCNA`包进行加权基因共表达网络分析(WGCNA) 为了实现这一目标,首先需要安装并加载必要的软件包: ```r if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install(c("WGCNA", "clusterProfiler")) library(WGNCA) library(clusterProfiler) ``` #### 准备数据 准备用于构建网络的数据矩阵。此过程涉及读取原始计数数据,并可能对其进行标准化处理。 ```r # 加载样本数据作为示例 data <- read.csv('path/to/your/count_matrix.csv', row.names=1) # 转置使行代表样品而列代表探针 datExpr = as.data.frame(t(data)) ``` #### 构建模块特征节点(MEs) 通过软阈值化方法来确定最佳幂指数β,从而使得所选参数下的无尺度拓扑拟合指标达到最大值[^2]。 ```r softPower = pickSoftThreshold(datExpr, powerVector=c(1:20))[1,"SFTindex"] net = blockwiseModules( datExpr, power = softPower, TOMType="unsigned", minModuleSize=30, reassignThreshold=0, mergeCutHeight=0.25, numericLabels=TRUE, saveTOMs=FALSE, verbose=3 ) moduleColors = labels2colors(net$colors) table(moduleColors) MEs = moduleEigengenes(datExpr, net$colors)$eigengenes ``` #### 执行富集分析 完成上述步骤之后,可以针对每个识别出来的模块内的基因集合实施过表示分析(ORA)或基因集富集分析(GSEA)[^1]。 对于每一个感兴趣的模块,提取其成员基因ID列表,并调用相应的函数来进行功能注解和统计测试: ```r # 获取特定模块的基因名向量 geneNamesInBlueModule = names(MEs[,which(names(MEs)=='MEturquoise')]) # 进行GO富集分析 (以GO为例) ego <- enrichGO(gene = geneNamesInBlueModule, universe = colnames(datExpr), OrgDb = org.Hs.eg.db, ont = 'ALL', pAdjustMethod = 'BH') print(ego) dotplot(ego) barplot(ego) ``` 以上代码片段展示了如何利用`clusterProfiler`库对选定模块执行基于Gene Ontology数据库的功能分类富集检验。同样地,也可以替换其他类型的生物通路资源如KEGG Pathway等来进行更广泛的研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值