add 删除R脚本中多余的图形绘制
This commit is contained in:
parent
d22e9ab4df
commit
16cd091932
@ -1,14 +1,11 @@
|
|||||||
# Load required packages
|
# Load required packages
|
||||||
suppressPackageStartupMessages(library(grid))
|
|
||||||
suppressPackageStartupMessages(library(ComplexHeatmap))
|
|
||||||
suppressPackageStartupMessages(library(circlize))
|
suppressPackageStartupMessages(library(circlize))
|
||||||
suppressPackageStartupMessages(library(RColorBrewer))
|
suppressPackageStartupMessages(library(RColorBrewer))
|
||||||
|
suppressPackageStartupMessages(library(ComplexHeatmap))
|
||||||
suppressPackageStartupMessages(library(dendextend))
|
suppressPackageStartupMessages(library(dendextend))
|
||||||
suppressPackageStartupMessages(library(dendsort))
|
|
||||||
suppressPackageStartupMessages(library(gridBase))
|
|
||||||
|
|
||||||
# Get arguments from the command line
|
# Get arguments from the command line
|
||||||
args <- commandArgs(T)
|
args <- commandArgs(trailingOnly = TRUE)
|
||||||
|
|
||||||
# Check the number of arguments
|
# Check the number of arguments
|
||||||
if (length(args) != 2) {
|
if (length(args) != 2) {
|
||||||
@ -24,23 +21,17 @@ if (!file.exists(input_csv)) {
|
|||||||
stop("The input file does not exist. Please check the file path.", call. = FALSE)
|
stop("The input file does not exist. Please check the file path.", call. = FALSE)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load the data for plotting
|
# Function to load and preprocess data
|
||||||
data <- read.table(file = input_csv, header = TRUE, row.names = 1, sep = ',')
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
# View the data
|
# Load and preprocess data
|
||||||
message("Data loaded successfully. The first few rows are as follows:")
|
cir1 <- load_and_preprocess_data(input_csv)
|
||||||
print(head(data))
|
|
||||||
|
|
||||||
# Convert to matrix format and normalize the data
|
|
||||||
data <- as.matrix(data)
|
|
||||||
cir1 <- t(scale(t(data)))
|
|
||||||
|
|
||||||
# Handle NA values
|
|
||||||
cir1[is.na(cir1)] <- 0
|
|
||||||
|
|
||||||
# View the normalized data
|
|
||||||
message("Data normalization successful. The first few rows are as follows:")
|
|
||||||
print(head(cir1))
|
|
||||||
|
|
||||||
# Define the color gradient for the heatmap
|
# Define the color gradient for the heatmap
|
||||||
mycol <- colorRamp2(c(-2.5, 0.3, 3.1), c("blue", "white", "red"))
|
mycol <- colorRamp2(c(-2.5, 0.3, 3.1), c("blue", "white", "red"))
|
||||||
@ -48,57 +39,37 @@ mycol <- colorRamp2(c(-2.5, 0.3, 3.1), c("blue", "white", "red"))
|
|||||||
# Open the PDF device
|
# Open the PDF device
|
||||||
pdf(output_pdf, width = 10, height = 8)
|
pdf(output_pdf, width = 10, height = 8)
|
||||||
|
|
||||||
# Draw the basic circular heatmap
|
# Draw the adjusted and beautified circular heatmap
|
||||||
message("Drawing the basic circular heatmap...")
|
|
||||||
circos.heatmap(cir1, col = mycol)
|
|
||||||
circos.clear()
|
|
||||||
|
|
||||||
# Adjust and beautify the circular heatmap in circos.heatmap()
|
|
||||||
message("Drawing the adjusted and beautified circular heatmap...")
|
|
||||||
circos.par(gap.after = c(30))
|
circos.par(gap.after = c(30))
|
||||||
circos.heatmap(cir1, col = mycol,
|
circos.heatmap(cir1,
|
||||||
dend.side = "inside",
|
col = mycol,
|
||||||
rownames.side = "outside",
|
dend.side = "inside",
|
||||||
rownames.col = "black",
|
rownames.side = "outside",
|
||||||
rownames.cex = 1.2,
|
rownames.col = "black",
|
||||||
rownames.font = 1.2,
|
rownames.cex = 1.3,
|
||||||
bg.border = "black",
|
track.height = 0.35,
|
||||||
cluster = TRUE)
|
cluster = TRUE,
|
||||||
circos.clear()
|
dend.track.height = 0.18,
|
||||||
|
dend.callback = function(dend, m, si) {
|
||||||
|
color_branches(dend, k = 15, col = 1:15)
|
||||||
|
})
|
||||||
|
|
||||||
# Adjust and beautify the dendrogram
|
# Add column names
|
||||||
message("Drawing the circular heatmap with adjusted and beautified dendrogram...")
|
|
||||||
circos.par(gap.after = c(30))
|
|
||||||
circos.heatmap(cir1, col = mycol, dend.side = "inside",
|
|
||||||
rownames.side = "outside",
|
|
||||||
track.height = 0.35,
|
|
||||||
rownames.col = "black",
|
|
||||||
rownames.cex = 1.3,
|
|
||||||
rownames.font = 1.3,
|
|
||||||
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) {
|
circos.track(track.index = get.current.track.index(), panel.fun = function(x, y) {
|
||||||
if (CELL_META$sector.numeric.index == 1) {
|
if (CELL_META$sector.numeric.index == 1) {
|
||||||
cn <- colnames(cir1)
|
cn <- colnames(cir1)
|
||||||
n <- length(cn)
|
n <- length(cn)
|
||||||
# Adjust the x and y positions
|
|
||||||
circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(0.5, "mm"),
|
circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(0.5, "mm"),
|
||||||
1:n + 2.5,
|
1:n + 2.5,
|
||||||
cn, cex = 0.6, adj = c(0, 0.5), facing = "inside")
|
cn, cex = 0.6, adj = c(0, 0.5), facing = "inside")
|
||||||
}
|
}
|
||||||
}, bg.border = NA)
|
}, bg.border = NA)
|
||||||
|
|
||||||
# 添加图例
|
# Add legend
|
||||||
message("Adding legend labels...")
|
|
||||||
lg <- Legend(title = "Exp", col_fun = mycol, direction = "vertical")
|
lg <- Legend(title = "Exp", col_fun = mycol, direction = "vertical")
|
||||||
grid.draw(lg)
|
grid.draw(lg)
|
||||||
|
|
||||||
# 清除环形图
|
# Clear the circular plot
|
||||||
circos.clear()
|
circos.clear()
|
||||||
|
|
||||||
# Close the PDF device
|
# Close the PDF device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user