library(ComplexHeatmap)
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.18.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite either one:
## - Gu, Z. Complex Heatmap Visualization. iMeta 2022.
## - Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##     genomic data. Bioinformatics 2016.
## 
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
library(circlize)
## ========================================
## circlize version 0.4.16
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: https://jokergoo.github.io/circlize_book/book/
## 
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
##   in R. Bioinformatics 2014.
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(circlize))
## ========================================
remove_adeno <- readRDS("~/Documents/r_codes/remove_adeno.rds")
mat1 <- remove_adeno[,-1]
mat1 <- as.matrix(mat1)
mat1 <- t(mat1)

remove_scc <- readRDS("~/Documents/r_codes/remove_scc.rds")
mat2 <- remove_scc[,-1]
mat2 <- as.matrix(mat2)
mat2 <- t(mat2)

remove_adeno_selected <- readRDS("~/Documents/r_codes/remove_adeno_selected.rds")
mat3 <- remove_adeno_selected[,-7]
mat3 <- as.matrix(mat3)
mat3 <- t(mat3)

remove_sq_selected <- readRDS("~/Documents/r_codes/remove_sq_selected.rds")
mat4 <- remove_sq_selected[,-5]
mat4 <- as.matrix(mat4)
mat4 <- t(mat4)

col_fun <- colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))

grid.newpage()
pushViewport(viewport(layout = grid.layout(nr = 2, nc = 2)))

#for adeno
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 1))
heatmap1 <- Heatmap(mat1, col = col_fun, column_split = list(remove_adeno$merged_stage),
                    cluster_column = TRUE, cluster_rows = FALSE, show_row_names = TRUE,
                    row_title_rot = 90, column_names_rot = 45, show_column_names = FALSE,
                    cluster_column_slices = FALSE, row_title = "adeno ")
draw(heatmap1, newpage = FALSE)
upViewport()

#for sq
pushViewport(viewport(layout.pos.row = 1, layout.pos.col = 2))
heatmap2 <- Heatmap(mat2, col = col_fun, column_split = list(remove_scc$merged_stage),
                    cluster_column = TRUE, cluster_rows = FALSE, show_row_names = TRUE,
                    row_title_rot = 90, column_names_rot = 45, show_column_names = FALSE,
                    cluster_column_slices = FALSE, row_title = "scc")
draw(heatmap2, newpage = FALSE)
upViewport()

#for adeno selected
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 1))
heatmap3 <- Heatmap(mat3, col = col_fun, column_split = list(remove_adeno_selected$merged_stage),
                    cluster_column = TRUE, cluster_rows = FALSE, show_row_names = TRUE,
                    row_title_rot = 90, column_names_rot = 45, show_column_names = FALSE,
                    cluster_column_slices = FALSE, row_title = "adeno selected")
draw(heatmap3, newpage = FALSE)
upViewport()

#for sq selected
pushViewport(viewport(layout.pos.row = 2, layout.pos.col = 2))
heatmap4 <- Heatmap(mat4, col = col_fun, column_split = list(remove_sq_selected$merged_stage),
                    cluster_column = TRUE, cluster_rows = FALSE, show_row_names = TRUE,
                    row_title_rot = 90, column_names_rot = 45, show_column_names = FALSE,
                    cluster_column_slices = FALSE, row_title = "scc selected")
draw(heatmap4, newpage = FALSE)
upViewport()