原文地址:https://mp.weixin.qq.com/s/p-4-WerJ6m2F9b5Ie-cerA
? ? ? ? ? ? ? ? ? ? WGCNA和差異基因分析(DEG)的差異在于DEG主要分析樣本和樣本之間的差異,而WGCNA主要分析的是基因和基因之間的關(guān)系。WGCNA通過分析基因之間的關(guān)聯(lián)關(guān)系,將基因區(qū)分為多個(gè)模塊。而最后通過這些模塊和樣本表型之間的關(guān)聯(lián)性分析,尋找特定表型的分子特征。
網(wǎng)上例子千千萬(wàn),但是大部分都是從文檔翻譯而來,要用起來還是有些費(fèi)勁,要深入的可以移步這里:http://www.stat.wisc.edu/~yandell/statgen/ucla/WGCNA/wgcna.html
下面我將根據(jù)TCGA乳腺癌基因表達(dá)數(shù)據(jù)以及乳腺癌壓型數(shù)據(jù),一步一步的使用WGCNA來進(jìn)行乳腺癌各個(gè)亞型共表達(dá)模塊的挖掘
#############數(shù)據(jù)準(zhǔn)備#############
首先我們需要下載TCGA 的乳腺癌的RNA-seq數(shù)據(jù)以及臨床病理資料,我這里使用我們自己開發(fā)的TCGA簡(jiǎn)易下載工具進(jìn)行下載
首先下載RNA-Seq:
下載之后共得到1215個(gè)樣本表達(dá)數(shù)據(jù)
進(jìn)一步下載臨床病理資料
進(jìn)一步點(diǎn)擊
ClinicalFull按鈕對(duì)病理資料進(jìn)行提取得到ClinicalFull_matrix.txt文件,使用Excel打開ClinicalFull_matrix.txt文件可以看到共有301列信息,包含了各種用藥,隨訪,預(yù)后等等信息,我們這里選擇乳腺癌ER、PR、HER2的信息,去除其他用不上的信息,然后選擇了其中有明確ER、PR、HER2陽(yáng)性陰性的樣本,隨機(jī)拿100個(gè)做例子吧
樣本篩選完了,現(xiàn)在輪到怎么獲取這些樣本的RNA-seq數(shù)據(jù)啦,前面下載了一千多個(gè)樣本的RNA-seq,從里面找到這一百個(gè)樣本的表達(dá)數(shù)據(jù)其實(shí)也是不需要變成的啦,看清楚咯
首先打開RNA-Seq數(shù)據(jù)目錄的fileID.tmp(用Excel打開),然后可以看到兩列:
將第二列復(fù)制,并且替換-01.gz為空
使用Excel的vlookup命令將臨床病理資料的那100個(gè)樣本進(jìn)行映射
然后篩選非N/A的就得到了這一百個(gè)樣本對(duì)于的RNA-seq數(shù)據(jù)信息
進(jìn)一步刪除其他的樣本,還原成fileID.tmp格式保存退出:
然后使用TCGA簡(jiǎn)易小工具“合并文件”按鈕就得到表達(dá)矩陣了,進(jìn)一步使用ENSD_ID轉(zhuǎn)換按鈕就得到了基因表達(dá)矩陣和lncRNA表達(dá)矩陣了
#################R代碼實(shí)現(xiàn)WGCNA##############
setwd('E:/rawData/TCGA_DATA/TCGA-BRCA')
samples=read.csv('ClinicalFull_matrix.txt',sep = '\t',row.names = 1)
dim(samples)
#[1] 100 ? 3
expro=read.csv('Merge_matrix.txt.cv.txt',sep = '\t',row.names = 1)
dim(expro)
#[1] 24991 ? 100
數(shù)據(jù)讀取完成,從上述結(jié)果可以看出100個(gè)樣本,有24991個(gè)基因,這么多基因全部用來做WGCNA很顯然沒有必要,我們只要選擇一些具有代表性的基因就夠了,這里我們采取的方式是選擇在100個(gè)樣本中方差較大的那些基因(意味著在不同樣本中變化較大)
繼續(xù)命令:
m.vars=apply(expro,1,var)
expro.upper=expro[which(m.vars>quantile(m.vars, probs = seq(0, 1, 0.25))[4]),]##選擇方差最大的前25%個(gè)基因作為后續(xù)WGCNA的輸入數(shù)據(jù)集
通過上述步驟拿到了6248個(gè)基因的表達(dá)譜作為WGCNA的輸入數(shù)據(jù)集,進(jìn)一步的我們需要看看樣本之間的差異情況
datExpr=as.data.frame(t(expro.upper));
gsg = goodSamplesGenes(datExpr, verbose = 3);
gsg$allOK
sampleTree = hclust(dist(datExpr), method = "average")
plot(sampleTree, main = "Sample clustering to detect outliers"
, sub="", xlab="")
從圖中可看出大部分樣本表現(xiàn)比較相近,而有兩個(gè)離群樣本,對(duì)后續(xù)的分析可能造成影響,我們需要將其去掉,共得到98個(gè)樣本
clust = cutreeStatic(sampleTree, cutHeight = 80000, minSize = 10)
table(clust)
#clust
#0 ?1
#2 98
keepSamples = (clust==1)
datExpr = datExpr[keepSamples, ]
nGenes = ncol(datExpr)
nSamples = nrow(datExpr)
save(datExpr, file = "FPKM-01-dataInput.RData")
得到最終的數(shù)據(jù)矩陣之后,我們需要確定軟閾值,從代碼中可以看出pickSoftThreshold很簡(jiǎn)單,就兩個(gè)參數(shù),其他默認(rèn)即可
powers = c(c(1:10), seq(from = 12, to=20, by=2))
sft = pickSoftThreshold(datExpr, powerVector = powers, verbose = 5)
##畫圖##
par(mfrow = c(1,2));
cex1 = 0.9;
plot(sft$fitIndices[,1], -sign(sft$fitIndices[,3])*sft$fitIndices[,2],
xlab="Soft Threshold (power)",ylab="Scale Free Topology Model Fit,signed R^2",type="n",
main = paste("Scale independence"));
text(sft$fitIndices[,1], -sign(sft$fitIndices[,3])*sft$fitIndices[,2],
labels=powers,cex=cex1,col="red");
abline(h=0.90,col="red")
plot(sft$fitIndices[,1], sft$fitIndices[,5],
xlab="Soft Threshold (power)",ylab="Mean Connectivity", type="n",
main = paste("Mean connectivity"))
text(sft$fitIndices[,1], sft$fitIndices[,5], labels=powers, cex=cex1,col="red")
從圖中可以看出這個(gè)軟閾值選擇7比較合適,選擇軟閾值7進(jìn)行共表達(dá)模塊挖掘
pow=7
net = blockwiseModules(datExpr, power = pow, maxBlockSize = 7000,
TOMType = "unsigned", minModuleSize = 30,
reassignThreshold = 0, mergeCutHeight = 0.25,
numericLabels = TRUE, pamRespectsDendro = FALSE,
saveTOMs = TRUE,
saveTOMFileBase = "FPKM-TOM",
verbose = 3)
table(net$colors)
# open a graphics window
#sizeGrWindow(12, 9)
# Convert labels to colors for plotting
mergedColors = labels2colors(net$colors)
# Plot the dendrogram and the module colors underneath
plotDendroAndColors(net$dendrograms[[1]], mergedColors[net$blockGenes[[1]]],
groupLabels = c("Module colors",
"GS.weight"),
dendroLabels = FALSE, hang = 0.03,
addGuide = TRUE, guideHang = 0.05)
從圖中可以看出大部分基因在灰色區(qū)域,灰色部分一般認(rèn)為是沒有模塊接受的,從這里也可以看出其實(shí)咱們選擇的這些基因并不是特別好
那么做到這一步了基本上共表達(dá)模塊做完了,每個(gè)顏色代表一個(gè)共表達(dá)模塊,統(tǒng)計(jì)看看各個(gè)模塊下的基因個(gè)數(shù):
那么得到模塊之后下一步該做啥呢,或許很多人到這就不知道如何繼續(xù)分析了
這里就需要咱們利用這些模塊搞事情了,舉個(gè)例子
如果你是整合的數(shù)據(jù)(整合lnc與gene),那么同時(shí)在某個(gè)模塊中的基因和lncRNA咱們可以認(rèn)為是 共表達(dá)的,這便是lnc-gene共表達(dá)關(guān)系的獲得途徑之一了,進(jìn)一步你可以根據(jù)該模塊的基因-lnc-基因之間的關(guān)系繪制出共表達(dá)網(wǎng)絡(luò)
今天咱們這里不講這個(gè),而是跟表型關(guān)聯(lián),咱們已經(jīng)拿到了這98個(gè)樣本的ER、PR、HER2陽(yáng)性陰性信息,那么進(jìn)一步的咱們可以看看哪些共表達(dá)模塊跟ER、PR、HER2陰性最相關(guān),代碼如下:
moduleLabelsAutomatic = net$colors
moduleColorsAutomatic = labels2colors(moduleLabelsAutomatic)
moduleColorsFemale = moduleColorsAutomatic
MEs0 = moduleEigengenes(datExpr, moduleColorsFemale)$eigengenes
MEsFemale = orderMEs(MEs0)
samples=samples[match(row.names(datExpr),paste0(gsub('-','.',row.names(samples)),'.01')),]#匹配98個(gè)樣本數(shù)據(jù)
trainDt=as.matrix(cbind(ifelse(samples[,1]=='Positive',0,1),#將陰性的樣本標(biāo)記為1
ifelse(samples[,2]=='Positive',0,1),#將陰性的樣本標(biāo)記為1
ifelse(samples[,3]=='Positive',0,1),#將陰性的樣本標(biāo)記為1
ifelse(samples[,1]=='Negative'&samples[,2]=='Negative'&samples[,3]=='Negative',1,0))#將三陰性的樣本標(biāo)記為1
)#得到一個(gè)表型的0-1矩陣
modTraitCor = cor(MEsFemale, trainDt, use = "p")
colnames(MEsFemale)
modTraitP = corPvalueStudent(modTraitCor, nSamples)
textMatrix = paste(signif(modTraitCor, 2), "\n(", signif(modTraitP, 1), ")", sep = "")
dim(textMatrix) = dim(modTraitCor)
labeledHeatmap(Matrix = modTraitCor, xLabels = colnames(trainDt), yLabels = names(MEsFemale),
ySymbols = colnames(modlues), colorLabels = FALSE, colors = greenWhiteRed(50),
textMatrix = textMatrix, setStdMargins = FALSE, cex.text = 0.5, zlim = c(-1,1)
, main = paste("Module-trait relationships"))
最終找到幾個(gè)共表達(dá)網(wǎng)絡(luò)與三陰性表型最相關(guān)的模塊。
到了這一步其實(shí)還沒完,咱們已經(jīng)拿到了最相關(guān)的模塊比如上圖中的yellow模塊,那么yellow模塊中的基因,哪些基因最重要,我們?cè)撊绾潍@取
首先我們需要計(jì)算每個(gè)基因與模塊的相關(guān)關(guān)系
modTraitCor = cor(MEsFemale, datExpr, use = "p")
modTraitP = corPvalueStudent(modTraitCor, nSamples)
corYellow=modTraitCor[which(row.names(modTraitCor)=='MEyellow'),]
head(corYellow[order(-corYellow)])
#RAD51AP1 ? ? HDAC2 ? ? FOXM1 ? ?NCAPD2 ? ? ?TPI1 ? ? ?NOP2
#0.9249354 0.9080872 0.8991733 0.8872607 0.8717050 0.8708449
從上訴結(jié)果中可以看出RAD51AP1,HDAC2兩個(gè)基因與yellow相關(guān)性最好,也就是說這兩個(gè)基因是yellow模塊的hub-gene
進(jìn)一步的咱們導(dǎo)出yellow模塊的基因共表達(dá)關(guān)系使用cytoscape進(jìn)行可視化,代碼如下:
TOM = TOMsimilarityFromExpr(datExpr, power = pow);
probes = names(datExpr)
mc='yellow'
mcInds=which(match(moduleColorsAutomatic, gsub('^ME','',mc))==1)
modProbes=probes[mcInds]
modTOM = TOM[mcInds, mcInds];
dimnames(modTOM) = list(modProbes, modProbes)
cyt = exportNetworkToCytoscape(modTOM,
edgeFile = paste("edges-", mc, ".txt", sep=""),
nodeFile = paste("nodes-", mc, ".txt", sep=""),
weighted = TRUE,
threshold = median(modTOM),
nodeNames = modProbes,
#altNodeNames = modGenes,
nodeAttr = moduleColorsAutomatic[mcInds]);
到此基本結(jié)束了,敲這么多字。。。。。。好累。。。。。
歡迎關(guān)注生信人