1. 模块划分(聚类)

Signed or unsigned: which network type is preferable?

  1. net <- blockwiseModules(
  2. datExpr, # 输入数据
  3. corType = "pearson", # pearson | bicor
  4. power = sft$powerEstimate, # 前面得到的软阈值
  5. networkType = "unsigned", # unsigned | signed | signed hybrid
  6. TOMType = "unsigned", # none | unsigned | signed
  7. saveTOMs = TRUE,
  8. saveTOMFileBase = "blockwiseTOM",
  9. # deepSplit = 2, # 0|1|2|3|4, 值越大得到的模块就越多越小
  10. minModuleSize = 30, # 模块中最少的基因数
  11. mergeCutHeight = 0.25, # 对距离小于 mergeCutHeight (1-cor)的模块进行合并
  12. numericLabels = FALSE, # 以数字命名模块
  13. nThreads = 0, # 0 则使用所有可用线程
  14. maxBlockSize = nGenes # 需要大于基因的数目
  15. )
  16. net %>% names()
  17. #> [1] "colors" "unmergedColors" "MEs" "goodSamples"
  18. #> [5] "goodGenes" "dendrograms" "TOMFiles" "blockGenes"
  19. #> [9] "blocks" "MEsOK"
  20. # net$MEs: 模块特征向量
  21. wgcna_result <- data.frame(gene_id = names(net$colors), module = net$colors)
  22. moduleColors = (net$colors)
  23. pdf(file = "WGCNA_result.pdf")
  24. plotDendroAndColors(dendro = net$dendrograms[[1]],
  25. colors = net$colors,
  26. groupLabels = "Module colors",
  27. dendroLabels = FALSE,
  28. addGuide = TRUE)
  29. dev.off()

2. 相似模块合并

3. 模块特征向量

  1. # my_order: 样本组别顺序
  2. tgc <- net$MEs %>%
  3. rownames_to_column("Sample") %>%
  4. pivot_longer(-Sample, names_to = "Module", values_to = "Vleu") %>%
  5. mutate(Type = str_replace(Sample, "\\..*", "")) %>% # 得到样本组别信息,根据自己情况
  6. arrange(Module) %>%
  7. summarySE(measurevar="Vleu", groupvars=c("Module","Type")) %>%
  8. mutate(Type = factor(Type, levels = my_order)) %>%
  9. arrange(Module, Type)
  10. pdf(file='gene_expression_pattern_in_all_modules_1.pdf', w=12,h=14)
  11. ggplot(tgc, aes(Type, Vleu, group = Module)) +
  12. geom_errorbar(aes(ymin = Vleu - se, ymax = Vleu + se), width = .1, color = "#99CCCC") +
  13. geom_line(color = "#99CCCC", size = 0.5) +
  14. geom_point(color = "#99CCCC") +
  15. facet_wrap(~ Module, ncol = 4) +
  16. theme_bw()
  17. dev.off()