... | ... |
@@ -188,17 +188,20 @@ function(input, output, session) { |
188 | 188 |
req(rv$gs) |
189 | 189 |
tagList( |
190 | 190 |
br(), |
191 |
- div("To see the Empirical Cumulative Distribution Function |
|
192 |
- of a Sample, click on its line in this plot and go to the |
|
193 |
- 'Gene.Set' Panel", style="text-align: center;") |
|
191 |
+ div("Non-parametric kernel density estimation of sample |
|
192 |
+ profiles of GSVA enrichment scores. Clicking on the |
|
193 |
+ line of a sample will display the empirical cumulative |
|
194 |
+ distribution of GSVA scores for that sample on the |
|
195 |
+ 'GeneSets' tab", style="text-align: center;") |
|
194 | 196 |
) |
195 | 197 |
}) |
196 | 198 |
|
197 | 199 |
# TABLE |
198 | 200 |
output$result <- renderTable({ |
199 | 201 |
req(rv$gs) |
200 |
- resultInformation <- data.frame("Nr of gene sets" = nrow(rv$gs), |
|
201 |
- "Nr of samples" = ncol(rv$gs)) |
|
202 |
+ resultInformation <- data.frame("Nr. of gene sets" = nrow(rv$gs), |
|
203 |
+ "Nr. of samples" = ncol(rv$gs), |
|
204 |
+ check.names=FALSE) |
|
202 | 205 |
resultInformation |
203 | 206 |
}, bordered = TRUE) |
204 | 207 |
|
... | ... |
@@ -212,9 +215,11 @@ function(input, output, session) { |
212 | 215 |
output$text3 <- renderUI({ |
213 | 216 |
tagList( |
214 | 217 |
br(), |
215 |
- div("To see the Kernel Density Estimation of genes of any given |
|
216 |
- Gene Set in this Sample, click on any point in this plot and a |
|
217 |
- second plot will appear bellow it", style = "text-align: center;") |
|
218 |
+ div("Empirical cumulative distribution of GSVA scores, where each |
|
219 |
+ point is a gene set. Clicking on a gene set will display below |
|
220 |
+ the individual gene expression values of its constituent genes |
|
221 |
+ and the non-parametric kernel density estimation of their |
|
222 |
+ distribution", style = "text-align: center;") |
|
218 | 223 |
) |
219 | 224 |
}) |
220 | 225 |
|
... | ... |
@@ -181,14 +181,17 @@ function(input, output, session) { |
181 | 181 |
|
182 | 182 |
# CLOSE BTN |
183 | 183 |
closeBtnServer("close", reactive(rv$gs)) |
184 |
- |
|
184 |
+ |
|
185 | 185 |
|
186 | 186 |
# TEXT1 |
187 | 187 |
output$text1 <- renderUI({ |
188 | 188 |
req(rv$gs) |
189 |
- HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function |
|
190 |
- of a Sample, click on its line in this plot and go |
|
191 |
- to the 'Gene.Set' Panel", "<br/>", sep="<br/>")) |
|
189 |
+ tagList( |
|
190 |
+ br(), |
|
191 |
+ div("To see the Empirical Cumulative Distribution Function |
|
192 |
+ of a Sample, click on its line in this plot and go to the |
|
193 |
+ 'Gene.Set' Panel", style="text-align: center;") |
|
194 |
+ ) |
|
192 | 195 |
}) |
193 | 196 |
|
194 | 197 |
# TABLE |
... | ... |
@@ -181,14 +181,17 @@ function(input, output, session) { |
181 | 181 |
|
182 | 182 |
# CLOSE BTN |
183 | 183 |
closeBtnServer("close", reactive(rv$gs)) |
184 |
- |
|
184 |
+ |
|
185 | 185 |
|
186 | 186 |
# TEXT1 |
187 | 187 |
output$text1 <- renderUI({ |
188 | 188 |
req(rv$gs) |
189 |
- HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function |
|
190 |
- of a Sample, click on its line in this plot and go |
|
191 |
- to the 'Gene.Set' Panel", "<br/>", sep="<br/>")) |
|
189 |
+ tagList( |
|
190 |
+ br(), |
|
191 |
+ div("To see the Empirical Cumulative Distribution Function |
|
192 |
+ of a Sample, click on its line in this plot and go to the |
|
193 |
+ 'Gene.Set' Panel", style="text-align: center;") |
|
194 |
+ ) |
|
192 | 195 |
}) |
193 | 196 |
|
194 | 197 |
# TABLE |
... | ... |
@@ -22,7 +22,8 @@ function(input, output, session) { |
22 | 22 |
|
23 | 23 |
## REACTIVE VALUES |
24 | 24 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
25 |
- p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL) |
|
25 |
+ p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL, |
|
26 |
+ method=NULL) |
|
26 | 27 |
gsva.cancel <- reactiveVal(FALSE) |
27 | 28 |
|
28 | 29 |
## GSVA RESULT |
... | ... |
@@ -41,6 +42,7 @@ function(input, output, session) { |
41 | 42 |
rv$p3 <- NULL |
42 | 43 |
rv$sample.c <- NULL |
43 | 44 |
rv$errors.gsva <- NULL |
45 |
+ rv$method <- argInp$method() |
|
44 | 46 |
|
45 | 47 |
## this is a flag for the future. Futures cannot be canceled or |
46 | 48 |
## terminated in a strict way, so when they get interrupted they |
... | ... |
@@ -129,6 +129,12 @@ function(input, output, session) { |
129 | 129 |
plot2_Server("plot2", eventData1, rv) |
130 | 130 |
|
131 | 131 |
# PLOT3 RENDER |
132 |
+ |
|
133 |
+ ## Whenever the user clicks on the first plot, the third one resets |
|
134 |
+ observeEvent(eventData1(), { |
|
135 |
+ runjs("Shiny.setInputValue('plotly_click-click2', null);") |
|
136 |
+ }) |
|
137 |
+ |
|
132 | 138 |
eventData2 <- reactive({ |
133 | 139 |
req(rv$p2) |
134 | 140 |
ind <- event_data("plotly_click", source = "click2") |
... | ... |
@@ -122,10 +122,9 @@ function(input, output, session) { |
122 | 122 |
|
123 | 123 |
# PLOT2 RENDER |
124 | 124 |
eventData1 <- reactive({ |
125 |
- req(rv$dat.t) |
|
125 |
+ if(is.null(rv$p))return(NULL) |
|
126 | 126 |
ind <- event_data("plotly_click", source = "click1") |
127 | 127 |
ind <- ind$curveNumber+1 |
128 |
- |
|
129 | 128 |
}) |
130 | 129 |
plot2_Server("plot2", eventData1, rv) |
131 | 130 |
|
... | ... |
@@ -134,7 +133,6 @@ function(input, output, session) { |
134 | 133 |
req(rv$p2) |
135 | 134 |
ind <- event_data("plotly_click", source = "click2") |
136 | 135 |
ind <- ind$pointNumber+1 |
137 |
- |
|
138 | 136 |
}) |
139 | 137 |
plot3_Server("plot3", eventData2, rv, matrix, genesets) |
140 | 138 |
|
... | ... |
@@ -161,12 +159,12 @@ function(input, output, session) { |
161 | 159 |
} |
162 | 160 |
}) |
163 | 161 |
|
164 |
- ## HIDE 'GeneSets' PANEL WHILE THERE IS NO GSVA OBJECT |
|
162 |
+ ## HIDE 'GeneSets' PANEL WHILE THERE IS NO CLICK EVENT ON THE FIRST PLOT |
|
165 | 163 |
observe({ |
166 |
- if(is.null(rv$gs)) { |
|
167 |
- hideTab(inputId="Panels", target="GeneSets") |
|
164 |
+ if( length(eventData1()) == 0){ |
|
165 |
+ hideTab(inputId = "Panels", target = "GeneSets") |
|
168 | 166 |
} else { |
169 |
- showTab(inputId="Panels", target="GeneSets") |
|
167 |
+ showTab(inputId = "Panels", target = "GeneSets", select = TRUE) |
|
170 | 168 |
} |
171 | 169 |
}) |
172 | 170 |
|
... | ... |
@@ -4,143 +4,9 @@ function(input, output, session) { |
4 | 4 |
rout <- tempfile("consoleText", fileext = ".txt") |
5 | 5 |
file.create(rout) |
6 | 6 |
console.text <- reactiveFileReader(200, session, rout, readLines, warn=F) |
7 |
-<<<<<<< HEAD |
|
8 |
- |
|
9 |
- # ERRORS MESSAGES |
|
10 |
- output$errorsGsva <- renderText({ |
|
11 |
- req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau()) |
|
12 |
- rv$errors.gsva |
|
13 |
- }) |
|
14 |
- |
|
15 |
- # ENABLING 'RUN' BTN |
|
16 |
- observe({ |
|
17 |
- if(!is.null(matrix()) && !is.null(genesets())){ |
|
18 |
- enable("button") |
|
19 |
- } else { |
|
20 |
- disable("button") |
|
21 |
- } |
|
22 |
- }) |
|
23 |
- |
|
24 |
- ### INPUTS ### |
|
25 |
- |
|
26 |
- # DATA MATRIX |
|
27 |
- matrix <- matrixServer("matrix1") |
|
28 |
- |
|
29 |
- # GENES |
|
30 |
- genesets <- geneSetsServer("genes1") |
|
31 |
- |
|
32 |
- # ARGUMENTS |
|
33 |
- argInp <- argumentsDataServer("argumentsInput") |
|
34 |
- |
|
35 |
- |
|
36 |
- #### GSVA RESULTS #### |
|
37 |
- |
|
38 |
- ## REACTIVE VALUES |
|
39 |
- rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
|
40 |
- p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL) |
|
41 |
- gsva.cancel <- reactiveVal(FALSE) |
|
42 |
- |
|
43 |
- ## GSVA RESULT |
|
44 |
- observeEvent( input$button, { |
|
45 |
- |
|
46 |
- ## This js is in order to reset the event_data from the plotlys, |
|
47 |
- ## so every time the .user hits the 'run' button, plotlys get back to null |
|
48 |
- runjs("Shiny.setInputValue('plotly_click-click1', null);") |
|
49 |
- runjs("Shiny.setInputValue('plotly_click-click2', null);") |
|
50 |
- |
|
51 |
- ## here we reset all the reactiveValues to NULL |
|
52 |
- rv$gs <- NULL |
|
53 |
- rv$dat.t <- NULL |
|
54 |
- rv$p <- NULL |
|
55 |
- rv$p2 <- NULL |
|
56 |
- rv$p3 <- NULL |
|
57 |
- rv$sample.c <- NULL |
|
58 |
- rv$errors.gsva <- NULL |
|
59 |
- |
|
60 |
- ## this is a flag for the future. Futures cannot be canceled or |
|
61 |
- ## terminated in a strict way, so when they get interrupted they |
|
62 |
- ## throw an error that is not related to gsva(). When future is |
|
63 |
- ## interrupted, the flag goes TRUE in order to make the errors |
|
64 |
- ## message print NULL |
|
65 |
- gsva.cancel(FALSE) |
|
66 |
- |
|
67 |
- modalGSVAUI("modal.text") |
|
68 |
- |
|
69 |
- ## future() cannot take reactive values, so we must isolate() them |
|
70 |
- future({ |
|
71 |
- ## sink() will redirect all console cats and prints to a |
|
72 |
- ## text file that the main session will be reading in order |
|
73 |
- ## to print the progress bar from bplaply() |
|
74 |
- sink(rout) |
|
75 |
- result <- gsva(isolate(matrix()), |
|
76 |
- isolate(genesets()), |
|
77 |
- method=isolate(argInp$method()), |
|
78 |
- kcdf=isolate(argInp$kcdf()), |
|
79 |
- abs.ranking=isolate(argInp$absRanking()), |
|
80 |
- min.sz= isolate(argInp$varMinsz()), |
|
81 |
- max.sz=isolate(argInp$varMaxsz()), |
|
82 |
- parallel.sz=1L, ## by now, disable parallelism |
|
83 |
- mx.diff=isolate(argInp$mxDiff()), |
|
84 |
- tau=isolate(argInp$selectedTau()), |
|
85 |
- ssgsea.norm=isolate(argInp$ssgseaNorm()), |
|
86 |
- verbose=TRUE) |
|
87 |
- sink() |
|
88 |
- ## when gsva() ends, we reset the console text file to empty |
|
89 |
- write("", file=rout) |
|
90 |
- return(result) |
|
91 |
- }, seed = TRUE) %...>% |
|
92 |
- (function(result){ |
|
93 |
- ## the future's result will be the gsva() result, and we save it |
|
94 |
- ## and transform it in reactiveValues(). In order to make the future |
|
95 |
- ## not block the app at an inner-session level, we save the results in |
|
96 |
- ## reactiveValues() and then at the end of the observeEvent() we return NULL |
|
97 |
- ## in order to make the plots. |
|
98 |
- ## https://github.com/rstudio/promises/issues/23#issuecomment-386687705 |
|
99 |
- rv$gs <- result |
|
100 |
- rv$dat.t <- melt(as.data.table(rv$gs, keep.rownames = "gene.sets"), |
|
101 |
- variable.name = "Sample", id.vars="gene.sets") |
|
102 |
- rv$n <- length(levels(rv$dat.t$Sample)) |
|
103 |
- rv$dd.col <- hcl(h = seq(15, 375, length=rv$n), l = 65, c = 100)[1:rv$n] |
|
104 |
- names(rv$dd.col) <- levels(rv$dat.t$Sample) |
|
105 |
- |
|
106 |
- ## finally, we leave the console.text file empty again and |
|
107 |
- ## remove the modal |
|
108 |
- write("", file=rout) |
|
109 |
- removeModal() |
|
110 |
- }) %...!% |
|
111 |
- (function(error){ |
|
112 |
- ## there can be two ways to get an error here: |
|
113 |
- ## 1. gsva() fails, which is an ok error and should be returnet to user |
|
114 |
- ## 2. User interrupts the future, which shouldn't be printed, that's |
|
115 |
- ## why I use a flag to identify if error comes from pressing "Cancel" btn |
|
116 |
- ## on the modal |
|
117 |
- removeModal() |
|
118 |
- write("", file=rout) |
|
119 |
- if(gsva.cancel()){ |
|
120 |
- rv$errors.gsva <- NULL |
|
121 |
- } else { |
|
122 |
- rv$errors.gsva <- as.character(error) |
|
123 |
- } |
|
124 |
- |
|
125 |
- }) |
|
126 |
- NULL |
|
127 |
- }) |
|
128 |
- |
|
129 |
- # PRINTING CONSOLE.TEXT |
|
130 |
- modalGSVAServer("modal.text", console.text, gsva.cancel, rout) |
|
131 |
- |
|
132 |
- # PLOT1 RENDER |
|
133 |
- plot1_Server("plot1", rv) |
|
134 |
- |
|
135 |
- # PLOT2 RENDER |
|
136 |
- eventData1 <- reactive({ |
|
137 |
- req(rv$dat.t) |
|
138 |
- ind <- event_data("plotly_click", source = "click1") |
|
139 |
- ind <- ind$curveNumber+1 |
|
140 |
-======= |
|
141 | 7 |
|
142 | 8 |
|
143 |
- ##################### INPUTS ##################### |
|
9 |
+ ##################### INPUTS ##################### |
|
144 | 10 |
|
145 | 11 |
# DATA MATRIX |
146 | 12 |
matrix <- matrixServer("matrix1") |
... | ... |
@@ -151,9 +17,8 @@ function(input, output, session) { |
151 | 17 |
# ARGUMENTS |
152 | 18 |
argInp <- argumentsDataServer("argumentsInput") |
153 | 19 |
|
154 |
- |
|
155 | 20 |
|
156 |
- ##################### GSVA RESULTS ################ |
|
21 |
+ ##################### GSVA RESULTS ##################### |
|
157 | 22 |
|
158 | 23 |
## REACTIVE VALUES |
159 | 24 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
... | ... |
@@ -244,47 +109,12 @@ function(input, output, session) { |
244 | 109 |
|
245 | 110 |
}) |
246 | 111 |
NULL |
247 |
->>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d |
|
248 | 112 |
}) |
249 |
- plot2_Server("plot2", eventData1, rv) |
|
250 |
- |
|
251 |
-<<<<<<< HEAD |
|
252 | 113 |
|
253 |
- # PLOT3 RENDER |
|
254 |
- eventData2 <- reactive({ |
|
255 |
- req(rv$p2) |
|
256 |
- ind <- event_data("plotly_click", source = "click2") |
|
257 |
- ind <- ind$pointNumber+1 |
|
258 |
- }) |
|
259 |
- plot3_Server("plot3", eventData2, rv, matrix, genesets) |
|
260 |
- |
|
261 |
- # DWN BTN |
|
262 |
- downloadServer("download", reactive(rv$gs)) |
|
263 |
- |
|
264 |
- # CLOSE BTN |
|
265 |
- closeBtnServer("close", reactive(rv$gs)) |
|
266 |
- |
|
267 |
- |
|
268 |
- # TEXT1 |
|
269 |
- output$text1 <- renderUI({ |
|
270 |
- req(rv$gs) |
|
271 |
- HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function |
|
272 |
- of a Sample, click on its line in this plot and go |
|
273 |
- to the 'Gene.Set' Panel", "<br/>", sep="<br/>")) |
|
274 |
- }) |
|
275 |
- |
|
276 |
- # TABLE |
|
277 |
- output$result <- renderTable({ |
|
278 |
- req(rv$gs) |
|
279 |
- resultInformation <- data.frame("Nr of gene sets" = nrow(rv$gs), |
|
280 |
- "Nr of samples" = ncol(rv$gs)) |
|
281 |
- resultInformation |
|
282 |
-======= |
|
283 | 114 |
# PRINTING CONSOLE.TEXT |
284 | 115 |
modalGSVAServer("modal.text", console.text, gsva.cancel, rout) |
285 | 116 |
|
286 | 117 |
|
287 |
- |
|
288 | 118 |
##################### OUTPUTS ################## |
289 | 119 |
|
290 | 120 |
# PLOT1 RENDER |
... | ... |
@@ -295,46 +125,29 @@ function(input, output, session) { |
295 | 125 |
req(rv$dat.t) |
296 | 126 |
ind <- event_data("plotly_click", source = "click1") |
297 | 127 |
ind <- ind$curveNumber+1 |
298 |
->>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d |
|
128 |
+ |
|
299 | 129 |
}) |
300 | 130 |
plot2_Server("plot2", eventData1, rv) |
301 |
- |
|
302 |
-<<<<<<< HEAD |
|
303 |
- # TEXT2 |
|
304 |
- output$text2 <- renderUI({ |
|
305 |
- title1 <- rv$sample.c |
|
306 |
- h2(tags$b(title1), align ="center") |
|
307 |
-======= |
|
131 |
+ |
|
308 | 132 |
# PLOT3 RENDER |
309 | 133 |
eventData2 <- reactive({ |
310 | 134 |
req(rv$p2) |
311 | 135 |
ind <- event_data("plotly_click", source = "click2") |
312 | 136 |
ind <- ind$pointNumber+1 |
313 |
->>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d |
|
137 |
+ |
|
314 | 138 |
}) |
315 | 139 |
plot3_Server("plot3", eventData2, rv, matrix, genesets) |
316 |
- |
|
317 |
-<<<<<<< HEAD |
|
318 |
- # TEXT3 |
|
319 |
- output$text3 <- renderUI({ |
|
320 |
- HTML(paste("<br/>", "\t To see the Kernel Density Estimation of genes of |
|
321 |
- any given Gene Set in this Sample, click on any point in this plot and a |
|
322 |
- second plot will appear bellow it", "<br/>", sep="<br/>")) |
|
323 |
-======= |
|
140 |
+ |
|
324 | 141 |
# ERRORS MESSAGES |
325 | 142 |
output$errorsGsva <- renderText({ |
326 | 143 |
req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau()) |
327 | 144 |
rv$errors.gsva |
328 |
->>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d |
|
329 | 145 |
}) |
330 | 146 |
|
331 | 147 |
# SESSION INFO |
332 | 148 |
output$sessionInfo <- renderPrint({ |
333 | 149 |
sessionInfo() |
334 | 150 |
}) |
335 |
-<<<<<<< HEAD |
|
336 |
- |
|
337 |
-======= |
|
338 | 151 |
|
339 | 152 |
|
340 | 153 |
##################### UI SETUPS ##################### |
... | ... |
@@ -393,6 +206,4 @@ function(input, output, session) { |
393 | 206 |
second plot will appear bellow it", "<br/>", sep="<br/>")) |
394 | 207 |
}) |
395 | 208 |
|
396 |
- |
|
397 |
->>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d |
|
398 | 209 |
} |
... | ... |
@@ -30,26 +30,46 @@ function(input, output, session) { |
30 | 30 |
|
31 | 31 |
# ARGUMENTS |
32 | 32 |
argInp <- argumentsDataServer("argumentsInput") |
33 |
+ |
|
33 | 34 |
|
34 | 35 |
#### GSVA RESULTS #### |
35 | 36 |
|
37 |
+ ## REACTIVE VALUES |
|
36 | 38 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
37 |
- errors.gsva = NULL) |
|
39 |
+ p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL) |
|
38 | 40 |
gsva.cancel <- reactiveVal(FALSE) |
39 | 41 |
|
42 |
+ ## GSVA RESULT |
|
40 | 43 |
observeEvent( input$button, { |
44 |
+ |
|
45 |
+ ## This js is in order to reset the event_data from the plotlys, |
|
46 |
+ ## so every time the .user hits the 'run' button, plotlys get back to null |
|
41 | 47 |
runjs("Shiny.setInputValue('plotly_click-click1', null);") |
42 | 48 |
runjs("Shiny.setInputValue('plotly_click-click2', null);") |
49 |
+ |
|
50 |
+ ## here we reset all the reactiveValues to NULL |
|
43 | 51 |
rv$gs <- NULL |
44 | 52 |
rv$dat.t <- NULL |
45 | 53 |
rv$p <- NULL |
46 | 54 |
rv$p2 <- NULL |
47 | 55 |
rv$p3 <- NULL |
48 |
- rv$errors.gsva = NULL |
|
56 |
+ rv$sample.c <- NULL |
|
57 |
+ rv$errors.gsva <- NULL |
|
58 |
+ |
|
59 |
+ ## this is a flag for the future. Futures cannot be canceled or |
|
60 |
+ ## terminated in a strict way, so when they get interrupted they |
|
61 |
+ ## throw an error that is not related to gsva(). When future is |
|
62 |
+ ## interrupted, the flag goes TRUE in order to make the errors |
|
63 |
+ ## message print NULL |
|
49 | 64 |
gsva.cancel(FALSE) |
65 |
+ |
|
50 | 66 |
modalGSVAUI("modal.text") |
51 |
- # future() cannot take reactive values, so we must isolate() them |
|
67 |
+ |
|
68 |
+ ## future() cannot take reactive values, so we must isolate() them |
|
52 | 69 |
future({ |
70 |
+ ## sink() will redirect all console cats and prints to a |
|
71 |
+ ## text file that the main session will be reading in order |
|
72 |
+ ## to print the progress bar from bplaply() |
|
53 | 73 |
sink(rout) |
54 | 74 |
result <- gsva(isolate(matrix()), |
55 | 75 |
isolate(genesets()), |
... | ... |
@@ -64,20 +84,35 @@ function(input, output, session) { |
64 | 84 |
ssgsea.norm=isolate(argInp$ssgseaNorm()), |
65 | 85 |
verbose=TRUE) |
66 | 86 |
sink() |
87 |
+ ## when gsva() ends, we reset the console text file to empty |
|
67 | 88 |
write("", file=rout) |
68 | 89 |
return(result) |
69 | 90 |
}, seed = TRUE) %...>% |
70 | 91 |
(function(result){ |
92 |
+ ## the future's result will be the gsva() result, and we save it |
|
93 |
+ ## and transform it in reactiveValues(). In order to make the future |
|
94 |
+ ## not block the app at an inner-session level, we save the results in |
|
95 |
+ ## reactiveValues() and then at the end of the observeEvent() we return NULL |
|
96 |
+ ## in order to make the plots. |
|
97 |
+ ## https://github.com/rstudio/promises/issues/23#issuecomment-386687705 |
|
71 | 98 |
rv$gs <- result |
72 | 99 |
rv$dat.t <- melt(as.data.table(rv$gs, keep.rownames = "gene.sets"), |
73 | 100 |
variable.name = "Sample", id.vars="gene.sets") |
74 | 101 |
rv$n <- length(levels(rv$dat.t$Sample)) |
75 | 102 |
rv$dd.col <- hcl(h = seq(15, 375, length=rv$n), l = 65, c = 100)[1:rv$n] |
76 | 103 |
names(rv$dd.col) <- levels(rv$dat.t$Sample) |
104 |
+ |
|
105 |
+ ## finally, we leave the console.text file empty again and |
|
106 |
+ ## remove the modal |
|
77 | 107 |
write("", file=rout) |
78 | 108 |
removeModal() |
79 | 109 |
}) %...!% |
80 | 110 |
(function(error){ |
111 |
+ ## there can be two ways to get an error here: |
|
112 |
+ ## 1. gsva() fails, which is an ok error and should be returnet to user |
|
113 |
+ ## 2. User interrupts the future, which shouldn't be printed, that's |
|
114 |
+ ## why I use a flag to identify if error comes from pressing "Cancel" btn |
|
115 |
+ ## on the modal |
|
81 | 116 |
removeModal() |
82 | 117 |
write("", file=rout) |
83 | 118 |
if(gsva.cancel()){ |
... | ... |
@@ -111,7 +111,6 @@ function(input, output, session) { |
111 | 111 |
ind <- event_data("plotly_click", source = "click2") |
112 | 112 |
ind <- ind$pointNumber+1 |
113 | 113 |
}) |
114 |
- # plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
115 | 114 |
plot3_Server("plot3", eventData2, rv, matrix, genesets) |
116 | 115 |
|
117 | 116 |
# DWN BTN |
... | ... |
@@ -34,18 +34,18 @@ function(input, output, session) { |
34 | 34 |
#### GSVA RESULTS #### |
35 | 35 |
|
36 | 36 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
37 |
- errors.gsva = NULL, matrix=NULL, genesets=NULL) |
|
37 |
+ errors.gsva = NULL) |
|
38 | 38 |
gsva.cancel <- reactiveVal(FALSE) |
39 | 39 |
|
40 | 40 |
observeEvent( input$button, { |
41 |
+ runjs("Shiny.setInputValue('plotly_click-click1', null);") |
|
42 |
+ runjs("Shiny.setInputValue('plotly_click-click2', null);") |
|
41 | 43 |
rv$gs <- NULL |
42 | 44 |
rv$dat.t <- NULL |
43 | 45 |
rv$p <- NULL |
44 | 46 |
rv$p2 <- NULL |
45 | 47 |
rv$p3 <- NULL |
46 | 48 |
rv$errors.gsva = NULL |
47 |
- rv$matrix <- isolate(matrix()) |
|
48 |
- rv$genesets <- isolate(genesets()) |
|
49 | 49 |
gsva.cancel(FALSE) |
50 | 50 |
modalGSVAUI("modal.text") |
51 | 51 |
# future() cannot take reactive values, so we must isolate() them |
... | ... |
@@ -96,7 +96,6 @@ function(input, output, session) { |
96 | 96 |
# PLOT1 RENDER |
97 | 97 |
plot1_Server("plot1", rv) |
98 | 98 |
|
99 |
- |
|
100 | 99 |
# PLOT2 RENDER |
101 | 100 |
eventData1 <- reactive({ |
102 | 101 |
req(rv$dat.t) |
... | ... |
@@ -112,7 +111,8 @@ function(input, output, session) { |
112 | 111 |
ind <- event_data("plotly_click", source = "click2") |
113 | 112 |
ind <- ind$pointNumber+1 |
114 | 113 |
}) |
115 |
- plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
114 |
+ # plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
115 |
+ plot3_Server("plot3", eventData2, rv, matrix, genesets) |
|
116 | 116 |
|
117 | 117 |
# DWN BTN |
118 | 118 |
downloadServer("download", reactive(rv$gs)) |
... | ... |
@@ -89,7 +89,7 @@ function(input, output, session) { |
89 | 89 |
}) |
90 | 90 |
|
91 | 91 |
# PRINTING CONSOLE.TEXT |
92 |
- modalGSVAServer("modal.text", console.text, gsva.cancel) |
|
92 |
+ modalGSVAServer("modal.text", console.text, gsva.cancel, rout) |
|
93 | 93 |
|
94 | 94 |
# PLOT1 RENDER |
95 | 95 |
plot1_Server("plot1", rv) |
... | ... |
@@ -113,7 +113,7 @@ function(input, output, session) { |
113 | 113 |
plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
114 | 114 |
|
115 | 115 |
# DWN BTN |
116 |
- downloadServer("download", rv$gs) |
|
116 |
+ downloadServer("download", reactive(rv$gs)) |
|
117 | 117 |
|
118 | 118 |
# CLOSE BTN |
119 | 119 |
closeBtnServer("close", reactive(rv$gs)) |
... | ... |
@@ -111,14 +111,12 @@ function(input, output, session) { |
111 | 111 |
ind <- ind$pointNumber+1 |
112 | 112 |
}) |
113 | 113 |
plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
114 |
- |
|
115 |
- # SAVE & CLOSE BTN |
|
116 |
- observeEvent(input$closeSave, { |
|
117 |
- stopApp(rv$gs) #Stops the app and returns the rv$gs object to the R session |
|
118 |
- }) |
|
119 | 114 |
|
120 | 115 |
# DWN BTN |
121 | 116 |
downloadServer("download", rv$gs) |
117 |
+ |
|
118 |
+ # CLOSE BTN |
|
119 |
+ closeBtnServer("close", reactive(rv$gs)) |
|
122 | 120 |
|
123 | 121 |
|
124 | 122 |
# TEXT1 |
... | ... |
@@ -1,361 +1,158 @@ |
1 |
-library(GSVA) |
|
2 |
-library(shiny) |
|
3 |
-library(shinythemes) |
|
4 |
-library(GSEABase) |
|
5 |
-library(GSVAdata) |
|
6 |
-library(limma) |
|
7 |
-library(ggplot2) |
|
8 |
-library(data.table) |
|
9 |
-library(plotly) |
|
10 |
- |
|
11 |
-argumentsDataInput <- function(id) { |
|
12 |
- # Create a namespace function using the provided id |
|
13 |
- ns <- NS(id) |
|
1 |
+function(input, output, session) { |
|
14 | 2 |
|
15 |
- #UI Definition |
|
16 |
- column( |
|
17 |
- 3, |
|
18 |
- conditionalPanel( |
|
19 |
- condition = "input.arg == 'yes'", |
|
20 |
- h3("Select arguments:"), |
|
21 |
- wellPanel(fluidRow( |
|
22 |
- column( |
|
23 |
- 12, |
|
24 |
- selectInput("method", "Choose method:", |
|
25 |
- c("gsva","ssgsea","zscore","plage")), |
|
26 |
- selectInput("kcdf", "Choose kcdf:", |
|
27 |
- c("Gaussian","Poisson","none")), |
|
28 |
- radioButtons("absRanking", "abs.ranking:", |
|
29 |
- c("False" = FALSE, |
|
30 |
- "True" = TRUE)), |
|
31 |
- numericInput("minSz","min.sz:",value = 1), |
|
32 |
- numericInput("maxSz","max.sz (Write 0 for infinite):",value = 0), |
|
33 |
- ## numericInput("parallelSz","parallel.sz:",value = 0), |
|
34 |
- ## selectInput("parallelType", "parallel.type:", |
|
35 |
- ## c("SOCK","MPI","NWS")), |
|
36 |
- radioButtons("mxDiff", "mx.diff:", |
|
37 |
- c("True" = TRUE, |
|
38 |
- "False" = FALSE)), |
|
39 |
- conditionalPanel( |
|
40 |
- condition = "input.method == 'gsva'", |
|
41 |
- numericInput("tau1","tau:",value = 1) |
|
42 |
- ), |
|
43 |
- conditionalPanel( |
|
44 |
- condition = "input.method == 'ssgsea'", |
|
45 |
- numericInput("tau2","tau:",value = 0.25) |
|
46 |
- ), |
|
47 |
- conditionalPanel( |
|
48 |
- condition = "input.method == 'zscore' || input.method == 'plage'" |
|
49 |
- ), |
|
50 |
- radioButtons("ssgseaNorm", "ssgsea.norm:", |
|
51 |
- c("True" = TRUE, |
|
52 |
- "False" = FALSE)), |
|
53 |
- radioButtons("verbose", "verbose:", |
|
54 |
- c("True" = TRUE, |
|
55 |
- "False" = FALSE)) |
|
56 |
- ))) |
|
57 |
- ) |
|
58 |
- ) |
|
59 |
-} |
|
3 |
+ # CREATE REACTIVE FOR CONSOLE TEXT PROGRESS BAR |
|
4 |
+ rout <- tempfile("consoleText", fileext = ".txt") |
|
5 |
+ file.create(rout) |
|
6 |
+ console.text <- reactiveFileReader(200, session, rout, readLines, warn=F) |
|
7 |
+ |
|
8 |
+ # ERRORS MESSAGES |
|
9 |
+ output$errorsGsva <- renderText({ |
|
10 |
+ req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau()) |
|
11 |
+ rv$errors.gsva |
|
12 |
+ }) |
|
60 | 13 |
|
61 |
-gsva_validation <- function(input, output, session) { |
|
62 |
- success <- FALSE #Variable to control if the GSVA variables are assigned correctly |
|
63 |
- if(input$matrixSourceType == "fileMatrix") |
|
64 |
- { |
|
65 |
- if (is.null(input$matrixFile)) |
|
66 |
- { |
|
67 |
- paste("No matrix file selected!") |
|
68 |
- success <- FALSE |
|
69 |
- } |
|
70 |
- else |
|
71 |
- { |
|
72 |
- #Matrix file selected |
|
73 |
- if(input$genesetSourceType == "fileGeneset") |
|
74 |
- { |
|
75 |
- if (is.null(input$genesetFile)) |
|
76 |
- { |
|
77 |
- paste("No geneSet file selected!") |
|
78 |
- success <- FALSE |
|
79 |
- } |
|
80 |
- else |
|
81 |
- { |
|
82 |
- #User selects matrix file and geneSet file |
|
83 |
- inFile <- input$matrixFile |
|
84 |
- newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix |
|
85 |
- rownames(newY) <- newY[,1] #Taking the first column as rownames |
|
86 |
- newY <- newY[,-1] #Deleting the first column |
|
87 |
- inGenesetFile <- input$genesetFile |
|
88 |
- genes <- getGmt(inGenesetFile$datapath) |
|
89 |
- if(input$maxSz == 0) { |
|
90 |
- varMaxsz <- Inf |
|
91 |
- }else { |
|
92 |
- varMaxsz <- input$maxSz |
|
93 |
- } |
|
94 |
- success <- TRUE |
|
95 |
- } |
|
96 |
- } |
|
97 |
- else |
|
98 |
- { |
|
99 |
- #User selects matrix file and geneset var |
|
100 |
- inFile <- input$matrixFile |
|
101 |
- newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix |
|
102 |
- rownames(newY) <- newY[,1] #Taking the first column as rownames |
|
103 |
- newY <- newY[,-1] #Deleting the first column |
|
104 |
- assign("genes",get(input$genesetVar)) |
|
105 |
- if(input$maxSz == 0) { |
|
106 |
- varMaxsz <- Inf |
|
107 |
- }else { |
|
108 |
- varMaxsz <- input$maxSz |
|
109 |
- } |
|
110 |
- success <- TRUE |
|
111 |
- } |
|
14 |
+ # ENABLING 'RUN' BTN |
|
15 |
+ observe({ |
|
16 |
+ if(!is.null(matrix()) && !is.null(genesets())){ |
|
17 |
+ enable("button") |
|
18 |
+ } else { |
|
19 |
+ disable("button") |
|
112 | 20 |
} |
113 |
- } |
|
114 |
- else |
|
115 |
- { |
|
116 |
- #User selects matrix var and geneset file |
|
117 |
- if(input$genesetSourceType == "fileGeneset") |
|
118 |
- { |
|
119 |
- if (is.null(input$genesetFile)) |
|
120 |
- { |
|
121 |
- paste("No geneSet file selected!") |
|
122 |
- success <- FALSE |
|
123 |
- } |
|
124 |
- else |
|
125 |
- { |
|
126 |
- assign("newY",get(input$matrixVar)) |
|
127 |
- inGenesetFile <- input$genesetFile |
|
128 |
- genes <- getGmt(inGenesetFile$datapath) |
|
129 |
- if(input$maxSz == 0) { |
|
130 |
- varMaxsz <- Inf |
|
131 |
- }else { |
|
132 |
- varMaxsz <- input$maxSz |
|
133 |
- } |
|
134 |
- success <- TRUE |
|
135 |
- } |
|
136 |
- } |
|
137 |
- else |
|
138 |
- { |
|
139 |
- #User selects matrix var selected and geneset var |
|
140 |
- assign("newY",get(input$matrixVar)) |
|
141 |
- assign("genes",get(input$genesetVar)) |
|
142 |
- if(input$maxSz == 0) { |
|
143 |
- varMaxsz <- Inf |
|
144 |
- }else { |
|
145 |
- varMaxsz <- input$maxSz |
|
146 |
- } |
|
147 |
- success <- TRUE |
|
148 |
- } |
|
149 |
- } |
|
150 |
- if(success==TRUE) |
|
151 |
- { |
|
152 |
- gsva_generation(input, output, session, newY, genes,varMaxsz) |
|
153 |
- gsva_information(input,output,session, newY, genes) |
|
154 |
- } |
|
155 |
-} |
|
21 |
+ }) |
|
22 |
+ |
|
23 |
+ ### INPUTS ### |
|
24 |
+ |
|
25 |
+ # DATA MATRIX |
|
26 |
+ matrix <- matrixServer("matrix1") |
|
27 |
+ |
|
28 |
+ # GENES |
|
29 |
+ genesets <- geneSetsServer("genes1") |
|
30 |
+ |
|
31 |
+ # ARGUMENTS |
|
32 |
+ argInp <- argumentsDataServer("argumentsInput") |
|
156 | 33 |
|
157 |
-gsva_generation <- function(input, output, session, newY, genes,varMaxsz) { |
|
158 |
- x <- input$method |
|
159 |
- selectedTau <- NULL |
|
160 |
- switch (x, |
|
161 |
- "gsva" = { |
|
162 |
- selectedTau <- input$tau1 |
|
163 |
- }, |
|
164 |
- "ssgsea" = { |
|
165 |
- selectedTau <- input$tau2 |
|
166 |
- }, |
|
167 |
- "zscore" = { |
|
168 |
- selectedTau <- NULL |
|
169 |
- }, |
|
170 |
- "plage" = { |
|
171 |
- selectedTau <- NULL |
|
172 |
- } |
|
173 |
- ) |
|
174 |
- # GSVA Generation |
|
175 |
- withProgress(message = 'Runing GSVA', value = 0, { |
|
176 |
- incProgress(1, detail = "This may take a while...") |
|
177 |
- generated_gsva <<- gsva(newY, genes, method=input$method, kcdf=input$kcdf, |
|
178 |
- abs.ranking=as.logical(input$absRanking), |
|
179 |
- min.sz=input$minSz, max.sz=varMaxsz, |
|
180 |
- parallel.sz=1L, ## by now, disable parallelism |
|
181 |
- mx.diff=as.logical(input$mxDiff), |
|
182 |
- tau=selectedTau, |
|
183 |
- ssgsea.norm=as.logical(input$ssgseaNorm), |
|
184 |
- verbose=as.logical(input$verbose)) |
|
34 |
+ #### GSVA RESULTS #### |
|
35 |
+ |
|
36 |
+ rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
|
37 |
+ errors.gsva = NULL, matrix=NULL, genesets=NULL) |
|
38 |
+ gsva.cancel <- reactiveVal(FALSE) |
|
39 |
+ |
|
40 |
+ observeEvent( input$button, { |
|
41 |
+ rv$gs <- NULL |
|
42 |
+ rv$dat.t <- NULL |
|
43 |
+ rv$p <- NULL |
|
44 |
+ rv$errors.gsva = NULL |
|
45 |
+ rv$matrix <- isolate(matrix()) |
|
46 |
+ rv$genesets <- isolate(genesets()) |
|
47 |
+ gsva.cancel(FALSE) |
|
48 |
+ modalGSVAUI("modal.text") |
|
49 |
+ # future() cannot take reactive values, so we must isolate() them |
|
50 |
+ future({ |
|
51 |
+ sink(rout) |
|
52 |
+ result <- gsva(isolate(matrix()), |
|
53 |
+ isolate(genesets()), |
|
54 |
+ method=isolate(argInp$method()), |
|
55 |
+ kcdf=isolate(argInp$kcdf()), |
|
56 |
+ abs.ranking=isolate(argInp$absRanking()), |
|
57 |
+ min.sz= isolate(argInp$varMinsz()), |
|
58 |
+ max.sz=isolate(argInp$varMaxsz()), |
|
59 |
+ parallel.sz=1L, ## by now, disable parallelism |
|
60 |
+ mx.diff=isolate(argInp$mxDiff()), |
|
61 |
+ tau=isolate(argInp$selectedTau()), |
|
62 |
+ ssgsea.norm=isolate(argInp$ssgseaNorm()), |
|
63 |
+ verbose=TRUE) |
|
64 |
+ sink() |
|
65 |
+ write("", file=rout) |
|
66 |
+ return(result) |
|
67 |
+ }, seed = TRUE) %...>% |
|
68 |
+ (function(result){ |
|
69 |
+ rv$gs <- result |
|
70 |
+ rv$dat.t <- melt(as.data.table(rv$gs, keep.rownames = "gene.sets"), |
|
71 |
+ variable.name = "Sample", id.vars="gene.sets") |
|
72 |
+ rv$n <- length(levels(rv$dat.t$Sample)) |
|
73 |
+ rv$dd.col <- hcl(h = seq(15, 375, length=rv$n), l = 65, c = 100)[1:rv$n] |
|
74 |
+ names(rv$dd.col) <- levels(rv$dat.t$Sample) |
|
75 |
+ write("", file=rout) |
|
76 |
+ removeModal() |
|
77 |
+ }) %...!% |
|
78 |
+ (function(error){ |
|
79 |
+ removeModal() |
|
80 |
+ write("", file=rout) |
|
81 |
+ if(gsva.cancel()){ |
|
82 |
+ rv$errors.gsva <- NULL |
|
83 |
+ } else { |
|
84 |
+ rv$errors.gsva <- as.character(error) |
|
85 |
+ } |
|
86 |
+ |
|
87 |
+ }) |
|
88 |
+ NULL |
|
185 | 89 |
}) |
90 |
+ |
|
91 |
+ # PRINTING CONSOLE.TEXT |
|
92 |
+ modalGSVAServer("modal.text", console.text, gsva.cancel) |
|
93 |
+ |
|
94 |
+ # PLOT1 RENDER |
|
95 |
+ plot1_Server("plot1", rv) |
|
186 | 96 |
|
187 |
-} |
|
188 | 97 |
|
189 |
-gsva_information <- function(input, output, session, newY, genes) { |
|
190 |
- gsva_es <- NA |
|
191 |
- if("matrix" %in% class(generated_gsva)) |
|
192 |
- gsva_es <- as.data.frame(generated_gsva) |
|
193 |
- else if ("ExpressionSet" %in% class(generated_gsva)) |
|
194 |
- gsva_es <- as.data.frame(exprs(generated_gsva)) |
|
195 |
- else if ("SummarizedExperiment" %in% class(generated_gsva)) |
|
196 |
- gsva_es <- as.data.frame(assays(generated_gsva)[[1]]) |
|
197 |
- else |
|
198 |
- stop("Unknown output generated by the call to the 'gsva()' function.") |
|
98 |
+ # PLOT2 RENDER |
|
99 |
+ eventData1 <- reactive({ |
|
100 |
+ req(rv$dat.t) |
|
101 |
+ ind <- event_data("plotly_click", source = "click1") |
|
102 |
+ ind <- ind$curveNumber+1 |
|
103 |
+ }) |
|
104 |
+ plot2_Server("plot2", eventData1, rv) |
|
105 |
+ |
|
106 |
+ |
|
107 |
+ # PLOT3 RENDER |
|
108 |
+ eventData2 <- reactive({ |
|
109 |
+ req(rv$p2) |
|
110 |
+ ind <- event_data("plotly_click", source = "click2") |
|
111 |
+ ind <- ind$pointNumber+1 |
|
112 |
+ }) |
|
113 |
+ plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
114 |
+ |
|
115 |
+ # SAVE & CLOSE BTN |
|
116 |
+ observeEvent(input$closeSave, { |
|
117 |
+ stopApp(rv$gs) #Stops the app and returns the rv$gs object to the R session |
|
118 |
+ }) |
|
119 |
+ |
|
120 |
+ # DWN BTN |
|
121 |
+ downloadServer("download", rv$gs) |
|
199 | 122 |
|
200 |
- #Rendering text1 |
|
123 |
+ |
|
124 |
+ # TEXT1 |
|
201 | 125 |
output$text1 <- renderUI({ |
126 |
+ req(rv$gs) |
|
202 | 127 |
HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function |
203 | 128 |
of a Sample, click on its line in this plot and go |
204 | 129 |
to the 'Gene.Set' Panel", "<br/>", sep="<br/>")) |
205 | 130 |
}) |
206 | 131 |
|
207 |
- # Rendering graph1 |
|
208 |
- dat.t <- melt(as.data.table(generated_gsva, keep.rownames = "gene.sets"), |
|
209 |
- variable.name = "Sample", id.vars="gene.sets") |
|
210 |
- n <- length(levels(dat.t$Sample)) |
|
211 |
- dd.col <- hcl(h = seq(15, 375, length=n), l = 65, c = 100)[1:n] |
|
212 |
- names(dd.col) <- levels(dat.t$Sample) |
|
213 |
- |
|
214 |
- |
|
215 |
- output$plot <- renderPlotly({ |
|
216 |
- p <- ggplot(data = dat.t, aes(x=value, color=Sample)) + |
|
217 |
- stat_density(geom="line", position = "identity") + |
|
218 |
- theme(legend.position = "none") + labs(x="GSVA Scores", y="Density") + |
|
219 |
- scale_color_manual("Legend", values = dd.col) |
|
220 |
- ggplotly(p, tooltip = "Sample", source = "click1") |
|
132 |
+ # TABLE |
|
133 |
+ output$result <- renderTable({ |
|
134 |
+ req(rv$gs) |
|
135 |
+ resultInformation <- data.frame("Nr of gene sets" = nrow(rv$gs), |
|
136 |
+ "Nr of samples" = ncol(rv$gs)) |
|
137 |
+ resultInformation |
|
221 | 138 |
}) |
222 | 139 |
|
223 |
- # Rendering table |
|
224 |
- resultInformation <- matrix(data = c(nrow(generated_gsva), |
|
225 |
- ncol(generated_gsva)), |
|
226 |
- nrow = 1, ncol = 2) |
|
227 |
- colnames(resultInformation) <- c("Nr. of gene sets", "Nr. of samples") |
|
228 |
- output$result <- renderTable(resultInformation) |
|
229 |
- |
|
230 |
- #Rendering text2 |
|
140 |
+ # TEXT2 |
|
231 | 141 |
output$text2 <- renderUI({ |
232 |
- title1 <- sample.c() |
|
142 |
+ title1 <- rv$sample.c |
|
233 | 143 |
h2(tags$b(title1), align ="center") |
234 | 144 |
}) |
235 | 145 |
|
236 |
- #Rendering text3 |
|
146 |
+ # TEXT3 |
|
237 | 147 |
output$text3 <- renderUI({ |
238 | 148 |
HTML(paste("<br/>", "\t To see the Kernel Density Estimation of genes of |
239 | 149 |
any given Gene Set in this Sample, click on any point in this plot and a |
240 | 150 |
second plot will appear bellow it", "<br/>", sep="<br/>")) |
241 | 151 |
}) |
242 | 152 |
|
243 |
- #Rendering graph2 |
|
244 |
- eventData1 <- reactive({ |
|
245 |
- event_data("plotly_click", source = "click1") |
|
246 |
- }) |
|
247 |
- |
|
248 |
- sample.c <- reactive({ |
|
249 |
- req(eventData1()) |
|
250 |
- ind <- eventData1()$curveNumber+1 |
|
251 |
- colnames(generated_gsva)[ind] |
|
252 |
- }) |
|
253 |
- |
|
254 |
- plot2 <- reactive({ |
|
255 |
- req(sample.c()) |
|
256 |
- data <- dat.t[Sample==sample.c()] |
|
257 |
- p <- ggplot(data = data, aes(x=value, color=Sample)) + |
|
258 |
- stat_ecdf(geom="point") + theme(legend.position = "none") + |
|
259 |
- labs(x="GSVA Scores in selected sample", y="Empirical Cumulative Density") + |
|
260 |
- scale_color_manual("Legend", values = dd.col) |
|
261 |
- p <- ggplotly(p, source="click2") %>% style(text=data$gene.sets) |
|
262 |
- }) |
|
263 |
- |
|
264 |
- output$plot2 <- renderPlotly({ |
|
265 |
- req(plot2()) |
|
266 |
- plot2() |
|
267 |
- }) |
|
268 |
- |
|
269 |
- # Rendering graph 3 |
|
270 |
- eventData2 <- reactive({ |
|
271 |
- event_data("plotly_click", source = "click2") |
|
272 |
- }) |
|
273 |
- |
|
274 |
- gene.set <- reactive({ |
|
275 |
- plot2()$x$data[[1]]$text[eventData2()$pointNumber+1] |
|
276 |
- }) |
|
277 |
- |
|
278 |
- output$plot3 <- renderPlotly({ |
|
279 |
- req(eventData2()) |
|
280 |
- genes.toplot <- geneIds(genes)[[gene.set()]] |
|
281 |
- mt <- match(genes.toplot, rownames(newY)) |
|
282 |
- x <- newY[na.omit(mt), sample.c()] |
|
283 |
- df <- as.data.frame(x) |
|
284 |
- df$x <- as.numeric(df$x) |
|
285 |
- df$Gene <- rownames(df) |
|
286 |
- df$Sample <- sample.c() |
|
287 |
- p1 <- ggplot(data = df, aes(x=x, color = Sample, label = Gene)) + |
|
288 |
- stat_density(geom="line", position = "identity") + |
|
289 |
- geom_rug() + theme(legend.position = "none") + |
|
290 |
- labs(x="Gene Expressions in selected sample", y="Density") + |
|
291 |
- xlim(as.numeric(range(newY))) + |
|
292 |
- scale_color_manual("legend", values= dd.col) |
|
293 |
- ggplotly(p1, tooltip = c("Gene", "x")) %>% style(hoverinfo="none", traces = 1) %>% |
|
294 |
- layout(title = list(text = paste0('<br><sup><i>', gene.set(), '</i></sup>'), |
|
295 |
- font = list(size=15))) |
|
296 |
- }) |
|
297 |
- |
|
298 |
- # Rendering Session Info |
|
153 |
+ # SESSION INFO |
|
299 | 154 |
output$sessionInfo <- renderPrint({ |
300 | 155 |
sessionInfo() |
301 | 156 |
}) |
302 |
- |
|
303 |
- tagList( |
|
304 |
- downloadButton('downloadData', 'Download'), |
|
305 |
- actionButton('closeSave','Save & Close') |
|
306 |
- ) |
|
307 |
-} |
|
308 | 157 |
|
309 |
-download_handler <- function(input, output, session) { |
|
310 |
- #Controls the Download button |
|
311 |
- output$downloadData <- downloadHandler( |
|
312 |
- filename = function() { |
|
313 |
- paste("gsva_es-", Sys.Date(), ".csv", sep="") |
|
314 |
- }, |
|
315 |
- content = function(file) { |
|
316 |
- if("matrix" %in% class(generated_gsva)) # if the whole object is a matrix |
|
317 |
- { |
|
318 |
- dataFrameObs <- as.data.frame(generated_gsva) |
|
319 |
- write.csv(dataFrameObs, file) |
|
320 |
- } |
|
321 |
- else |
|
322 |
- { |
|
323 |
- if("ExpressionSet" %in% class(generated_gsva)) #If the generated gsva result object is an ExpressionSet |
|
324 |
- { |
|
325 |
- expressionSetObs <- exprs(generated_gsva) |
|
326 |
- dataFrameObs <- as.data.frame(expressionSetObs) |
|
327 |
- write.csv(dataFrameObs, file) |
|
328 |
- } |
|
329 |
- else |
|
330 |
- { |
|
331 |
- dataFrameObs <- as.data.frame(generated_gsva) |
|
332 |
- write.csv(dataFrameObs, file) |
|
333 |
- } |
|
334 |
- } |
|
335 |
- } |
|
336 |
- ) |
|
337 |
-} |
|
338 |
- |
|
339 |
-function(input, output, session) { |
|
340 |
- v <- reactiveValues(action = FALSE) |
|
341 |
- |
|
342 |
- observeEvent(input$button, { |
|
343 |
- v$action <- input$button |
|
344 |
- }) |
|
345 |
- |
|
346 |
- output$download <- renderUI({ |
|
347 |
- if(v$action) |
|
348 |
- { |
|
349 |
- #Isolates the Run event, that allows the program to run the generation only if the user clicks the button. |
|
350 |
- isolate({ |
|
351 |
- gsva_validation(input,output,session) |
|
352 |
- }) |
|
353 |
- } |
|
354 |
- }) |
|
355 |
- download_handler(input,output,session) |
|
356 |
- |
|
357 |
- #Observe the Save & Close button |
|
358 |
- observeEvent(input$closeSave, { |
|
359 |
- stopApp(generated_gsva) #Stops the app and returns the generated_gsva object |
|
360 |
- }) |
|
361 | 158 |
} |
... | ... |
@@ -5,22 +5,8 @@ function(input, output, session) { |
5 | 5 |
file.create(rout) |
6 | 6 |
console.text <- reactiveFileReader(200, session, rout, readLines, warn=F) |
7 | 7 |
|
8 |
- # ERRORS MESSAGES |
|
9 |
- output$errorsGsva <- renderText({ |
|
10 |
- req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau()) |
|
11 |
- rv$errors.gsva |
|
12 |
- }) |
|
13 |
- |
|
14 |
- # ENABLING 'RUN' BTN |
|
15 |
- observe({ |
|
16 |
- if(!is.null(matrix()) && !is.null(genesets())){ |
|
17 |
- enable("button") |
|
18 |
- } else { |
|
19 |
- disable("button") |
|
20 |
- } |
|
21 |
- }) |
|
22 | 8 |
|
23 |
- ### INPUTS ### |
|
9 |
+ ##################### INPUTS ##################### |
|
24 | 10 |
|
25 | 11 |
# DATA MATRIX |
26 | 12 |
matrix <- matrixServer("matrix1") |
... | ... |
@@ -31,8 +17,9 @@ function(input, output, session) { |
31 | 17 |
# ARGUMENTS |
32 | 18 |
argInp <- argumentsDataServer("argumentsInput") |
33 | 19 |
|
20 |
+ |
|
34 | 21 |
|
35 |
- #### GSVA RESULTS #### |
|
22 |
+ ##################### GSVA RESULTS ################ |
|
36 | 23 |
|
37 | 24 |
## REACTIVE VALUES |
38 | 25 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
... | ... |
@@ -128,6 +115,10 @@ function(input, output, session) { |
128 | 115 |
# PRINTING CONSOLE.TEXT |
129 | 116 |
modalGSVAServer("modal.text", console.text, gsva.cancel, rout) |
130 | 117 |
|
118 |
+ |
|
119 |
+ |
|
120 |
+ ##################### OUTPUTS ################## |
|
121 |
+ |
|
131 | 122 |
# PLOT1 RENDER |
132 | 123 |
plot1_Server("plot1", rv) |
133 | 124 |
|
... | ... |
@@ -139,7 +130,6 @@ function(input, output, session) { |
139 | 130 |
}) |
140 | 131 |
plot2_Server("plot2", eventData1, rv) |
141 | 132 |
|
142 |
- |
|
143 | 133 |
# PLOT3 RENDER |
144 | 134 |
eventData2 <- reactive({ |
145 | 135 |
req(rv$p2) |
... | ... |
@@ -148,7 +138,39 @@ function(input, output, session) { |
148 | 138 |
}) |
149 | 139 |
plot3_Server("plot3", eventData2, rv, matrix, genesets) |
150 | 140 |
|
151 |
- # DWN BTN |
|
141 |
+ # ERRORS MESSAGES |
|
142 |
+ output$errorsGsva <- renderText({ |
|
143 |
+ req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau()) |
|
144 |
+ rv$errors.gsva |
|
145 |
+ }) |
|
146 |
+ |
|
147 |
+ # SESSION INFO |
|
148 |
+ output$sessionInfo <- renderPrint({ |
|
149 |
+ sessionInfo() |
|
150 |
+ }) |
|
151 |
+ |
|
152 |
+ |
|
153 |
+ ##################### UI SETUPS ##################### |
|
154 |
+ |
|
155 |
+ ## ENABLING 'RUN' BTN |
|
156 |
+ observe({ |
|
157 |
+ if(!is.null(matrix()) && !is.null(genesets())){ |
|
158 |
+ enable("button") |
|
159 |
+ } else { |
|
160 |
+ disable("button") |
|
161 |
+ } |
|
162 |
+ }) |
|
163 |
+ |
|
164 |
+ ## HIDE 'GeneSets' PANEL WHILE THERE IS NO GSVA OBJECT |
|
165 |
+ observe({ |
|
166 |
+ if(is.null(rv$gs)) { |
|
167 |
+ hideTab(inputId="Panels", target="GeneSets") |
|
168 |
+ } else { |
|
169 |
+ showTab(inputId="Panels", target="GeneSets") |
|
170 |
+ } |
|
171 |
+ }) |
|
172 |
+ |
|
173 |
+ # DNLD BTN |
|
152 | 174 |
downloadServer("download", reactive(rv$gs)) |
153 | 175 |
|
154 | 176 |
# CLOSE BTN |
... | ... |
@@ -183,10 +205,6 @@ function(input, output, session) { |
183 | 205 |
any given Gene Set in this Sample, click on any point in this plot and a |
184 | 206 |
second plot will appear bellow it", "<br/>", sep="<br/>")) |
185 | 207 |
}) |
186 |
- |
|
187 |
- # SESSION INFO |
|
188 |
- output$sessionInfo <- renderPrint({ |
|
189 |
- sessionInfo() |
|
190 |
- }) |
|
208 |
+ |
|
191 | 209 |
|
192 | 210 |
} |
... | ... |
@@ -30,26 +30,46 @@ function(input, output, session) { |
30 | 30 |
|
31 | 31 |
# ARGUMENTS |
32 | 32 |
argInp <- argumentsDataServer("argumentsInput") |
33 |
+ |
|
33 | 34 |
|
34 | 35 |
#### GSVA RESULTS #### |
35 | 36 |
|
37 |
+ ## REACTIVE VALUES |
|
36 | 38 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
37 |
- errors.gsva = NULL) |
|
39 |
+ p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL) |
|
38 | 40 |
gsva.cancel <- reactiveVal(FALSE) |
39 | 41 |
|
42 |
+ ## GSVA RESULT |
|
40 | 43 |
observeEvent( input$button, { |
44 |
+ |
|
45 |
+ ## This js is in order to reset the event_data from the plotlys, |
|
46 |
+ ## so every time the .user hits the 'run' button, plotlys get back to null |
|
41 | 47 |
runjs("Shiny.setInputValue('plotly_click-click1', null);") |
42 | 48 |
runjs("Shiny.setInputValue('plotly_click-click2', null);") |
49 |
+ |
|
50 |
+ ## here we reset all the reactiveValues to NULL |
|
43 | 51 |
rv$gs <- NULL |
44 | 52 |
rv$dat.t <- NULL |
45 | 53 |
rv$p <- NULL |
46 | 54 |
rv$p2 <- NULL |
47 | 55 |
rv$p3 <- NULL |
48 |
- rv$errors.gsva = NULL |
|
56 |
+ rv$sample.c <- NULL |
|
57 |
+ rv$errors.gsva <- NULL |
|
58 |
+ |
|
59 |
+ ## this is a flag for the future. Futures cannot be canceled or |
|
60 |
+ ## terminated in a strict way, so when they get interrupted they |
|
61 |
+ ## throw an error that is not related to gsva(). When future is |
|
62 |
+ ## interrupted, the flag goes TRUE in order to make the errors |
|
63 |
+ ## message print NULL |
|
49 | 64 |
gsva.cancel(FALSE) |
65 |
+ |
|
50 | 66 |
modalGSVAUI("modal.text") |
51 |
- # future() cannot take reactive values, so we must isolate() them |
|
67 |
+ |
|
68 |
+ ## future() cannot take reactive values, so we must isolate() them |
|
52 | 69 |
future({ |
70 |
+ ## sink() will redirect all console cats and prints to a |
|
71 |
+ ## text file that the main session will be reading in order |
|
72 |
+ ## to print the progress bar from bplaply() |
|
53 | 73 |
sink(rout) |
54 | 74 |
result <- gsva(isolate(matrix()), |
55 | 75 |
isolate(genesets()), |
... | ... |
@@ -64,20 +84,35 @@ function(input, output, session) { |
64 | 84 |
ssgsea.norm=isolate(argInp$ssgseaNorm()), |
65 | 85 |
verbose=TRUE) |
66 | 86 |
sink() |
87 |
+ ## when gsva() ends, we reset the console text file to empty |
|
67 | 88 |
write("", file=rout) |
68 | 89 |
return(result) |
69 | 90 |
}, seed = TRUE) %...>% |
70 | 91 |
(function(result){ |
92 |
+ ## the future's result will be the gsva() result, and we save it |
|
93 |
+ ## and transform it in reactiveValues(). In order to make the future |
|
94 |
+ ## not block the app at an inner-session level, we save the results in |
|
95 |
+ ## reactiveValues() and then at the end of the observeEvent() we return NULL |
|
96 |
+ ## in order to make the plots. |
|
97 |
+ ## https://github.com/rstudio/promises/issues/23#issuecomment-386687705 |
|
71 | 98 |
rv$gs <- result |
72 | 99 |
rv$dat.t <- melt(as.data.table(rv$gs, keep.rownames = "gene.sets"), |
73 | 100 |
variable.name = "Sample", id.vars="gene.sets") |
74 | 101 |
rv$n <- length(levels(rv$dat.t$Sample)) |
75 | 102 |
rv$dd.col <- hcl(h = seq(15, 375, length=rv$n), l = 65, c = 100)[1:rv$n] |
76 | 103 |
names(rv$dd.col) <- levels(rv$dat.t$Sample) |
104 |
+ |
|
105 |
+ ## finally, we leave the console.text file empty again and |
|
106 |
+ ## remove the modal |
|
77 | 107 |
write("", file=rout) |
78 | 108 |
removeModal() |
79 | 109 |
}) %...!% |
80 | 110 |
(function(error){ |
111 |
+ ## there can be two ways to get an error here: |
|
112 |
+ ## 1. gsva() fails, which is an ok error and should be returnet to user |
|
113 |
+ ## 2. User interrupts the future, which shouldn't be printed, that's |
|
114 |
+ ## why I use a flag to identify if error comes from pressing "Cancel" btn |
|
115 |
+ ## on the modal |
|
81 | 116 |
removeModal() |
82 | 117 |
write("", file=rout) |
83 | 118 |
if(gsva.cancel()){ |
... | ... |
@@ -111,7 +111,6 @@ function(input, output, session) { |
111 | 111 |
ind <- event_data("plotly_click", source = "click2") |
112 | 112 |
ind <- ind$pointNumber+1 |
113 | 113 |
}) |
114 |
- # plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
115 | 114 |
plot3_Server("plot3", eventData2, rv, matrix, genesets) |
116 | 115 |
|
117 | 116 |
# DWN BTN |
... | ... |
@@ -34,18 +34,18 @@ function(input, output, session) { |
34 | 34 |
#### GSVA RESULTS #### |
35 | 35 |
|
36 | 36 |
rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, |
37 |
- errors.gsva = NULL, matrix=NULL, genesets=NULL) |
|
37 |
+ errors.gsva = NULL) |
|
38 | 38 |
gsva.cancel <- reactiveVal(FALSE) |
39 | 39 |
|
40 | 40 |
observeEvent( input$button, { |
41 |
+ runjs("Shiny.setInputValue('plotly_click-click1', null);") |
|
42 |
+ runjs("Shiny.setInputValue('plotly_click-click2', null);") |
|
41 | 43 |
rv$gs <- NULL |
42 | 44 |
rv$dat.t <- NULL |
43 | 45 |
rv$p <- NULL |
44 | 46 |
rv$p2 <- NULL |
45 | 47 |
rv$p3 <- NULL |
46 | 48 |
rv$errors.gsva = NULL |
47 |
- rv$matrix <- isolate(matrix()) |
|
48 |
- rv$genesets <- isolate(genesets()) |
|
49 | 49 |
gsva.cancel(FALSE) |
50 | 50 |
modalGSVAUI("modal.text") |
51 | 51 |
# future() cannot take reactive values, so we must isolate() them |
... | ... |
@@ -96,7 +96,6 @@ function(input, output, session) { |
96 | 96 |
# PLOT1 RENDER |
97 | 97 |
plot1_Server("plot1", rv) |
98 | 98 |
|
99 |
- |
|
100 | 99 |
# PLOT2 RENDER |
101 | 100 |
eventData1 <- reactive({ |
102 | 101 |
req(rv$dat.t) |
... | ... |
@@ -112,7 +111,8 @@ function(input, output, session) { |
112 | 111 |
ind <- event_data("plotly_click", source = "click2") |
113 | 112 |
ind <- ind$pointNumber+1 |
114 | 113 |
}) |
115 |
- plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
114 |
+ # plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
|
115 |
+ plot3_Server("plot3", eventData2, rv, matrix, genesets) |
|
116 | 116 |
|
117 | 117 |
# DWN BTN |
118 | 118 |
downloadServer("download", reactive(rv$gs)) |
... | ... |
@@ -89,7 +89,7 @@ function(input, output, session) { |
89 | 89 |
}) |
90 | 90 |
|
91 | 91 |
# PRINTING CONSOLE.TEXT |
92 |
- modalGSVAServer("modal.text", console.text, gsva.cancel) |
|
92 |
+ modalGSVAServer("modal.text", console.text, gsva.cancel, rout) |
|
93 | 93 |
|
94 | 94 |
# PLOT1 RENDER |
95 | 95 |
plot1_Server("plot1", rv) |
... | ... |
@@ -113,7 +113,7 @@ function(input, output, session) { |
113 | 113 |
plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
114 | 114 |
|
115 | 115 |
# DWN BTN |
116 |
- downloadServer("download", rv$gs) |
|
116 |
+ downloadServer("download", reactive(rv$gs)) |
|
117 | 117 |
|
118 | 118 |
# CLOSE BTN |
119 | 119 |
closeBtnServer("close", reactive(rv$gs)) |
... | ... |
@@ -111,14 +111,12 @@ function(input, output, session) { |
111 | 111 |
ind <- ind$pointNumber+1 |
112 | 112 |
}) |
113 | 113 |
plot3_Server("plot3", eventData2, rv, rv$matrix, rv$genesets) |
114 |
- |
|
115 |
- # SAVE & CLOSE BTN |
|
116 |
- observeEvent(input$closeSave, { |
|
117 |
- stopApp(rv$gs) #Stops the app and returns the rv$gs object to the R session |
|
118 |
- }) |
|
119 | 114 |
|