-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircos_Plot.R
More file actions
78 lines (65 loc) · 2.54 KB
/
Circos_Plot.R
File metadata and controls
78 lines (65 loc) · 2.54 KB
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
library(circlize)
library(ComplexHeatmap)
# Load data efficiently
input_data <- read.csv("input_data.csv", stringsAsFactors = FALSE)
# Define expression columns
expression_cols <- c("PT8465_R1", "PT8465_R2", "PT8465_R3", "ND6401_R1", "ND6401_R2", "ND6401_R3")
input_data[expression_cols] <- lapply(input_data[expression_cols], as.numeric)
# Create matrix for heatmap
expression_matrices <- lapply(expression_cols, function(col) {
mat <- as.matrix(input_data[, col, drop = FALSE])
rownames(mat) <- input_data$gene
return(mat)
})
# Define functional annotation colors
function_colors <- c(
"No annotation - Protein had a hit in the EggNOG database, but the function is not annotated" = "#adec93",
"Function unknown" = "#37a9ed",
"Intracellular trafficking and secretion" = "#0f456e",
"Coenzyme metabolism" = "#064619",
"Post-translational modification, protein turnover, chaperone functions" = "#c3b091",
"Defense mechanisms" = "#6f5618",
"Inorganic ion transport and metabolism" = "#0fe900",
"Cell wall/membrane/envelope biogenesis" = "#f62222",
"Amino Acid metabolism and transport" = "#e3f988",
"Carbohydrate metabolism and transport" = "#403849",
"Translation" = "#ff7e7e",
"Replication and repair" = "#ff1ca1",
"Transcription" = "#ff9f3a"
)
# Function annotation matrix
mat_function <- as.matrix(input_data$function_)
rownames(mat_function) <- input_data$gene
# Define expression color mapping
col_fun <- colorRamp2(c(0, 1, 50, 200, 500, 1000),
c("#FFFFFF", "#edd6ff", "#ca85ff", "#950aff", "#6800b8", "#23003d"))
# Configure Circos plot
circos.clear()
circos.par(start.degree = 90, gap.degree = 35, track.margin = c(0.01, 0.01))
# Plot function-based heatmap
circos.heatmap(mat_function, col = function_colors, track.height = 0.05,
bg.border = "black", bg.lwd = 2, track.margin = c(0.02, 0.02))
# Plot expression-based heatmaps
for (mat in expression_matrices) {
circos.heatmap(mat, col = col_fun, track.height = 0.04, track.margin = c(0.005, 0.005))
}
circos.clear()
# Create and render legends
legend_expression <- Legend(
at = c(0, 1, 50, 200, 500, 1000),
col_fun = col_fun,
title = "Expression Levels",
direction = "horizontal",
title_gp = gpar(fontsize = 14, fontface = "bold"),
labels_gp = gpar(fontsize = 12)
)
legend_function <- Legend(
at = names(function_colors),
legend_gp = gpar(fill = function_colors),
title = "Gene Function",
ncol = 3,
grid_height = unit(5, "mm"),
grid_width = unit(5, "mm")
)
# Pack and draw legends
grid.draw(packLegend(legend_expression, legend_function))