做一个基于 R 语言的环形热图(Circos Heatmap)绘制工具,通过 Aardio 实现图形界面。
项目地址:CircosHeatmap-aardio
示例:

输出:

编译打包前的准备:
修改 aardio\lib\process\r\_.aardio 文件中:
Code AardioLine:1复制
1.- setLibPaths({..
io
.appData("aardio/std/r/site-library"
)});
修改为
Code AardioLine:7复制
1.2.3.4.5.6.7.if
(_STUDIO_INVOKED) {-
- setLibPaths({..
io
.appData("aardio/std/r/site-library"
)}); - }
else
{ -
- setLibPaths({
"lib\r-library"
}); - }
修改它的目的:初次接触 aardio + R 的开发,安装 R 的相关库时遇到无法安装部分 R 库的问题,所以干脆把安装好的 R 相关库放入程序根目录下,便于将程序分发给别人使用。
这样做缺点:R 库体积偏大,100MB+,不过真正需要的人应该不在乎体积吧
TODO:
1、aardio 图形界面开发
Code AardioLine:59复制
2、 R 脚本实现
R 脚本是该程序的核心,负责数据处理和环形热图的绘制。
Code AardioLine:84复制
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.- suppressPackageStartupMessages(library(circlize))
- suppressPackageStartupMessages(library(RColorBrewer))
- suppressPackageStartupMessages(library(ComplexHeatmap))
- suppressPackageStartupMessages(library(dendextend))
- args <- commandArgs(trailingOnly =
TRUE
) if
(length(args) != 2
) {- stop(
"请提供两个参数:输入CSV文件路径和输出PDF文件路径。"
, call
. = FALSE
) - }
- input_csv <- args[
1
] - output_pdf <- args[
2
] if
(!file.exists(input_csv)) {- stop(
"输入文件不存在。请检查文件路径。"
, call
. = FALSE
) - }
- load_and_preprocess_data <-
function
(file_path) { - data <- read.
table
(file = file_path, header = TRUE
, row.names = 1
, sep = ','
) - data_matrix <- as.matrix(data)
- normalized_data <- t(scale(t(data_matrix)))
- normalized_data[is.na(normalized_data)] <-
0
-
return
(normalized_data) - }
- cir1 <- load_and_preprocess_data(input_csv)
- print(dim(cir1))
- print(head(cir1))
- mycol <- colorRamp2(c(-
2
.5
, 0
.3
, 3
.1
), c("blue"
, "white"
, "red"
)) - pdf(output_pdf, width =
8
, height = 8
) - circos.par(gap.after = c(
30
)) - circos.heatmap(cir1,
- col = mycol,
- dend.side =
"inside"
, - rownames.side =
"outside"
, - rownames.col =
"black"
, - rownames.cex =
1
.3
, - track.height =
0
.35
, - cluster =
TRUE
, - dend.track.height =
0
.18
, - dend.callback =
function
(dend, m, si) { - color_branches(dend, k =
15
, col = 1
:15
) - })
- circos.track(track.index = get.current.track.index(), panel.fun =
function
(x, y) { -
if
(CELL_META$sector.numeric.index == 1
) { - cn <- colnames(cir1)
- n <- length(cn)
- circos.text(rep(CELL_META$cell.xlim[
2
], n) + convert_x(0
.5
, "mm"
), -
1
:n + 2
.5
, - cn, cex =
0
.6
, adj = c(0
, 0
.5
), facing = "inside"
) - }
- }, bg.border = NA)
- lg <- Legend(title =
"Exp"
, col_fun = mycol, direction = "vertical"
) - grid.draw(lg)
- circos.clear()
- dev.off()
- message(
"热图已成功保存至: "
, output_pdf)