From 1fce34b1ca52f8cf2ec5a6e4f6469bf8ddc997f1 Mon Sep 17 00:00:00 2001 From: freefire <97975089@qq.com> Date: Sun, 12 Jan 2025 03:51:54 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E4=BC=98=E5=8C=96R=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/heatmap_script.R | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/res/heatmap_script.R b/res/heatmap_script.R index c954a6e..5d5368b 100644 --- a/res/heatmap_script.R +++ b/res/heatmap_script.R @@ -1,27 +1,27 @@ -# Load required packages +# 加载所需的包 suppressPackageStartupMessages(library(circlize)) suppressPackageStartupMessages(library(RColorBrewer)) suppressPackageStartupMessages(library(ComplexHeatmap)) suppressPackageStartupMessages(library(dendextend)) -# Get arguments from the command line +# 获取命令行参数 args <- commandArgs(trailingOnly = TRUE) -# Check the number of arguments +# 检查参数数量 if (length(args) != 2) { - stop("Please provide two arguments: the input CSV file path and the output PDF file path.", call. = FALSE) + stop("请提供两个参数:输入CSV文件路径和输出PDF文件路径。", call. = FALSE) } -# Get the input CSV file path and the output PDF file path +# 获取输入CSV文件路径和输出PDF文件路径 input_csv <- args[1] output_pdf <- args[2] -# Check if the input file exists +# 检查输入文件是否存在 if (!file.exists(input_csv)) { - stop("The input file does not exist. Please check the file path.", call. = FALSE) + stop("输入文件不存在。请检查文件路径。", call. = FALSE) } -# Function to load and preprocess data +# 函数加载和预处理数据 load_and_preprocess_data <- function(file_path) { data <- read.table(file = file_path, header = TRUE, row.names = 1, sep = ',') data_matrix <- as.matrix(data) @@ -30,31 +30,37 @@ load_and_preprocess_data <- function(file_path) { return(normalized_data) } -# Load and preprocess data +# 加载和预处理数据 cir1 <- load_and_preprocess_data(input_csv) -# Define the color gradient for the heatmap +# 打印数据维度和头部 +print(dim(cir1)) +print(head(cir1)) + +# 定义颜色梯度 mycol <- colorRamp2(c(-2.5, 0.3, 3.1), c("blue", "white", "red")) -# Open the PDF device -pdf(output_pdf, width = 10, height = 8) +# 打开PDF设备,设置宽度和高度相等 +pdf(output_pdf, width = 8, height = 8) -# Draw the adjusted and beautified circular heatmap +# 设置绘图参数 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, + 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) }) -# Add column names +# 添加列名 circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) { if (CELL_META$sector.numeric.index == 1) { cn <- colnames(cir1) @@ -65,14 +71,14 @@ circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) } }, bg.border = NA) -# Add legend +# 添加图例 lg <- Legend(title = "Exp", col_fun = mycol, direction = "vertical") grid.draw(lg) -# Clear the circular plot +# 清除圆形图 circos.clear() -# Close the PDF device +# 关闭PDF设备 dev.off() -message("The heatmap has been successfully saved to: ", output_pdf) \ No newline at end of file +message("热图已成功保存至: ", output_pdf) \ No newline at end of file