Browse code

Bugfix on the igsva() function.

[rcastelo] authored on 27/04/2018 22:14:15
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,3 +0,0 @@
1
-igsva <- function() {
2
-  runApp("GSVA/R/app")
3
-}
Browse code

Deprecated functions become defunct.

Robert Castelo authored on 16/03/2018 07:36:20
Showing 1 changed files
... ...
@@ -1,13 +1,3 @@
1
-#'
2
-#' @importFrom shiny HTML actionButton animationOptions checkboxGroupInput column div downloadHandler downloadLink eventReactive fileInput fluidPage fluidRow h2 h3 h4 headerPanel htmlOutput mainPanel need numericInput NS observe observeEvent p plotOutput reactiveValues renderPlot renderUI selectInput shinyApp sliderInput stopApp tabPanel tabsetPanel textOutput uiOutput updateSelectInput validate wellPanel withProgress conditionalPanel reactive outputOptions tableOutput tags radioButtons downloadButton
3
-#' @importFrom shinythemes shinytheme
4
-#' @importFrom utils head
5
-#' @importFrom geneplotter multidensity
6
-#' @importFrom stats median
7
-#' @importFrom graphics plot
8
-#' @export
9
-#'
10
-
11 1
 igsva <- function() {
12 2
   runApp("GSVA/R/app")
13
-}
14 3
\ No newline at end of file
4
+}
Browse code

Two file app

JoanFernandez authored on 06/02/2018 16:30:41
Showing 1 changed files
... ...
@@ -8,353 +8,6 @@
8 8
 #' @export
9 9
 #'
10 10
 
11
-selectDataInput <- function(id) {
12
-  # Create a namespace function using the provided id
13
-  ns <- NS(id)
14
-  
15
-  #UI declaration
16
-  column(
17
-    3,
18
-    h3("Select data source:"),
19
-    #Select data source
20
-    wellPanel(fluidRow(
21
-      column(
22
-        12,
23
-        #Select matrix
24
-        radioButtons("matrixSourceType", "Select matrix:",
25
-                     c("From file" = "fileMatrix",
26
-                       "From workspace" = "varMatrix"))
27
-        ,
28
-        #If the selected data source is a file
29
-        conditionalPanel(
30
-          condition = "input.matrixSourceType == 'fileMatrix'",
31
-          fileInput("matrixFile", "Choose matrix file:",
32
-                    accept = c(
33
-                      "text/csv",
34
-                      "text/comma-separated-values,text/plain",
35
-                      ".csv",".ods",".xls",".xlt")
36
-          )
37
-        ),
38
-        #If the selected data source is a workspace object
39
-        conditionalPanel(
40
-          condition = "input.matrixSourceType == 'varMatrix'",
41
-          selectInput("matrixVar", "Choose matrix var:",
42
-                      ls(envir=.GlobalEnv))
43
-        ),
44
-        fluidRow(column(12,
45
-                        HTML("<br>"))),
46
-        #Select geneset
47
-        radioButtons("genesetSourceType", "Select GeneSet:",
48
-                     c("From file" = "fileGeneset",
49
-                       "From workspace" = "varGeneset"))
50
-        ,
51
-        #If the selected data source is a file
52
-        conditionalPanel(
53
-          condition = "input.genesetSourceType == 'fileGeneset'",
54
-          fileInput("genesetFile", "Choose GeneSet file:",
55
-                    accept = ".gmt")
56
-        ),
57
-        #If the selected data source is a workspace object
58
-        conditionalPanel(
59
-          condition = "input.genesetSourceType == 'varGeneset'",
60
-          selectInput("genesetVar", "Choose GeneSet var:",
61
-                      ls(envir=.GlobalEnv))
62
-        ),
63
-        HTML("<br>"),
64
-        radioButtons("arg", "Control arguments:",
65
-                     c("No" = "no",
66
-                       "Yes" = "yes"))
67
-      )
68
-    ),
69
-    actionButton("button", "Run"))
70
-  )
71
-}
72
-
73
-mainDataInput <- function(id) {
74
-  # Create a namespace function using the provided id
75
-  ns <- NS(id)
76
-  
77
-  #UI Definition
78
-  mainPanel(width = 6,
79
-            h2("Generated GSVA data:"),
80
-            textOutput("information"),
81
-            plotOutput("plot"),
82
-            tableOutput("result"),
83
-            uiOutput("download"))
84
-}
85
-
86
-argumentsDataInput <- function(id) {
87
-  # Create a namespace function using the provided id
88
-  ns <- NS(id)
89
-  
90
-  #UI Definition
91
-  column(
92
-    3,
93
-    conditionalPanel(
94
-      condition = "input.arg == 'yes'",
95
-      h3("Select arguments:"),
96
-      wellPanel(fluidRow(
97
-        column(
98
-          12,
99
-          selectInput("method", "Choose method:",
100
-                      c("gsva","ssgsea","zscore","plage")),
101
-          selectInput("kcdf", "Choose kcdf:",
102
-                      c("Gaussian","Poisson","none")),
103
-          radioButtons("absRanking", "abs.ranking:",
104
-                       c("False" = FALSE,
105
-                         "True" = TRUE)),
106
-          numericInput("minSz","min.sz:",value = 1),
107
-          numericInput("maxSz","max.sz (Write 0 for infinite):",value = 0),
108
-          numericInput("parallelSz","parallel.sz:",value = 0),
109
-          selectInput("parallelType", "parallel.type:",
110
-                      c("SOCK","MPI","NWS")),
111
-          radioButtons("mxDiff", "mx.diff:",
112
-                       c("True" = TRUE,
113
-                         "False" = FALSE)),
114
-          conditionalPanel(
115
-            condition = "input.method == 'gsva'",
116
-            numericInput("tau1","tau:",value = 1)
117
-          ),
118
-          conditionalPanel(
119
-            condition = "input.method == 'ssgsea'",
120
-            numericInput("tau2","tau:",value = 0.25)
121
-          ),
122
-          conditionalPanel(
123
-            condition = "input.method == 'zscore' || input.method == 'plage'"
124
-          ),
125
-          radioButtons("ssgseaNorm", "ssgsea.norm:",
126
-                       c("True" = TRUE,
127
-                         "False" = FALSE)),
128
-          radioButtons("verbose", "verbose:",
129
-                       c("True" = TRUE,
130
-                         "False" = FALSE))
131
-        )))
132
-    )
133
-  )
134
-}
135
-
136
-gsva_validation <- function(input, output, session) {
137
-  success <- FALSE #Variable to control if the GSVA variables are assigned correctly
138
-  if(input$matrixSourceType == "fileMatrix")
139
-  {
140
-    if (is.null(input$matrixFile))
141
-    {
142
-      paste("No matrix file selected!")
143
-      success <- FALSE
144
-    }
145
-    else
146
-    {
147
-      #Matrix file selected
148
-      if(input$genesetSourceType == "fileGeneset")
149
-      {
150
-        if (is.null(input$genesetFile))
151
-        {
152
-          paste("No geneSet file selected!")
153
-          success <- FALSE
154
-        }
155
-        else
156
-        {
157
-          #User selects matrix file and geneSet file
158
-          inFile <- input$matrixFile
159
-          newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix
160
-          rownames(newY) <- newY[,1] #Taking the first column as rownames
161
-          newY <- newY[,-1] #Deleting the first column
162
-          inGenesetFile <- input$genesetFile
163
-          genes <- getGmt(inGenesetFile$datapath)
164
-          if(input$maxSz == 0) {
165
-            varMaxsz <- Inf
166
-          }else {
167
-            varMaxsz <- input$maxSz
168
-          }
169
-          success <- TRUE
170
-        }
171
-      }
172
-      else
173
-      {
174
-        #User selects matrix file and geneset var
175
-        inFile <- input$matrixFile
176
-        newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix
177
-        rownames(newY) <- newY[,1] #Taking the first column as rownames
178
-        newY <- newY[,-1] #Deleting the first column
179
-        assign("genes",get(input$genesetVar))
180
-        if(input$maxSz == 0) {
181
-          varMaxsz <- Inf
182
-        }else {
183
-          varMaxsz <- input$maxSz
184
-        }
185
-        success <- TRUE
186
-      }
187
-    }
188
-  }
189
-  else
190
-  {
191
-    #User selects matrix varand geneset file
192
-    if(input$genesetSourceType == "fileGeneset")
193
-    {
194
-      if (is.null(input$genesetFile))
195
-      {
196
-        paste("No geneSet file selected!")
197
-        success <- FALSE
198
-      }
199
-      else
200
-      {
201
-        assign("newY",get(input$matrixVar))
202
-        inGenesetFile <- input$genesetFile
203
-        genes <- getGmt(inGenesetFile$datapath)
204
-        if(input$maxSz == 0) {
205
-          varMaxsz <- Inf
206
-        }else {
207
-          varMaxsz <- input$maxSz
208
-        }
209
-        success <- TRUE
210
-      }
211
-    }
212
-    else
213
-    {
214
-      #User selects matrix var selected and geneset var
215
-      assign("newY",get(input$matrixVar))
216
-      assign("genes",get(input$genesetVar))
217
-      if(input$maxSz == 0) {
218
-        varMaxsz <- Inf
219
-      }else {
220
-        varMaxsz <- input$maxSz
221
-      }
222
-      success <- TRUE
223
-    }
224
-  }
225
-  if(success==TRUE)
226
-  {
227
-    gsva_generation(input, output, session, newY, genes,varMaxsz)
228
-    gsva_information(input,output,session)
229
-  }
230
-}
231
-
232
-gsva_generation <- function(input, output, session, newY, genes,varMaxsz) {
233
-  x <- input$method
234
-  selectedTau <- NULL
235
-  switch (x,
236
-          "gsva" = {
237
-            selectedTau <- input$tau1
238
-          },
239
-          "ssgsea" = {
240
-            selectedTau <- input$tau2
241
-          },
242
-          "zscore" = {
243
-            selectedTau <- NULL
244
-          },
245
-          "plage" = {
246
-            selectedTau <- NULL
247
-          }
248
-  )
249
-  #GSVA Generation
250
-  withProgress(message = 'Runing GSVA', value = 0, {
251
-    incProgress(1, detail = "This may take a while...")
252
-    generated_gsva <<- gsva(newY, genes, method=input$method, kcdf=input$kcdf, abs.ranking=as.logical(input$absRanking),
253
-                            min.sz=input$minSz, max.sz=varMaxsz, parallel.sz=input$parallelSz, parallel.type=input$parallelType,
254
-                            mx.diff=as.logical(input$mxDiff), tau=selectedTau, ssgsea.norm=as.logical(input$ssgseaNorm),
255
-                            verbose=as.logical(input$verbose))
256
-  })
257
-}
258
-
259
-gsva_information <- function(input, output, session) {
260
-  if(class(generated_gsva) == "matrix")
261
-  {
262
-    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva),nrow(generated_gsva)), nrow = 1, ncol = 4)
263
-    colnames(resultInformation) <- c("Matrix used","GeneSet used", "Col num", "Row num")
264
-    output$result <- renderTable(resultInformation)
265
-    output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
266
-    tagList(
267
-      downloadButton('downloadData', 'Download'),
268
-      actionButton('closeSave','Save & Close')
269
-    )
270
-  }
271
-  else
272
-  {
273
-
274
-    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva),nrow(generated_gsva)), nrow = 1, ncol = 4)
275
-    colnames(resultInformation) <- c("Matrix used","GeneSet used", "Col num", "Row num")
276
-    output$result <- renderTable(resultInformation)
277
-    if(class(generated_gsva) == "ExpressionSet") #If the generated gsva is an ExpressionSet
278
-    {
279
-      expressionSetObs <- exprs(generated_gsva)
280
-      output$plot <- renderPlot(multidensity(as.list(as.data.frame(expressionSetObs)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2)) 
281
-    }
282
-    else
283
-    {
284
-      output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
285
-    }
286
-    tagList(
287
-      downloadButton('downloadData', 'Download'),
288
-      actionButton('closeSave','Save & Close')
289
-    )
290
-  }
291
-}
292
-
293
-download_handler <- function(input, output, session) {
294
-  #Controls the Download button
295
-  output$downloadData <- downloadHandler(
296
-    filename = function() {
297
-      paste("gsva_es-", Sys.Date(), ".csv", sep="")
298
-    },
299
-    content = function(file) {
300
-      if(class(generated_gsva) == "matrix") #If the whole object is a matrix
301
-      {
302
-        dataFrameObs <- as.data.frame(generated_gsva)
303
-        write.csv(dataFrameObs, file)
304
-      }
305
-      else
306
-      {
307
-        if(class(generated_gsva) == "ExpressionSet") #If the generated gsva result value is an ExpressionSet
308
-        {
309
-          expressionSetObs <- exprs(generated_gsva)
310
-          dataFrameObs <- as.data.frame(expressionSetObs)
311
-          write.csv(dataFrameObs, file)
312
-        }
313
-        else
314
-        {
315
-          dataFrameObs <- as.data.frame(generated_gsva)
316
-          write.csv(dataFrameObs, file)
317
-        } 
318
-      }
319
-    }
320
-  )
321
-}
322
-
323 11
 igsva <- function() {
324
-  app <- list(ui = NULL, server = NULL)
325
-  app$ui <- fluidPage(theme = shinytheme("simplex"),
326
-                      fluidRow(
327
-                        selectDataInput("dataInput"),
328
-                        mainDataInput("mainInput")
329
-                        ,
330
-                        fluidRow(
331
-                          argumentsDataInput("argumentsInput")
332
-                        )
333
-                      )
334
-  )
335
-  
336
-  app$server <- function(input, output, session) {
337
-    v <- reactiveValues(action = FALSE)
338
-    
339
-    observeEvent(input$button, {
340
-      v$action <- input$button
341
-    })
342
-    
343
-    output$download <- renderUI({
344
-      if(v$action)
345
-      {
346
-        #Isolates the Run event, that allows the program to run the generation only if the user clicks the button.
347
-        isolate({
348
-          gsva_validation(input,output,session)
349
-        })
350
-      }
351
-    })
352
-    download_handler(input,output,session)
353
-    
354
-    #Observe the Save & Close button
355
-    observeEvent(input$closeSave, {
356
-      stopApp(generated_gsva) #Stops the app and returns the generated_gsva object
357
-    })
358
-  }
359
-  runApp(app)
360
-}
12
+  runApp("GSVA/R/app")
13
+}
361 14
\ No newline at end of file
Browse code

Deprecate arguments no.bootstraps and bootstrap.percent, simplify return value to the object storing the enrichment scores and add argument return.old.value to provide backward compability for the return value during the next release.

[rcastelo] authored on 06/09/2017 15:00:02
Showing 1 changed files
... ...
@@ -271,17 +271,17 @@ gsva_information <- function(input, output, session) {
271 271
   else
272 272
   {
273 273
 
274
-    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva$es.obs),nrow(generated_gsva$es.obs)), nrow = 1, ncol = 4)
274
+    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva),nrow(generated_gsva)), nrow = 1, ncol = 4)
275 275
     colnames(resultInformation) <- c("Matrix used","GeneSet used", "Col num", "Row num")
276 276
     output$result <- renderTable(resultInformation)
277
-    if(class(generated_gsva$es.obs) == "ExpressionSet") #If the generated gsva is an ExpressionSet
277
+    if(class(generated_gsva) == "ExpressionSet") #If the generated gsva is an ExpressionSet
278 278
     {
279
-      expressionSetObs <- exprs(generated_gsva$es.obs)
279
+      expressionSetObs <- exprs(generated_gsva)
280 280
       output$plot <- renderPlot(multidensity(as.list(as.data.frame(expressionSetObs)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2)) 
281 281
     }
282 282
     else
283 283
     {
284
-      output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva$es.obs)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
284
+      output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
285 285
     }
286 286
     tagList(
287 287
       downloadButton('downloadData', 'Download'),
... ...
@@ -304,15 +304,15 @@ download_handler <- function(input, output, session) {
304 304
       }
305 305
       else
306 306
       {
307
-        if(class(generated_gsva$es.obs) == "ExpressionSet") #If the generated gsva es.obs is an ExpressionSet
307
+        if(class(generated_gsva) == "ExpressionSet") #If the generated gsva result value is an ExpressionSet
308 308
         {
309
-          expressionSetObs <- exprs(generated_gsva$es.obs)
309
+          expressionSetObs <- exprs(generated_gsva)
310 310
           dataFrameObs <- as.data.frame(expressionSetObs)
311 311
           write.csv(dataFrameObs, file)
312 312
         }
313 313
         else
314 314
         {
315
-          dataFrameObs <- as.data.frame(generated_gsva$es.obs)
315
+          dataFrameObs <- as.data.frame(generated_gsva)
316 316
           write.csv(dataFrameObs, file)
317 317
         } 
318 318
       }
Browse code

Arguments rnaseq and kernel deprecated and replaced by new argument kcdf.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/GSVA@131287 bc3139a8-67e5-0310-9ffc-ced21a209358

Robert Castelo authored on 17/07/2017 17:11:21
Showing 1 changed files
... ...
@@ -98,16 +98,13 @@ argumentsDataInput <- function(id) {
98 98
           12,
99 99
           selectInput("method", "Choose method:",
100 100
                       c("gsva","ssgsea","zscore","plage")),
101
-          radioButtons("rnaseq", "Rnaseq:",
102
-                       c("False" = FALSE,
103
-                         "True" = TRUE)),
101
+          selectInput("kcdf", "Choose kcdf:",
102
+                      c("Gaussian","Poisson","none")),
104 103
           radioButtons("absRanking", "abs.ranking:",
105 104
                        c("False" = FALSE,
106 105
                          "True" = TRUE)),
107 106
           numericInput("minSz","min.sz:",value = 1),
108 107
           numericInput("maxSz","max.sz (Write 0 for infinite):",value = 0),
109
-          numericInput("noBootstraps","no.bootstraps:",value = 0),
110
-          numericInput("bootstrapPercent","bootstrap.percent:",value = .632),
111 108
           numericInput("parallelSz","parallel.sz:",value = 0),
112 109
           selectInput("parallelType", "parallel.type:",
113 110
                       c("SOCK","MPI","NWS")),
... ...
@@ -125,9 +122,6 @@ argumentsDataInput <- function(id) {
125 122
           conditionalPanel(
126 123
             condition = "input.method == 'zscore' || input.method == 'plage'"
127 124
           ),
128
-          radioButtons("kernel", "kernel:",
129
-                       c("True" = TRUE,
130
-                         "False" = FALSE)),
131 125
           radioButtons("ssgseaNorm", "ssgsea.norm:",
132 126
                        c("True" = TRUE,
133 127
                          "False" = FALSE)),
... ...
@@ -255,10 +249,10 @@ gsva_generation <- function(input, output, session, newY, genes,varMaxsz) {
255 249
   #GSVA Generation
256 250
   withProgress(message = 'Runing GSVA', value = 0, {
257 251
     incProgress(1, detail = "This may take a while...")
258
-    generated_gsva <<- gsva(newY, genes, method = input$method, rnaseq = as.logical(input$rnaseq), abs.ranking = as.logical(input$absRanking),
259
-                            min.sz = input$minSz, max.sz = varMaxsz, no.bootstraps = input$noBootstraps, bootstrap.percent = input$bootstrapPercent, 
260
-                            parallel.sz = input$parallelSz, parallel.type = input$parallelType, mx.diff = as.logical(input$mxDiff), tau = selectedTau, kernel = as.logical(input$kernel),
261
-                            ssgsea.norm = as.logical(input$ssgseaNorm), verbose = as.logical(input$verbose)) #Result asignation
252
+    generated_gsva <<- gsva(newY, genes, method=input$method, kcdf=input$kcdf, abs.ranking=as.logical(input$absRanking),
253
+                            min.sz=input$minSz, max.sz=varMaxsz, parallel.sz=input$parallelSz, parallel.type=input$parallelType,
254
+                            mx.diff=as.logical(input$mxDiff), tau=selectedTau, ssgsea.norm=as.logical(input$ssgseaNorm),
255
+                            verbose=as.logical(input$verbose))
262 256
   })
263 257
 }
264 258
 
Browse code

Added first version of a GSVA shiny app.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/GSVA@130609 bc3139a8-67e5-0310-9ffc-ced21a209358

Robert Castelo authored on 22/06/2017 12:53:26
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,366 @@
1
+#'
2
+#' @importFrom shiny HTML actionButton animationOptions checkboxGroupInput column div downloadHandler downloadLink eventReactive fileInput fluidPage fluidRow h2 h3 h4 headerPanel htmlOutput mainPanel need numericInput NS observe observeEvent p plotOutput reactiveValues renderPlot renderUI selectInput shinyApp sliderInput stopApp tabPanel tabsetPanel textOutput uiOutput updateSelectInput validate wellPanel withProgress conditionalPanel reactive outputOptions tableOutput tags radioButtons downloadButton
3
+#' @importFrom shinythemes shinytheme
4
+#' @importFrom utils head
5
+#' @importFrom geneplotter multidensity
6
+#' @importFrom stats median
7
+#' @importFrom graphics plot
8
+#' @export
9
+#'
10
+
11
+selectDataInput <- function(id) {
12
+  # Create a namespace function using the provided id
13
+  ns <- NS(id)
14
+  
15
+  #UI declaration
16
+  column(
17
+    3,
18
+    h3("Select data source:"),
19
+    #Select data source
20
+    wellPanel(fluidRow(
21
+      column(
22
+        12,
23
+        #Select matrix
24
+        radioButtons("matrixSourceType", "Select matrix:",
25
+                     c("From file" = "fileMatrix",
26
+                       "From workspace" = "varMatrix"))
27
+        ,
28
+        #If the selected data source is a file
29
+        conditionalPanel(
30
+          condition = "input.matrixSourceType == 'fileMatrix'",
31
+          fileInput("matrixFile", "Choose matrix file:",
32
+                    accept = c(
33
+                      "text/csv",
34
+                      "text/comma-separated-values,text/plain",
35
+                      ".csv",".ods",".xls",".xlt")
36
+          )
37
+        ),
38
+        #If the selected data source is a workspace object
39
+        conditionalPanel(
40
+          condition = "input.matrixSourceType == 'varMatrix'",
41
+          selectInput("matrixVar", "Choose matrix var:",
42
+                      ls(envir=.GlobalEnv))
43
+        ),
44
+        fluidRow(column(12,
45
+                        HTML("<br>"))),
46
+        #Select geneset
47
+        radioButtons("genesetSourceType", "Select GeneSet:",
48
+                     c("From file" = "fileGeneset",
49
+                       "From workspace" = "varGeneset"))
50
+        ,
51
+        #If the selected data source is a file
52
+        conditionalPanel(
53
+          condition = "input.genesetSourceType == 'fileGeneset'",
54
+          fileInput("genesetFile", "Choose GeneSet file:",
55
+                    accept = ".gmt")
56
+        ),
57
+        #If the selected data source is a workspace object
58
+        conditionalPanel(
59
+          condition = "input.genesetSourceType == 'varGeneset'",
60
+          selectInput("genesetVar", "Choose GeneSet var:",
61
+                      ls(envir=.GlobalEnv))
62
+        ),
63
+        HTML("<br>"),
64
+        radioButtons("arg", "Control arguments:",
65
+                     c("No" = "no",
66
+                       "Yes" = "yes"))
67
+      )
68
+    ),
69
+    actionButton("button", "Run"))
70
+  )
71
+}
72
+
73
+mainDataInput <- function(id) {
74
+  # Create a namespace function using the provided id
75
+  ns <- NS(id)
76
+  
77
+  #UI Definition
78
+  mainPanel(width = 6,
79
+            h2("Generated GSVA data:"),
80
+            textOutput("information"),
81
+            plotOutput("plot"),
82
+            tableOutput("result"),
83
+            uiOutput("download"))
84
+}
85
+
86
+argumentsDataInput <- function(id) {
87
+  # Create a namespace function using the provided id
88
+  ns <- NS(id)
89
+  
90
+  #UI Definition
91
+  column(
92
+    3,
93
+    conditionalPanel(
94
+      condition = "input.arg == 'yes'",
95
+      h3("Select arguments:"),
96
+      wellPanel(fluidRow(
97
+        column(
98
+          12,
99
+          selectInput("method", "Choose method:",
100
+                      c("gsva","ssgsea","zscore","plage")),
101
+          radioButtons("rnaseq", "Rnaseq:",
102
+                       c("False" = FALSE,
103
+                         "True" = TRUE)),
104
+          radioButtons("absRanking", "abs.ranking:",
105
+                       c("False" = FALSE,
106
+                         "True" = TRUE)),
107
+          numericInput("minSz","min.sz:",value = 1),
108
+          numericInput("maxSz","max.sz (Write 0 for infinite):",value = 0),
109
+          numericInput("noBootstraps","no.bootstraps:",value = 0),
110
+          numericInput("bootstrapPercent","bootstrap.percent:",value = .632),
111
+          numericInput("parallelSz","parallel.sz:",value = 0),
112
+          selectInput("parallelType", "parallel.type:",
113
+                      c("SOCK","MPI","NWS")),
114
+          radioButtons("mxDiff", "mx.diff:",
115
+                       c("True" = TRUE,
116
+                         "False" = FALSE)),
117
+          conditionalPanel(
118
+            condition = "input.method == 'gsva'",
119
+            numericInput("tau1","tau:",value = 1)
120
+          ),
121
+          conditionalPanel(
122
+            condition = "input.method == 'ssgsea'",
123
+            numericInput("tau2","tau:",value = 0.25)
124
+          ),
125
+          conditionalPanel(
126
+            condition = "input.method == 'zscore' || input.method == 'plage'"
127
+          ),
128
+          radioButtons("kernel", "kernel:",
129
+                       c("True" = TRUE,
130
+                         "False" = FALSE)),
131
+          radioButtons("ssgseaNorm", "ssgsea.norm:",
132
+                       c("True" = TRUE,
133
+                         "False" = FALSE)),
134
+          radioButtons("verbose", "verbose:",
135
+                       c("True" = TRUE,
136
+                         "False" = FALSE))
137
+        )))
138
+    )
139
+  )
140
+}
141
+
142
+gsva_validation <- function(input, output, session) {
143
+  success <- FALSE #Variable to control if the GSVA variables are assigned correctly
144
+  if(input$matrixSourceType == "fileMatrix")
145
+  {
146
+    if (is.null(input$matrixFile))
147
+    {
148
+      paste("No matrix file selected!")
149
+      success <- FALSE
150
+    }
151
+    else
152
+    {
153
+      #Matrix file selected
154
+      if(input$genesetSourceType == "fileGeneset")
155
+      {
156
+        if (is.null(input$genesetFile))
157
+        {
158
+          paste("No geneSet file selected!")
159
+          success <- FALSE
160
+        }
161
+        else
162
+        {
163
+          #User selects matrix file and geneSet file
164
+          inFile <- input$matrixFile
165
+          newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix
166
+          rownames(newY) <- newY[,1] #Taking the first column as rownames
167
+          newY <- newY[,-1] #Deleting the first column
168
+          inGenesetFile <- input$genesetFile
169
+          genes <- getGmt(inGenesetFile$datapath)
170
+          if(input$maxSz == 0) {
171
+            varMaxsz <- Inf
172
+          }else {
173
+            varMaxsz <- input$maxSz
174
+          }
175
+          success <- TRUE
176
+        }
177
+      }
178
+      else
179
+      {
180
+        #User selects matrix file and geneset var
181
+        inFile <- input$matrixFile
182
+        newY <- as.matrix(read.csv(inFile$datapath, header = TRUE, sep = ",")) #Reading file as matrix
183
+        rownames(newY) <- newY[,1] #Taking the first column as rownames
184
+        newY <- newY[,-1] #Deleting the first column
185
+        assign("genes",get(input$genesetVar))
186
+        if(input$maxSz == 0) {
187
+          varMaxsz <- Inf
188
+        }else {
189
+          varMaxsz <- input$maxSz
190
+        }
191
+        success <- TRUE
192
+      }
193
+    }
194
+  }
195
+  else
196
+  {
197
+    #User selects matrix varand geneset file
198
+    if(input$genesetSourceType == "fileGeneset")
199
+    {
200
+      if (is.null(input$genesetFile))
201
+      {
202
+        paste("No geneSet file selected!")
203
+        success <- FALSE
204
+      }
205
+      else
206
+      {
207
+        assign("newY",get(input$matrixVar))
208
+        inGenesetFile <- input$genesetFile
209
+        genes <- getGmt(inGenesetFile$datapath)
210
+        if(input$maxSz == 0) {
211
+          varMaxsz <- Inf
212
+        }else {
213
+          varMaxsz <- input$maxSz
214
+        }
215
+        success <- TRUE
216
+      }
217
+    }
218
+    else
219
+    {
220
+      #User selects matrix var selected and geneset var
221
+      assign("newY",get(input$matrixVar))
222
+      assign("genes",get(input$genesetVar))
223
+      if(input$maxSz == 0) {
224
+        varMaxsz <- Inf
225
+      }else {
226
+        varMaxsz <- input$maxSz
227
+      }
228
+      success <- TRUE
229
+    }
230
+  }
231
+  if(success==TRUE)
232
+  {
233
+    gsva_generation(input, output, session, newY, genes,varMaxsz)
234
+    gsva_information(input,output,session)
235
+  }
236
+}
237
+
238
+gsva_generation <- function(input, output, session, newY, genes,varMaxsz) {
239
+  x <- input$method
240
+  selectedTau <- NULL
241
+  switch (x,
242
+          "gsva" = {
243
+            selectedTau <- input$tau1
244
+          },
245
+          "ssgsea" = {
246
+            selectedTau <- input$tau2
247
+          },
248
+          "zscore" = {
249
+            selectedTau <- NULL
250
+          },
251
+          "plage" = {
252
+            selectedTau <- NULL
253
+          }
254
+  )
255
+  #GSVA Generation
256
+  withProgress(message = 'Runing GSVA', value = 0, {
257
+    incProgress(1, detail = "This may take a while...")
258
+    generated_gsva <<- gsva(newY, genes, method = input$method, rnaseq = as.logical(input$rnaseq), abs.ranking = as.logical(input$absRanking),
259
+                            min.sz = input$minSz, max.sz = varMaxsz, no.bootstraps = input$noBootstraps, bootstrap.percent = input$bootstrapPercent, 
260
+                            parallel.sz = input$parallelSz, parallel.type = input$parallelType, mx.diff = as.logical(input$mxDiff), tau = selectedTau, kernel = as.logical(input$kernel),
261
+                            ssgsea.norm = as.logical(input$ssgseaNorm), verbose = as.logical(input$verbose)) #Result asignation
262
+  })
263
+}
264
+
265
+gsva_information <- function(input, output, session) {
266
+  if(class(generated_gsva) == "matrix")
267
+  {
268
+    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva),nrow(generated_gsva)), nrow = 1, ncol = 4)
269
+    colnames(resultInformation) <- c("Matrix used","GeneSet used", "Col num", "Row num")
270
+    output$result <- renderTable(resultInformation)
271
+    output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
272
+    tagList(
273
+      downloadButton('downloadData', 'Download'),
274
+      actionButton('closeSave','Save & Close')
275
+    )
276
+  }
277
+  else
278
+  {
279
+
280
+    resultInformation <- matrix(data = c(input$matrixVar,input$genesetVar,ncol(generated_gsva$es.obs),nrow(generated_gsva$es.obs)), nrow = 1, ncol = 4)
281
+    colnames(resultInformation) <- c("Matrix used","GeneSet used", "Col num", "Row num")
282
+    output$result <- renderTable(resultInformation)
283
+    if(class(generated_gsva$es.obs) == "ExpressionSet") #If the generated gsva is an ExpressionSet
284
+    {
285
+      expressionSetObs <- exprs(generated_gsva$es.obs)
286
+      output$plot <- renderPlot(multidensity(as.list(as.data.frame(expressionSetObs)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2)) 
287
+    }
288
+    else
289
+    {
290
+      output$plot <- renderPlot(multidensity(as.list(as.data.frame(generated_gsva$es.obs)), legend=NA, las=1, xlab=sprintf("%s scores", input$method), main="", lwd=2))
291
+    }
292
+    tagList(
293
+      downloadButton('downloadData', 'Download'),
294
+      actionButton('closeSave','Save & Close')
295
+    )
296
+  }
297
+}
298
+
299
+download_handler <- function(input, output, session) {
300
+  #Controls the Download button
301
+  output$downloadData <- downloadHandler(
302
+    filename = function() {
303
+      paste("gsva_es-", Sys.Date(), ".csv", sep="")
304
+    },
305
+    content = function(file) {
306
+      if(class(generated_gsva) == "matrix") #If the whole object is a matrix
307
+      {
308
+        dataFrameObs <- as.data.frame(generated_gsva)
309
+        write.csv(dataFrameObs, file)
310
+      }
311
+      else
312
+      {
313
+        if(class(generated_gsva$es.obs) == "ExpressionSet") #If the generated gsva es.obs is an ExpressionSet
314
+        {
315
+          expressionSetObs <- exprs(generated_gsva$es.obs)
316
+          dataFrameObs <- as.data.frame(expressionSetObs)
317
+          write.csv(dataFrameObs, file)
318
+        }
319
+        else
320
+        {
321
+          dataFrameObs <- as.data.frame(generated_gsva$es.obs)
322
+          write.csv(dataFrameObs, file)
323
+        } 
324
+      }
325
+    }
326
+  )
327
+}
328
+
329
+igsva <- function() {
330
+  app <- list(ui = NULL, server = NULL)
331
+  app$ui <- fluidPage(theme = shinytheme("simplex"),
332
+                      fluidRow(
333
+                        selectDataInput("dataInput"),
334
+                        mainDataInput("mainInput")
335
+                        ,
336
+                        fluidRow(
337
+                          argumentsDataInput("argumentsInput")
338
+                        )
339
+                      )
340
+  )
341
+  
342
+  app$server <- function(input, output, session) {
343
+    v <- reactiveValues(action = FALSE)
344
+    
345
+    observeEvent(input$button, {
346
+      v$action <- input$button
347
+    })
348
+    
349
+    output$download <- renderUI({
350
+      if(v$action)
351
+      {
352
+        #Isolates the Run event, that allows the program to run the generation only if the user clicks the button.
353
+        isolate({
354
+          gsva_validation(input,output,session)
355
+        })
356
+      }
357
+    })
358
+    download_handler(input,output,session)
359
+    
360
+    #Observe the Save & Close button
361
+    observeEvent(input$closeSave, {
362
+      stopApp(generated_gsva) #Stops the app and returns the generated_gsva object
363
+    })
364
+  }
365
+  runApp(app)
366
+}