WGCNA 模块-性状热图改用 BH 校正 p 值,并支持 job 置顶与优先级排序

This commit is contained in:
potaser
2026-08-30 00:17:25 +08:00
parent f712a657c0
commit abdd486ed8
4 changed files with 63 additions and 6 deletions
+15 -4
View File
@@ -360,23 +360,29 @@ colnames(condition_mm) <- sub("^condition", "", colnames(condition_mm))
traitData <- as.data.frame(condition_mm)
moduleTraitCor <- cor(MEs, traitData, use = "p")
moduleTraitPvalue <- corPvalueStudent(moduleTraitCor, nSamples = nrow(datExpr))
moduleTraitPadj <- matrix(
p.adjust(as.vector(moduleTraitPvalue), method = "BH"),
nrow = nrow(moduleTraitPvalue), ncol = ncol(moduleTraitPvalue),
dimnames = dimnames(moduleTraitPvalue)
)
write.table(moduleTraitCor, file = paste0(kv$out_prefix, ".module_trait_correlation.tsv"), sep = "\t", quote = FALSE, col.names = NA)
write.table(moduleTraitPvalue, file = paste0(kv$out_prefix, ".module_trait_pvalue.tsv"), sep = "\t", quote = FALSE, col.names = NA)
write.table(moduleTraitPadj, file = paste0(kv$out_prefix, ".module_trait_padj.tsv"), sep = "\t", quote = FALSE, col.names = NA)
write.table(MEs, file = paste0(kv$out_prefix, ".module_eigengenes.tsv"), sep = "\t", quote = FALSE, col.names = NA)
textMatrix <- paste(signif(moduleTraitCor, 2), "\n(", signif(moduleTraitPvalue, 1), ")", sep = "")
textMatrix <- paste(signif(moduleTraitCor, 2), "\n(FDR ", signif(moduleTraitPadj, 2), ")", sep = "")
dim(textMatrix) <- dim(moduleTraitCor)
png(paste0(kv$out_prefix, ".module_trait_heatmap.png"), width = 1800, height = 1600, res = 220)
labeledHeatmap(Matrix = moduleTraitCor, xLabels = colnames(traitData), yLabels = names(MEs),
ySymbols = names(MEs), colorLabels = FALSE, colors = blueWhiteRed(50),
textMatrix = textMatrix, setStdMargins = FALSE, cex.text = 0.7,
zlim = c(-1, 1), main = "Module-trait relationships")
zlim = c(-1, 1), main = "Module-trait relationships (BH-adjusted P values)")
dev.off()
pdf(paste0(kv$out_prefix, ".module_trait_heatmap.pdf"), width = 8, height = 7)
labeledHeatmap(Matrix = moduleTraitCor, xLabels = colnames(traitData), yLabels = names(MEs),
ySymbols = names(MEs), colorLabels = FALSE, colors = blueWhiteRed(50),
textMatrix = textMatrix, setStdMargins = FALSE, cex.text = 0.7,
zlim = c(-1, 1), main = "Module-trait relationships")
zlim = c(-1, 1), main = "Module-trait relationships (BH-adjusted P values)")
dev.off()
geneModule <- data.frame(gene_id = colnames(datExpr), module = moduleColors)
@@ -394,7 +400,8 @@ colnames(moduleSizes) <- c("module", "genes")
write.table(moduleSizes, file = paste0(kv$out_prefix, ".module_sizes.tsv"), sep = "\t", quote = FALSE, row.names = FALSE)
saveRDS(list(datExpr = datExpr, moduleColors = moduleColors, MEs = MEs, softPower = softPower,
moduleTraitCor = moduleTraitCor, moduleTraitPvalue = moduleTraitPvalue),
moduleTraitCor = moduleTraitCor, moduleTraitPvalue = moduleTraitPvalue,
moduleTraitPadj = moduleTraitPadj),
file = paste0(kv$out_prefix, ".wgcna_result.rds"))
summary <- data.frame(
@@ -475,6 +482,7 @@ def write_report(path: Path, manifest: dict[str, Any]) -> None:
"",
"- WGCNA is most reliable with larger sample sizes; interpret very small RNA-seq designs cautiously.",
"- Genes are filtered by expression and variance before TOM construction to keep the analysis tractable.",
"- Module-trait heatmap labels use Benjamini-Hochberg adjusted P values (FDR) across all displayed module-trait tests; raw P values are retained as a separate artifact.",
"",
"## Artifacts",
"",
@@ -581,6 +589,7 @@ def main(argv: list[str] | None = None) -> int:
"gene_dendrogram_modules_pdf": (Path(f"{out_prefix}.gene_dendrogram_modules.pdf"), "pdf"),
"module_trait_correlation": (Path(f"{out_prefix}.module_trait_correlation.tsv"), "tsv"),
"module_trait_pvalue": (Path(f"{out_prefix}.module_trait_pvalue.tsv"), "tsv"),
"module_trait_padj": (Path(f"{out_prefix}.module_trait_padj.tsv"), "tsv"),
"module_trait_heatmap_png": (Path(f"{out_prefix}.module_trait_heatmap.png"), "image"),
"module_trait_heatmap_pdf": (Path(f"{out_prefix}.module_trait_heatmap.pdf"), "pdf"),
"module_eigengenes": (Path(f"{out_prefix}.module_eigengenes.tsv"), "tsv"),
@@ -607,6 +616,7 @@ def main(argv: list[str] | None = None) -> int:
metrics = read_summary(Path(f"{out_prefix}.wgcna_summary.tsv"))
metrics["conditions_detail"] = {sample: groups[sample] for sample in samples}
metrics["matrix_type"] = matrix_type
metrics["module_trait_pvalue_adjustment"] = "BH_global"
manifest = {
"manifest_version": "1.0",
"stage": "rnaseq_wgcna",
@@ -637,6 +647,7 @@ def main(argv: list[str] | None = None) -> int:
"min_module_size": args.min_module_size,
"merge_cut_height": args.merge_cut_height,
"powers": args.powers,
"module_trait_pvalue_adjustment": "BH_global",
"cpu": threads,
"threads": threads,
},