-
Notifications
You must be signed in to change notification settings - Fork 0
/
Heatmap_PvalAndNMI.R
193 lines (186 loc) · 6.44 KB
/
Heatmap_PvalAndNMI.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
library(vroom)
setwd("C:/Users/tyson/OneDrive/Desktop/Coronavirus Proteins/UpdatedHackensack/omeClustFilteredMeta")
listOfRegions=list.files()
counter=1
listOfRegions=listOfRegions[-which(listOfRegions=="output")]
region=c()
for (x in listOfRegions){
exists=list.files(path=x)
if(length(exists)>2){
currentRegion=as.data.frame(vroom(paste(x,"/","clusters.txt",sep="")))
if(counter==1){
associationTable=as.data.frame(currentRegion[1,])
}else{
currentRegion=currentRegion[,match(x=colnames(currentRegion), table=colnames(associationTable))]
associationTable=as.data.frame(rbind(associationTable,currentRegion[1,]))
}
region=append(region,x)
counter=counter+1
}
}
rownames(associationTable)=region
#View(associationTable)
associationTable=associationTable[,c(-1,-2,-3,-4,-5)]
#View(associationTable)
categories=c("Clinical",
"Outcome",
"Clinical",
"Outcome",
"Clinical",
"Clinical",
"Clinical",
"Clinical",
"Clinical",
"Clinical",
"Clinical",
"Clinical",
"Outcome",
"Clinical",
"Patient",
"Clinical",
"Clinical",
"Patient",
"Outcome",
"Outcome",
"Clinical",
"Clinical",
"Other",
"Patient",
"Outcome",
"Outcome",
"Other",
"Clinical",
"Patient",
"Outcome",
"Clinical",
"Patient",
"Patient",
"Other",
"Patient",
"Medicine",
"Outcome",
"Medicine",
"Patient",
"Patient",
"Medicine",
"Clinical",
"Outcome",
"Outcome",
"Medicine",
"Medicine",
"Outcome",
"Patient",
"Medicine",
"Medicine",
"Patient",
"Medicine",
"Medicine",
"Patient",
"Medicine",
"Medicine",
"Patient",
"Medicine",
"Medicine",
"Outcome",
"Patient",
"Medicine",
"Patient",
"Patient",
"Medicine",
"Medicine",
"Medicine",
"Patient",
"Medicine",
"Patient",
"Outcome",
"Medicine",
"Medicine",
"Patient",
"Patient",
"Patient",
"Other",
"Medicine")
library(ComplexHeatmap)
library(RColorBrewer)
#Heatmap(as.matrix(associationTable))
row.names(associationTable)=str_remove_all(row.names(associationTable),"_output")
row_dend = dendsort(hclust(dist(t(associationTable))))
#pdf(file="heatmap_cleanNames.pdf",width=30,height=8)
Heatmap(as.matrix(associationTable),
column_split = data.frame(categories),
col = colorRampPalette(brewer.pal(n = 9, name = "Blues"))(100),
column_title_gp = gpar(fill = c("red", "blue", "green","orange","purple")),
column_order = sort(colnames(associationTable)),
cluster_columns = FALSE,
cluster_rows = FALSE
)
#dev.off()
#write.csv(associationTable,file="associationTable.csv")
pval=vroom("PERMANOVA_pval.txt")
coef=vroom("PERMANOVA_coef.txt")
saveRowNames=coef$...1
saveRowNames2=pval$...1
identical(colnames(coef),colnames(pval))
matchIDX=match(colnames(associationTable),colnames(coef))
#matchIDX2=match(colnames(associationTable),colnames(pval))
coef=coef[,matchIDX]
pval=pval[,matchIDX]
#coef=coef[,-1]
row.names(coef)=saveRowNames
row.names(pval)=saveRowNames2
library(dplyr)
coef <- mutate_all(coef, function(x) as.numeric(as.character(x)))
coef[is.na(coef)] <- 0
pval <- mutate_all(pval, function(x) as.numeric(as.character(x)))
#pval[is.na(pval)] <- 0
library(dendsort)
#matPos=match(colnames(coef),heat1@column_names_param$labels)
#saveRowNames3=row.names(pval)
#pval=pval[,-1,drop=FALSE]
#row.names(pval)=saveRowNames3
#matPos=match(colnames(pval),heat1@column_names_param$labels)
matchIDX=match(tolower(row.names(associationTable)),tolower(row.names(pval)))
pval=pval[matchIDX,,drop=FALSE]
saveColNames=colnames(pval)
saveRowNames=row.names(pval)
saveColNames2=colnames(coef)
matchIDX2=match(tolower(colnames(associationTable)),tolower(colnames(pval)))
pval=pval[,matchIDX2,drop=FALSE]
colnames(pval)=saveColNames[matchIDX2]
row.names(pval)=saveRowNames2[matchIDX]
colnames(coef)=saveColNames2[matchIDX2]
row.names(pval)=saveRowNames2[matchIDX]
row.names(coef)=saveRowNames2[matchIDX]
#matchIDX=match(tolower(row.names(associationTable)),tolower(row.names(coef)))
coef=coef[matchIDX,,drop=FALSE]
saveColNames=colnames(coef)
#=match(tolower(colnames(associationTable)),tolower(colnames(coef)))
#coef=coef[,matchIDX,drop=FALSE]
colnames(coef)=saveColNames[matchIDX2]
important=rep("",dim(pval)[1]*dim(pval)[2])
important[which(pval<0.05)]="*"
important[which(pval<0.01)]="**"
important[which(pval<0.005)]="***"
important=matrix(important,nrow=24,ncol=78)
pdf(file="PERMANOVA_heatmap_PvalAndNMI.pdf",width=30,height=8)
Heatmap(as.matrix(associationTable),
column_split = data.frame(categories),
col = colorRampPalette(brewer.pal(n = 9, name = "Blues"))(100),
column_title_gp = gpar(fill = c("red", "blue", "green","orange","purple")),
cluster_rows = FALSE,
column_order = sort(colnames(associationTable)),
cell_fun = function(j, i, x, y, width, height, fill) {
grid.text(sprintf("%s", important[i, j]), x, y, gp = gpar(fontsize = 8,fontface="bold",col="white"))
})
dev.off()
pdf(file="PERMANOVA_heatmap_Pval.pdf",width=30,height=8)
Heatmap(as.matrix(pval),
column_split = data.frame(categories),
col = rev(colorRampPalette(brewer.pal(n = 9, name = "Blues"))(100)),
column_title_gp = gpar(fill = c("red", "blue", "green","orange","purple")),
cluster_rows = FALSE,
column_order = sort(colnames(associationTable)),
cell_fun = function(j, i, x, y, width, height, fill) {
grid.text(sprintf("%s", important[i, j]), x, y, gp = gpar(fontsize = 8,fontface="bold",col="white"))
})
dev.off()