進(jìn)行WGCNA要注意,WGCNA輸入(INPUT)的是:行對應(yīng)著一個樣品,列對應(yīng)著探針的矩陣或者數(shù)據(jù)框。
0 數(shù)據(jù)準(zhǔn)備
從WGCNA教程網(wǎng)站上下載要分析的數(shù)據(jù)集:FemaleLiver-Data,這個文件夾中包含以下三個數(shù)據(jù)集,分別為臨床表型信息、基因注釋信息、LiverFemale3600個基因的表達(dá)數(shù)據(jù)集。

下圖是數(shù)據(jù)集LiverFemale3600的部分截圖。

從上圖可以看到,這個數(shù)據(jù)集中的第一列對應(yīng)著基因探針,每一行是對應(yīng)一個基因探針(暫時可以這樣理解),數(shù)據(jù)集的前八列都是一些其他信息,第九列開始,每一列對應(yīng)著一個樣品(又稱為觀測)。
1 數(shù)據(jù)導(dǎo)入
library(WGCNA)
#Read in the female liver data set
femData = read.csv("data/LiverFemale3600.csv",stringsAsFactors = FALSE)
# Take a quick look at what is in the data set:
dim(femData)
View(femData[1:6,1:10])
datExpr0 = as.data.frame(t(femData[, -c(1:8)]))#轉(zhuǎn)置
names(datExpr0) = femData$substanceBXH#每列對應(yīng)著一個樣品
rownames(datExpr0) = names(femData)[-c(1:8)]#每行對應(yīng)著一個探針
View(datExpr0[1:5,1:5])
此時datExpr0為下圖樣式,每一行對應(yīng)著一個樣品,每一列對應(yīng)著一個探針(變量)。這與在limma中是的表達(dá)矩陣是不一樣的。這個是要注意的!WGCNA輸入(INPUT)的一個行對應(yīng)著一個樣品,列對應(yīng)著探針的矩陣或者數(shù)據(jù)框。

2 檢查數(shù)據(jù)集中的缺失值(missing values)和去除離群樣本點(diǎn)(outlier)。
檢查數(shù)據(jù)集中是否含有過多的缺失值,如果沒有缺失值則返回TRUE,否則返回FLASE。
gsg = goodSamplesGenes(datExpr0, verbose = 3);
gsg$allOK
如果數(shù)據(jù)集中含有過多的缺失值,則對數(shù)據(jù)集執(zhí)行下列代碼。
if (!gsg$allOK)
{
# Optionally, print the gene and sample names that were removed:
if (sum(!gsg$goodGenes)>0)
printFlush(paste("Removing genes:", paste(names(datExpr0)[!gsg$goodGenes], collapse = ", ")));
if (sum(!gsg$goodSamples)>0)
printFlush(paste("Removing samples:", paste(rownames(datExpr0)[!gsg$goodSamples], collapse = ", ")));
# Remove the offending genes and samples from the data:
datExpr0 = datExpr0[gsg$goodSamples, gsg$goodGenes]
}
去除離群樣本點(diǎn),使用聚類的方法。
##remove outlier
sampleTree = hclust(dist(datExpr0), method = "average");
# Plot the sample tree: Open a graphic output window of size 12 by 9 inches
# The user should change the dimensions if the window is too large or too small.
sizeGrWindow(12,9)
#pdf(file = "Plots/sampleClustering.pdf", width = 12, height = 9);
par(cex = 0.6);
par(mar = c(0,4,2,0))
plot(sampleTree, main = "Sample clustering to detect outliers", sub="", xlab="", cex.lab = 1.5,
cex.axis = 1.5, cex.main = 2)

從上圖中,很明顯有一個離群樣本點(diǎn):F2_221。要去除這個離群樣本點(diǎn)有兩種方式:
(1)手動去除
(2)使用自動的方法
在這個教程中,使用的是自動的方法將離群的樣本點(diǎn)去除掉。
選擇一個切樹的高度,以將離群樣本點(diǎn)去除掉,這里設(shè)置的切樹高度為15(圖中的紅色線),使用這個切樹高度以下的分枝。有兩個分支,一個分支就是F2_221,另一個分支是剩余樣品。
# Plot a line to show the cut
abline(h = 15, col = "red");

這里設(shè)置的切樹高度為15(圖中的紅色線),使用這個切樹高度以下的分枝。有兩個分支,一個分枝就是F2_221(在程序中,對應(yīng)著clust==0),另一個分枝是剩余樣品(在程序中,對應(yīng)著clust==1)。選擇clust==1的樣品,獲得去除異常樣品的數(shù)據(jù)集,即datExpr。
# Determine cluster under the line
clust = cutreeStatic(sampleTree, cutHeight = 15, minSize = 10)
table(clust)
# clust 1 contains the samples we want to keep.
keepSamples = (clust==1)
datExpr = datExpr0[keepSamples, ]
nGenes = ncol(datExpr)
nSamples = nrow(datExpr)
教程及數(shù)據(jù)集參考:WGCNA:I. Network analysis of liver expression data from female mice