-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traits_heatmaps_take2.R
215 lines (159 loc) · 7.44 KB
/
Traits_heatmaps_take2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
##### This is a script for all the heatmaps wahahahah!
### differnt working directory for ease
setwd("~/Bioinformatics Work/Meth & RNA/Module exploration/Traits_Modules_Work")
### Load libraries
library(RColorBrewer)
library(pheatmap)
library(ggplot2)
library(gplots)
### need a cormat for the modules vs Stir meth
cormat1 <- read.table("Correlation_matrix_TCGA_meth.txt", sep = "\t",
header = TRUE, row.names = 1)
### for the TCGA and traits
cormat2 <- read.table("Correlation_matrix_TCGA_traits_trimmed.txt", sep = "\t",
header = TRUE, row.names = 1)
### for the METABRIC traits
cormat3 <- read.table("Correlation_matrix_METABRIC_traits_trimmed.txt", sep = "\t",
header = TRUE, row.names = 1)
############## trying out different heatmaps for the traits
#### information about par
### mai c(bottom, left, top, right) - the margin in inches
## mar is as mai but giving the value in lines
### oma c(bottom, left, top, right) of outer margins
par(oma= c(3,1,1,1))
### Info about heatmap.2
### must be done on a matrix not a dataframe
### dendro can be set to none or some
### key gives you a colour key
### srtCol/ srtRow gives an angle for the text
##sepCol, etc gives a cell outline
### RowSideColors - can set colours for marking the cols or rows
### colorpanel in gplots
###redgreen(n)
###redblue(n)
###bluered(n)
###colorpanel(n, low, mid, high)
## or can set the colour panel before
##eg palette <- colorRampPalette(c('#f0f3ff','#0033BB'))(256)
heatmap.2(as.matrix(cormat2),dendrogram="none",
notecol="black",col=bluered(200),scale="none",
key=TRUE, keysize=1.5,key.title = NA, key.xlab = "Correlation",
density.info="none", trace="none",
cexRow=1.2,cexCol=1.2, srtCol = 75,
main = "Traits expression \n by module in TCGA dataset",
rowsep = 1:nrow(cormat2), colsep = 1:ncol(cormat2), sepcolor = "grey")
heatmap.2(as.matrix(cormat3),dendrogram="none",
notecol="black",col=bluered(200),scale="none",
key=TRUE, key.title = NA, key.xlab = "Correlation", keysize=1.5,
density.info="none", trace="none",
cexRow=1.2,cexCol=1.2, srtCol = 75,
main = "Traits expression \n by module in METABRIC dataset",
rowsep = 1:nrow(cormat3), colsep = 1:ncol(cormat3), sepcolor = "grey")
#################### the meth heatmap
### pheatmap function uses slightly different wording
### annotate_rows instead of 'rowsidecols' for eg
pdf("Heat_test_meth3.pdf",height=8,width=10)
fontsize = 10
pheatmap(t(cormat1), color = colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
kmeans_k = NA, breaks = NA, border_color = "grey60",
cellwidth = NA, cellheight = NA, scale = "none",
cluster_rows = TRUE, cluster_cols = TRUE, fontsize_row = 10,
annotation_legend = TRUE, drop_levels = TRUE,
show_rownames = F,show_colnames = T,
treeheight_col = 0,
main = "Methylation of Stirzaker genes by module")
dev.off()
heatmap.2(as.matrix(t(cormat1)),dendrogram="row",
notecol="black",col=colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
scale="none",key=TRUE, keysize=1.5,
density.info="none", trace="none",
labRow = NA, cexRow=1.2,srtCol = 75,
main = "Methylation of Stirzaker genes by module")
########### cormat 4 might need a different approach??
#### for the lncs vs other
cormat4 <- read.table("LncMod_cor_MetaMod.txt", sep = "\t",
header = TRUE, row.names = 1)
#### for the trimmed out lnc mods
cormat5 <- read.table("LncMod_cor_MetaMod_trimmed.txt", sep = "\t",
header = TRUE, row.names = 1)
par(oma = c(2,2,2,3))
rowstrip <- c("Turquoise", "Yellow","Green","Magenta")
colstrip <- c("Blue","Brown", "Green", "Tan", "Yellow")
heatmap.2(as.matrix(cormat5),dendrogram="none",
Colv = TRUE, Rowv = FALSE,
notecol="black",col=colorpanel(200, "Green", "white", "Red"),scale="none",
key=TRUE, key.title = NA, key.xlab = "Correlation", keysize=1.5,
density.info="none", trace="none",
cexRow=1 ,cexCol=1, srtCol = 75,
main = "Correlation between \n LNC modules and EXP modules",
rowsep = 1:nrow(cormat5), colsep = 1:ncol(cormat5), sepcolor = "grey")
############## for the methylation work
cormat1 <- read.table("All_meth_trait_corr.txt", sep = "\t", header = TRUE, row.names = 1)
### heatmap of all
pdf("Heat_test_meth3.pdf",height=8,width=10)
fontsize = 10
pheatmap(t(cormat1), color = colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(50),
kmeans_k = NA, breaks = NA, border_color = "grey60",
cellwidth = NA, cellheight = NA, scale = "none",
cluster_rows = TRUE, cluster_cols = TRUE, fontsize_row = 10,
annotation_legend = TRUE, drop_levels = TRUE,
show_rownames = F,show_colnames = T,
treeheight_col = 0,
main = "Methylation of gene promoters by module")
dev.off()
### subset only the basal like
cormat_b <- cormat1[1:3,]
cormat_l <- cormat1[4:5,]
cormat_n <- cormat1[6:7,]
##comparison of opposites
cormat_op <- cormat1[c(2,4),]
pdf("Heat_test_meth_basal.pdf",height=8,width=8)
fontsize = 10
pheatmap(t(cormat_b), color = colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(50),
kmeans_k = NA, breaks = NA, border_color = "grey60",
cellwidth = NA, cellheight = NA, scale = "none",
cluster_rows = TRUE, cluster_cols = FALSE, fontsize_row = 10,
annotation_legend = TRUE, drop_levels = TRUE,
show_rownames = F,show_colnames = T,
treeheight_col = 0,
main = "Methylation of gene promoters by module")
dev.off()
pdf("Heat_test_meth_basal1.pdf",height=8,width=8)
par(oma= c(3,1,1,1))
heatmap.2(as.matrix(t(cormat_b)),dendrogram="row",
notecol="black",col=colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
scale="none",key=TRUE, keysize=1.5,
density.info="none", trace="none",
labRow = NA, cexRow=1, srtCol = 75, cexCol = 1,
main = "Methylation of gene promoter by module")
dev.off()
####Luminals
pdf("Heat_test_meth_luminal1.pdf",height=8,width=8)
par(oma= c(3,1,1,1))
heatmap.2(as.matrix(t(cormat_l)),dendrogram="row",
notecol="black",col=colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
scale="none",key=TRUE, keysize=1.5,
density.info="none", trace="none",
labRow = NA, cexRow=1, srtCol = 75, cexCol = 1,
main = "Methylation of gene promoter by module")
dev.off()
####Normals
pdf("Heat_test_meth_normal1.pdf",height=8,width=8)
par(oma= c(3,1,1,1))
heatmap.2(as.matrix(t(cormat_n)),dendrogram="row",
notecol="black",col=colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
scale="none",key=TRUE, keysize=1.5,
density.info="none", trace="none",
labRow = NA, cexRow=1, srtCol = 75, cexCol = 1,
main = "Methylation of gene promoter by module")
dev.off()
####Opposites
pdf("Heat_test_meth_opposites1.pdf",height=8,width=8)
par(oma= c(3,1,1,1))
heatmap.2(as.matrix(t(cormat_op)),dendrogram="row",
notecol="black",col=colorRampPalette(rev(brewer.pal(n = 10, name = "RdYlBu")))(100),
scale="none",key=TRUE, keysize=1.5,
density.info="none", trace="none",
labRow = NA, cexRow=1, srtCol = 75, cexCol = 1,
main = "Methylation of gene promoter by module")
dev.off()