-
Notifications
You must be signed in to change notification settings - Fork 41
/
server-samplegroupplots.R
130 lines (100 loc) · 4.47 KB
/
server-samplegroupplots.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
## ==================================================================================== ##
# START Shiny App for analysis and visualization of transcriptome data.
# Copyright (C) 2016 Jessica Minnier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# You may contact the author of this code, Jessica Minnier, at <minnier@ohsu.edu>
## ==================================================================================== ##
##
# update expression names for plotting
observe({
print("server-samplegroupplots-update-yname")
data_analyzed = analyzeDataReactive()
tmpdatlong = data_analyzed$data_long
tmpynames = tmpdatlong%>%select(-unique_id,-sampleid,-group,-one_of("rep"))%>%colnames()
updateRadioButtons(session,'groupplot_valuename',
choices=sort(tmpynames,decreasing = TRUE))
})
#update list of groups
observe({
print("server-samplegroupplots-update-groups")
data_analyzed = analyzeDataReactive()
tmpgroups = data_analyzed$group_names
tmpsamples = as.character(data_analyzed$sampledata$sampleid)
updateSelectizeInput(session,'sampleres_groups',
choices=tmpgroups, selected=tmpgroups)
updateSelectizeInput(session,'sampleres_samples',
choices=tmpsamples, selected=tmpsamples)
})
# sampleres_groups = intersect selected groups with sample names
observe({
print("server-sampleplots-update-samples")
data_analyzed = analyzeDataReactive()
tmpgroups = input$sampleres_groups
tmpdat = data_analyzed$sampledata%>%filter(group%in%tmpgroups)
tmpsamples = as.character(tmpdat$sampleid)
updateSelectizeInput(session,'sampleres_samples',
choices=tmpsamples, selected=tmpsamples)
})
fun_gene_pheatmap <- reactive({
print("render gene_pheatmap")
data_analyzed = analyzeDataReactive()
data_results = data_analyzed$results
geneids = data_analyzed$geneids
sampledata = data_analyzed$sampledata
tmpgroups = input$sampleres_groups
tmpsamples = input$sampleres_samples
tmplong = data_analyzed$data_long
tmplong = tmplong%>%filter(sampleid%in%tmpsamples,group%in%tmpgroups)
validate(need(nrow(tmplong)>1,message = "Need more samples to plot."))
tmpkeep = which((sampledata$group%in%tmpgroups)&(sampledata$sampleid%in%tmpsamples))
gene_pheatmap(data_long=tmplong,valuename=input$groupplot_valuename,
sampleid=sampledata$sampleid[tmpkeep],
annotation_row = sampledata[tmpkeep,c("group"),drop=FALSE])
})
fun_pca_plot <- reactive({
print("render PCA plot")
data_analyzed = analyzeDataReactive()
data_results = data_analyzed$results
geneids = data_analyzed$geneids
sampledata = data_analyzed$sampledata
tmpgroups = input$sampleres_groups
tmpsamples = input$sampleres_samples
tmplong = data_analyzed$data_long
tmplong = tmplong%>%filter(sampleid%in%tmpsamples,group%in%tmpgroups)
tmpkeep = which((sampledata$group%in%tmpgroups)&(sampledata$sampleid%in%tmpsamples))
validate(need(nrow(tmplong)>1,message = "Need more samples to plot."))
validate(need(length(input$pcnum)==2,message = "Select 2 Prinical Components."))
gene_pcaplot(data_long=tmplong,
valuename=input$groupplot_valuename,
sampleid= sampledata$sampleid[tmpkeep],
groupdat= sampledata[tmpkeep,c("sampleid","group")],
pcnum = as.numeric(input$pcnum),
colorfactor="group")
})
output$pca_plot <- renderPlot({fun_pca_plot()})
output$download_pca_plot <- downloadHandler(
filename = "pcaplot.png",
content = function(file) {
ggplot2::ggsave(filename = file, plot = fun_pca_plot(), device = "png", dpi = "retina")
}
)
output$gene_pheatmap <- renderPlot({fun_gene_pheatmap()})
output$download_gene_pheatmap <- downloadHandler(
filename = "sample_heatmap.png",
content = function(file) {
ggplot2::ggsave(filename = file, plot = fun_gene_pheatmap(), device = "png", dpi = "retina")
}
)