-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdefineScalePheatmap.R
61 lines (47 loc) · 1.42 KB
/
defineScalePheatmap.R
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
library(data.table)
library(tidyr)
library(tidyverse)
library(dplyr)
library(readxl)
library(ggpubr)
library(pheatmap)
library(dendextend)
library(RColorBrewer)
hm <- broad_expr_ccle_genelist_NBL_merge[,c(1:3,5)]
# create a unique column
hm$concat <- paste0(hm$gene,'_',hm$type)
hm <- hm[,c(1,3,5)]
# remove duplicates
hm <- hm[!duplicated(hm),]
# reshaping df
hm <- hm %>%
spread(key = concat, value = ceres_score)
# only 17 NBL cell lines have dependency data
# check!
#unique(intersect(broad_ccle$X, nbl_cl$cellLine))
colnames(hm) <- gsub('_.*','', colnames(hm), perl = TRUE)
hm <- hm %>%
column_to_rownames(var = 'cellLine')
hm[is.na(hm)] <- 0
# clustering
my_hclust_gene <- hclust(dist(t(hm)), method = "complete")
#plot(my_hclust_gene)
# plotting dendogram
as.dendrogram(my_hclust_gene) %>%
plot(horiz = FALSE)
# getting cluster info
my_gene_col <- cutree(tree = as.dendrogram(my_hclust_gene), k = 4)
cluster_info <- data.frame(gene = names(my_gene_col),
cluster = as.data.frame(my_gene_col))
# column annotation
col_anno <- broad_expr_ccle_genelist_NBL_merge[,c(2,5)]
col_anno <- col_anno %>%
column_to_rownames(var = 'gene')
# customizing scale
breaksList = seq(-2.5, 0.9, by = 0.5)
# heatmap
p <- pheatmap(hm,
cutree_cols = 4,
cluster_cols = my_hclust_gene,
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)