-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathheatmap.R
113 lines (91 loc) · 2.61 KB
/
heatmap.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
# heatmap
#heatmapGenes <- reactive({
# if(input$Genes != "Paste a gene list, one gene per line..."){
# Genes = input$Genes
# Genes = strsplit(Genes, "\\s+")[[1]]
#
# Genes = intersect(rownames(Expression), Genes)
#
# if (length(Genes) <= 2){
# return("Genelist must contains more than 2 genes")
# }
#
# ExpressionSelected = Expression[Genes,]
#
# return(rownames(ExpressionSelected))
#
# } else if (exists("DEGs")){
# return(DEGs)
#
# } else {
# return("Paste Genes Frist .")
# }
# })
# output$heatmapGenes = renderPrint({
# heatmapGenes()
# })
heatMAP <- function(scale, clust, rowname){
withProgress(message = 'Plot Heatmaps ', value = 0, {
Expression = EXP()$Expression
DEGs = values$DEGs
if(input$Genes != "Paste a gene list, one gene per line..."){
Genes = input$Genes
Genes = strsplit(Genes, "\\s+")[[1]]
Genes = intersect(rownames(Expression), Genes)
if (length(Genes) <= 2){
return(NULL)
}
} else if (!is.null(DEGs)) {
Genes = rownames(DEGs)
} else {
return(NULL)
}
incProgress(1/2, detail = "Ploting, Please Wait.")
ExpressionSelected = Expression[Genes,]
ExpressionSelected = log10(ExpressionSelected + 1)
if ("column" %in% clust){
C = TRUE
} else {
C = FALSE
}
if ("row" %in% clust){
R = TRUE
} else {
R = FALSE
}
library(RColorBrewer)
library(gplots)
hmcol = colorRampPalette(brewer.pal(11, "RdYlBu"))(100)
if (rowname){
heatmap.2(as.matrix(ExpressionSelected), trace="none", col = rev(hmcol), scale = scale, Rowv = R, Colv = C, main="Gene Expression Heatmap")
} else {
heatmap.2(as.matrix(ExpressionSelected), trace="none", col = rev(hmcol), scale = scale, Rowv = R, Colv = C, labRow = "", main="Gene Expression Heatmap")
}
incProgress(2/2, detail = "Plotting, Please Wait.")
})
}
#heatmapPlot <- eventReactive(input$plotButton, {
# heatMAP()
#})
output$plot.ui <- renderUI({
plotOutput("heatmapP", width = paste0(input$heatmapWidth, "px"), height = paste0(input$heatmapHeight, "px"))
})
output$heatmapP <- renderPlot({
heatMAP(heatmap_R(), heatmap_G(), heatmap_RN())
})
heatmap_R = reactive({
switch(input$HeatmapRadio,
"row" = "row",
"column" = "column",
"none" = "none"
)
})
heatmap_G = reactive({
input$HeatmapGroup
})
heatmap_RN = reactive({
switch(input$HeatmapRownames,
"Show" = TRUE,
"Hide" = FALSE
)
})