先码
WGCNA代码1:WGCNA分析,简单全面的最新教程
WGCNA代码2:WGCNA实战练习+离群点+随机选取基因TOM作图
clust = cutreeStatic(
sampleTree,
cutHeight = 15,
minSize = 10)
keepSamples = (clust==1)
datExpr = datExpr0[keepSamples, ]
nGenes = ncol(datExpr)
nSamples = nrow(datExpr)
————————————————
版权声明:本文为CSDN博主「weixin_43569478」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43569478/article/details/83747303
nSelect = 400
# For reproducibility, we set the random seed
set.seed(10);
select = sample(nGenes, size = nSelect);
selectTOM = dissTOM[select, select];
# There’s no simple way of restricting a clustering tree to a subset of genes, so we must re-cluster.
selectTree = hclust(as.dist(selectTOM), method = "average")
selectColors = moduleColors[select];
# Open a graphical window
sizeGrWindow(9,9)
# Taking the dissimilarity to a power, say 10, makes the plot more informative by effectively changing
# the color palette; setting the diagonal to NA also improves the clarity of the plot
plotDiss = selectTOM^7;
diag(plotDiss) = NA;
TOMplot(plotDiss, selectTree, selectColors, main = "Network heatmap plot, selected genes")
WGCNA代码3:WGCNA相关性分析+模块和性状
WGCNA代码4:WGCNA实例分析及解读+检验选定的β值下记忆网络是否逼近 scale free+hub gene
k <- softConnectivity(dataExpr,power=sft$powerEstimate)
sizeGrWindow(10, 5)
par(mfrow=c(1,2))
hist(k)
scaleFreePlot(k,main="Check Scale free topology\n")
#可以看出k与p(k)成负相关(相关性系数0.87),说明选择的β值能够建立基因无尺度网络
根据性状与模块特征向量基因的相关性及pvalue来挖掘与性状相关的模块
cor_ADR <- signif(WGCNA::cor(traitData,MEs,use="p",method="pearson"),5)
p.values <- corPvalueStudent(cor_ADR,nSamples=nrow(traitData))
Freq_MS_max_cor <- which.max(abs(cor_ADR["Insulin_ug_l",-which(colnames(cor_ADR) == "MEgrey")]))
Freq_MS_max_p <- which.min(p.values["Insulin_ug_l",-which(colnames(p.values) == "MEgrey")])
根据基因网络显著性,也就是性状与每个基因表达量相关性在各个模块的均值作为该性状在该模块的显著性,显著性最大的那个模块与该性状最相关:
GS1 <- as.numeric(WGCNA::cor(traitData[,'Insulin_ug_l'],dataExpr,use="p",method="pearson"))
GeneSignificance <- abs(GS1)
ModuleSignificance <- tapply(GeneSignificance,net$colors,mean,na.rm=T)
寻找与该性状相关的枢纽基因(hub genes),首先计算基因的内部连接度和模块身份,内部连接度衡量的是基因在模块内部的地位,而模块身份表明基因属于哪个模块。
WGCNA代码5:小张聊科研