a b/c_VisualizationScript/Visulz_bulkATAC_heatmapTrack.R
1
2
# MESSAGE -----------------------------------------------------------------
3
#
4
# author: Yulin Lyu
5
# email: lvyulin@pku.edu.cn
6
#
7
# require: R whatever
8
#
9
# ---
10
11
# * 1. Load packages ------------------------------------------------------
12
13
setwd("exampleData/ATAC")
14
15
# grammar
16
library(tidyverse)
17
library(magrittr)
18
library(glue)
19
library(data.table)
20
21
# graphics
22
library(ComplexHeatmap)
23
library(circlize)
24
library(RColorBrewer)
25
library(ggsci)
26
library(scales)
27
28
# * 2. Load data ----------------------------------------------------------
29
30
peakData <- fread("peak/peak_value.txt", skip = 3)
31
peakGroup <- readRDS("peakGroup.rds")
32
33
sample <- rep(c("F", "P", "XF"), each = 300) %>% factor(levels = c("P", "F", "XF"))
34
peakType <- rep(c("g1", "g4"), c(length(peakGroup$`1`), length(peakGroup$`4`))) %>% factor(levels = c("g4", "g1"))
35
36
heatData <- as.matrix(peakData)
37
heatData[is.nan(heatData)] <- 0
38
max(heatData)
39
40
colorFun <- colorRamp2(seq(6, 0, len = 11), brewer.pal(11, "Spectral"))
41
42
p <- Heatmap(
43
  heatData, border = F, col = colorFun,
44
  cluster_rows = F, cluster_columns = F,
45
  show_row_names = F, show_column_names = F,
46
  column_title_side = "bottom",
47
  row_split = peakType,
48
  column_split = sample,
49
  left_annotation = rowAnnotation(
50
    type = anno_block(
51
      gp = gpar(col = NA, fill = pal_nejm()(2)[2:1]),
52
      width = unit(.1, "in"))
53
  ),
54
  heatmap_legend_param = list(
55
    title = "Normalized signal",
56
    title_position = "lefttop-rot",
57
    legend_height = unit(2, "in")),
58
  width = unit(4, "in"),
59
  height = unit(8, "in")
60
)
61
62
png("graphics/heatmapTrack.png", res = 300, width = 6, height = 9, units = "in")
63
p
64
dev.off()
65