1. 模块划分(聚类)
Signed or unsigned: which network type is preferable?
net <- blockwiseModules(
datExpr, # 输入数据
corType = "pearson", # pearson | bicor
power = sft$powerEstimate, # 前面得到的软阈值
networkType = "unsigned", # unsigned | signed | signed hybrid
TOMType = "unsigned", # none | unsigned | signed
saveTOMs = TRUE,
saveTOMFileBase = "blockwiseTOM",
# deepSplit = 2, # 0|1|2|3|4, 值越大得到的模块就越多越小
minModuleSize = 30, # 模块中最少的基因数
mergeCutHeight = 0.25, # 对距离小于 mergeCutHeight (1-cor)的模块进行合并
numericLabels = FALSE, # 以数字命名模块
nThreads = 0, # 0 则使用所有可用线程
maxBlockSize = nGenes # 需要大于基因的数目
)
net %>% names()
#> [1] "colors" "unmergedColors" "MEs" "goodSamples"
#> [5] "goodGenes" "dendrograms" "TOMFiles" "blockGenes"
#> [9] "blocks" "MEsOK"
# net$MEs: 模块特征向量
wgcna_result <- data.frame(gene_id = names(net$colors), module = net$colors)
moduleColors = (net$colors)
pdf(file = "WGCNA_result.pdf")
plotDendroAndColors(dendro = net$dendrograms[[1]],
colors = net$colors,
groupLabels = "Module colors",
dendroLabels = FALSE,
addGuide = TRUE)
dev.off()
2. 相似模块合并
3. 模块特征向量
# my_order: 样本组别顺序
tgc <- net$MEs %>%
rownames_to_column("Sample") %>%
pivot_longer(-Sample, names_to = "Module", values_to = "Vleu") %>%
mutate(Type = str_replace(Sample, "\\..*", "")) %>% # 得到样本组别信息,根据自己情况
arrange(Module) %>%
summarySE(measurevar="Vleu", groupvars=c("Module","Type")) %>%
mutate(Type = factor(Type, levels = my_order)) %>%
arrange(Module, Type)
pdf(file='gene_expression_pattern_in_all_modules_1.pdf', w=12,h=14)
ggplot(tgc, aes(Type, Vleu, group = Module)) +
geom_errorbar(aes(ymin = Vleu - se, ymax = Vleu + se), width = .1, color = "#99CCCC") +
geom_line(color = "#99CCCC", size = 0.5) +
geom_point(color = "#99CCCC") +
facet_wrap(~ Module, ncol = 4) +
theme_bw()
dev.off()