Browse code

rebased

pablo-rodr-bio2 authored on 22/04/2021 22:05:25
Showing3 changed files

... ...
@@ -1,5 +1,9 @@
1 1
 Package: GSVA
2
+<<<<<<< HEAD
2 3
 Version: 1.39.24
4
+=======
5
+Version: 1.39.23
6
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
3 7
 Title: Gene Set Variation Analysis for microarray and RNA-seq data
4 8
 Authors@R: c(person("Justin", "Guinney", role=c("aut", "cre"), email="justin.guinney@sagebase.org"),
5 9
              person("Robert", "Castelo", role="aut", email="robert.castelo@upf.edu"),
... ...
@@ -11,8 +15,13 @@ Imports: methods, stats, utils, graphics, S4Vectors, IRanges,
11 15
          BiocParallel, SingleCellExperiment, sparseMatrixStats, DelayedArray,
12 16
          DelayedMatrixStats, HDF5Array, BiocSingular
13 17
 Suggests: BiocGenerics, RUnit, BiocStyle, knitr, rmarkdown, limma, RColorBrewer,
18
+<<<<<<< HEAD
14 19
           org.Hs.eg.db, genefilter, edgeR, GSVAdata, shiny, shinythemes, ggplot2,
15 20
           data.table, plotly, future, promises, shinybusy, org.Hs.eg.db
21
+=======
22
+          genefilter, edgeR, GSVAdata, shiny, shinythemes, ggplot2, data.table,
23
+          plotly, shinyjs, future, promises, shinybusy, org.Hs.eg.db
24
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
16 25
 Description: Gene Set Variation Analysis (GSVA) is a non-parametric, unsupervised method for estimating variation of gene set enrichment through the samples of a expression data set. GSVA performs a change in coordinate systems, transforming the data from a gene by sample matrix to a gene-set by sample matrix, thereby allowing the evaluation of pathway enrichment for each sample. This new matrix of GSVA enrichment scores facilitates applying standard analytical methods like functional enrichment, survival analysis, clustering, CNV-pathway analysis or cross-tissue pathway analysis, in a pathway-centric manner.
17 26
 License: GPL (>= 2)
18 27
 VignetteBuilder: knitr
... ...
@@ -4,6 +4,7 @@ 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
7 8
   
8 9
   # ERRORS MESSAGES
9 10
   output$errorsGsva <- renderText({
... ...
@@ -136,9 +137,118 @@ function(input, output, session) {
136 137
     req(rv$dat.t)
137 138
     ind <- event_data("plotly_click", source = "click1")
138 139
     ind <- ind$curveNumber+1
140
+=======
141
+  
142
+  
143
+  ##################### INPUTS #####################
144
+  
145
+  # DATA MATRIX
146
+  matrix <- matrixServer("matrix1")
147
+  
148
+  # GENES
149
+  genesets <- geneSetsServer("genes1")
150
+  
151
+  # ARGUMENTS
152
+  argInp <- argumentsDataServer("argumentsInput")
153
+  
154
+  
155
+
156
+  ##################### GSVA RESULTS ################
157
+  
158
+  ## REACTIVE VALUES
159
+  rv <- reactiveValues(gs=NULL, dat.t=NULL, n=NULL, dd.col=NULL, p=NULL, 
160
+                       p2=NULL, p3=NULL, errors.gsva = NULL, sample.c = NULL)
161
+  gsva.cancel <- reactiveVal(FALSE)
162
+  
163
+  ## GSVA RESULT
164
+  observeEvent( input$button, {
165
+    
166
+    ## This js is in order to reset the event_data from the plotlys,
167
+    ## so every time the .user hits the 'run' button, plotlys get back to null
168
+    runjs("Shiny.setInputValue('plotly_click-click1', null);")
169
+    runjs("Shiny.setInputValue('plotly_click-click2', null);")
170
+    
171
+    ## here we reset all the reactiveValues to NULL
172
+    rv$gs <- NULL
173
+    rv$dat.t <- NULL
174
+    rv$p <- NULL
175
+    rv$p2 <- NULL
176
+    rv$p3 <- NULL
177
+    rv$sample.c <- NULL
178
+    rv$errors.gsva <- NULL
179
+    
180
+    ## this is a flag for the future. Futures cannot be canceled or
181
+    ## terminated in a strict way, so when they get interrupted they
182
+    ## throw an error that is not related to gsva(). When future is 
183
+    ## interrupted, the flag goes TRUE in order to make the errors
184
+    ## message print NULL
185
+    gsva.cancel(FALSE)
186
+    
187
+    modalGSVAUI("modal.text")
188
+    
189
+    ## future() cannot take reactive values, so we must isolate() them
190
+    future({
191
+      ## sink() will redirect all console cats and prints to a
192
+      ## text file that the main session will be reading in order
193
+      ## to print the progress bar from bplaply()
194
+      sink(rout)
195
+      result <- gsva(isolate(matrix()),
196
+                     isolate(genesets()), 
197
+                     method=isolate(argInp$method()),
198
+                     kcdf=isolate(argInp$kcdf()),
199
+                     abs.ranking=isolate(argInp$absRanking()),
200
+                     min.sz= isolate(argInp$varMinsz()),
201
+                     max.sz=isolate(argInp$varMaxsz()),
202
+                     parallel.sz=1L, ## by now, disable parallelism
203
+                     mx.diff=isolate(argInp$mxDiff()),
204
+                     tau=isolate(argInp$selectedTau()),
205
+                     ssgsea.norm=isolate(argInp$ssgseaNorm()),
206
+                     verbose=TRUE)
207
+      sink()
208
+      ## when gsva() ends, we reset the console text file to empty
209
+      write("", file=rout)
210
+      return(result)
211
+    }, seed = TRUE) %...>%
212
+      (function(result){
213
+        ## the future's result will be the gsva() result, and we save it
214
+        ## and transform it in reactiveValues(). In order to make the future
215
+        ## not block the app at an inner-session level, we save the results in
216
+        ## reactiveValues() and then at the end of the observeEvent() we return NULL
217
+        ## in order to make the plots.
218
+        ## https://github.com/rstudio/promises/issues/23#issuecomment-386687705
219
+        rv$gs <- result
220
+        rv$dat.t <- melt(as.data.table(rv$gs, keep.rownames = "gene.sets"),
221
+                         variable.name = "Sample", id.vars="gene.sets")
222
+        rv$n <- length(levels(rv$dat.t$Sample))
223
+        rv$dd.col <- hcl(h = seq(15, 375, length=rv$n), l = 65, c = 100)[1:rv$n]
224
+        names(rv$dd.col)  <- levels(rv$dat.t$Sample)
225
+        
226
+        ## finally, we leave the console.text file empty again and
227
+        ## remove the modal
228
+        write("", file=rout)
229
+        removeModal()
230
+      }) %...!%
231
+      (function(error){
232
+        ## there can be two ways to get an error here: 
233
+        ## 1. gsva() fails, which is an ok error and should be returnet to user
234
+        ## 2. User interrupts the future, which shouldn't be printed, that's
235
+        ## why I use a flag to identify if error comes from pressing "Cancel" btn
236
+        ## on the modal
237
+        removeModal()
238
+        write("", file=rout)
239
+        if(gsva.cancel()){
240
+          rv$errors.gsva <- NULL
241
+        } else {
242
+          rv$errors.gsva <- as.character(error)
243
+        }
244
+        
245
+      })
246
+    NULL
247
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
139 248
   })
140 249
   plot2_Server("plot2", eventData1, rv)
141 250
   
251
+<<<<<<< HEAD
142 252
   
143 253
   # PLOT3 RENDER
144 254
   eventData2 <- reactive({
... ...
@@ -169,24 +279,120 @@ function(input, output, session) {
169 279
     resultInformation <- data.frame("Nr of gene sets" = nrow(rv$gs),
170 280
                                     "Nr of samples" = ncol(rv$gs))
171 281
     resultInformation
282
+=======
283
+  # PRINTING CONSOLE.TEXT
284
+  modalGSVAServer("modal.text", console.text, gsva.cancel, rout)
285
+  
286
+  
287
+  
288
+  ##################### OUTPUTS ##################
289
+  
290
+  # PLOT1 RENDER
291
+  plot1_Server("plot1", rv)
292
+
293
+  # PLOT2 RENDER
294
+  eventData1 <- reactive({
295
+    req(rv$dat.t)
296
+    ind <- event_data("plotly_click", source = "click1")
297
+    ind <- ind$curveNumber+1
298
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
172 299
   })
300
+  plot2_Server("plot2", eventData1, rv)
173 301
   
302
+<<<<<<< HEAD
174 303
   # TEXT2
175 304
   output$text2 <- renderUI({
176 305
     title1 <- rv$sample.c
177 306
     h2(tags$b(title1), align ="center")
307
+=======
308
+  # PLOT3 RENDER
309
+  eventData2 <- reactive({
310
+    req(rv$p2)
311
+    ind <- event_data("plotly_click", source = "click2")
312
+    ind <- ind$pointNumber+1
313
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
178 314
   })
315
+  plot3_Server("plot3", eventData2, rv, matrix, genesets)
179 316
   
317
+<<<<<<< HEAD
180 318
   # TEXT3
181 319
   output$text3 <- renderUI({
182 320
     HTML(paste("<br/>", "\t To see the Kernel Density Estimation of genes of 
183 321
     any given Gene Set in this Sample,  click on any point in this plot and a
184 322
     second plot will appear bellow it", "<br/>", sep="<br/>"))
323
+=======
324
+  # ERRORS MESSAGES
325
+  output$errorsGsva <- renderText({
326
+    req(argInp$varMinsz(), argInp$varMaxsz(), argInp$selectedTau())
327
+    rv$errors.gsva
328
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
185 329
   })
186 330
   
187 331
   # SESSION INFO
188 332
   output$sessionInfo <- renderPrint({
189 333
     sessionInfo()
190 334
   })
335
+<<<<<<< HEAD
336
+
337
+=======
338
+  
339
+  
340
+  ##################### UI SETUPS #####################
341
+  
342
+  ## ENABLING 'RUN' BTN
343
+  observe({
344
+    if(!is.null(matrix()) && !is.null(genesets())){
345
+      enable("button")
346
+    } else {
347
+      disable("button")
348
+    }
349
+  })
350
+  
351
+  ## HIDE 'GeneSets' PANEL WHILE THERE IS NO GSVA OBJECT
352
+  observe({
353
+    if(is.null(rv$gs)) {
354
+      hideTab(inputId="Panels", target="GeneSets")
355
+    } else {
356
+      showTab(inputId="Panels", target="GeneSets")
357
+    }
358
+  })
359
+  
360
+  # DNLD BTN
361
+  downloadServer("download", reactive(rv$gs))
362
+  
363
+  # CLOSE BTN
364
+  closeBtnServer("close", reactive(rv$gs))
365
+
366
+  
367
+  # TEXT1
368
+  output$text1 <- renderUI({
369
+    req(rv$gs)
370
+    HTML(paste("<br/>", "\t To see the Empirical Cumulative Distribution Function 
371
+    of a Sample, click on its line in this plot and go
372
+      to the 'Gene.Set' Panel", "<br/>", sep="<br/>"))
373
+  })
374
+  
375
+  # TABLE
376
+  output$result <- renderTable({
377
+    req(rv$gs)
378
+    resultInformation <- data.frame("Nr of gene sets" = nrow(rv$gs),
379
+                                    "Nr of samples" = ncol(rv$gs))
380
+    resultInformation
381
+  })
382
+  
383
+  # TEXT2
384
+  output$text2 <- renderUI({
385
+    title1 <- rv$sample.c
386
+    h2(tags$b(title1), align ="center")
387
+  })
388
+  
389
+  # TEXT3
390
+  output$text3 <- renderUI({
391
+    HTML(paste("<br/>", "\t To see the Kernel Density Estimation of genes of 
392
+    any given Gene Set in this Sample,  click on any point in this plot and a
393
+    second plot will appear bellow it", "<br/>", sep="<br/>"))
394
+  })
395
+
191 396
 
397
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
192 398
 }
... ...
@@ -33,7 +33,11 @@ fluidPage(
33 33
       ))
34 34
     ),
35 35
     mainPanel(width=6,
36
+<<<<<<< HEAD
36 37
               tabsetPanel(type="tabs",
38
+=======
39
+              tabsetPanel(id = "Panels", type="tabs",
40
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
37 41
                           tabPanel("Samples",
38 42
                                    textOutput("errorsGsva"),
39 43
                                    htmlOutput("text1"),
... ...
@@ -41,7 +45,11 @@ fluidPage(
41 45
                                    tableOutput("result"),
42 46
                                    downloadUI("download"),
43 47
                                    closeBtnUI("close")),
48
+<<<<<<< HEAD
44 49
                           tabPanel("Gene Sets",
50
+=======
51
+                          tabPanel("GeneSets",
52
+>>>>>>> 8dfc5494f0608cb5bbe03ef57fbf5f8532fe0b7d
45 53
                                    uiOutput("text2"),
46 54
                                    htmlOutput("text3"),
47 55
                                    plot2_UI("plot2"),