server.R 82.3 KB
Newer Older
1
source('LoadPackages.R')
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
2

stevenn's avatar
stevenn committed
3
shinyServer(function(input, output,session) {
svolant's avatar
svolant committed
4
5
6

  hide(id = "loading-content", anim = TRUE, animType = "fade",time=1.5)
  hide(id = "loading-content-bar", anim = TRUE, animType = "fade",time=1.5)
7
8
9
10
11
  #####################################################
  ##
  ##                    LOAD FILES
  ##
  #####################################################
stevenn's avatar
stevenn committed
12
  
stevenn's avatar
stevenn committed
13
14
  ## Create base for contrast
  rand = floor(runif(1,0,1e9))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
15
  namesfile = tempfile(pattern = "BaseContrast", tmpdir = tempdir(), fileext = "")
stevenn's avatar
stevenn committed
16
  file.create(namesfile,showWarnings=FALSE)
17
  target = NULL
18
  
svolant's avatar
svolant committed
19
  ## Popup messages
svolant's avatar
svolant committed
20
  observe(if(input$AddRegScatter) info("By adding the regression line, you will lose interactivity."))
21
  
22
23
24
  ## Reactive target
  values <- reactiveValues(TargetWorking = target,labeled=NULL)
  
stevenn's avatar
stevenn committed
25
  ## Counts file
stevenn's avatar
stevenn committed
26
  dataInputCounts <-reactive({ 
27
    
svolant's avatar
svolant committed
28
    data = NULL
stevenn's avatar
stevenn committed
29
    inFile <- input$fileCounts
30
    
stevenn's avatar
stevenn committed
31
    if (is.null(inFile)) return(NULL)
32
33
    
    
svolant's avatar
svolant committed
34
35
36
37
38
39
    try(read.csv(inFile$datapath,sep=input$sepcount,header=TRUE,check.names=FALSE)->data,silent=T)

    if(!is.null(data)){
      colnames(data) = gsub("-",".",colnames(data))
      ## Rownames
      if(!TRUE%in%duplicated(data[,1])) rownames(data)=data[,1];data=data[,-1]
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
40
      try(round(data, 0)->data, silent=T)
svolant's avatar
svolant committed
41
    }
stevenn's avatar
stevenn committed
42
43
44
    return(as.data.frame(data))
  })
  
45
46
  
  
stevenn's avatar
stevenn committed
47
48
  ## Taxo File
  dataInputTaxo <-reactive({ 
stevenn's avatar
stevenn committed
49
    
stevenn's avatar
stevenn committed
50
    inFile <- input$fileTaxo
stevenn's avatar
stevenn committed
51
    
stevenn's avatar
stevenn committed
52
    if (is.null(inFile)) return(NULL)
53
    
Stevenn Volant's avatar
Stevenn Volant committed
54
55
    if(input$TypeTaxo=="Table") 
    {
svolant's avatar
svolant committed
56
57
      try(read.csv(inFile$datapath,sep=input$septaxo,header=TRUE)->data,silent=T)
    
Stevenn Volant's avatar
Stevenn Volant committed
58
      ## Rownames
svolant's avatar
svolant committed
59
60
61
62
63
64
65
66
67
      if(!is.null(data))
      {
        if(!TRUE%in%duplicated(data[,1])){ 
          DataNames=data[,1]
          colNames=colnames(data)[-1]
          data=as.matrix(data[,-1])
          rownames(data)=DataNames
          colnames(data) = colNames
        }
68
      }
Stevenn Volant's avatar
Stevenn Volant committed
69
    }
stevenn's avatar
stevenn committed
70
    
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
71
72
    if(input$TypeTaxo=="RDP") 
    {
Stevenn Volant's avatar
Stevenn Volant committed
73
      data = read_rdp(inFile$datapath,input$RDP_th)
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
74
    }
stevenn's avatar
stevenn committed
75
76
77
    
    ## Add NA
    data=as.matrix(data)
Stevenn Volant's avatar
Stevenn Volant committed
78
    indNa = which(data=="")
stevenn's avatar
stevenn committed
79
80
    data[indNa]=NA
    
stevenn's avatar
stevenn committed
81
    return(as.data.frame(data))
stevenn's avatar
stevenn committed
82
  })
83
84
  
  
stevenn's avatar
stevenn committed
85
86
  ## BIOM File
  dataInputBiom <-reactive({ 
stevenn's avatar
stevenn committed
87
    
svolant's avatar
svolant committed
88
    data = NULL
stevenn's avatar
stevenn committed
89
    inFile <- input$fileBiom
stevenn's avatar
stevenn committed
90
    
stevenn's avatar
stevenn committed
91
    if (is.null(inFile)) return(NULL)
svolant's avatar
svolant committed
92
    try(read_biom(inFile$datapath)->data,silent=T)
stevenn's avatar
stevenn committed
93
    
stevenn's avatar
stevenn committed
94
    return(data)
stevenn's avatar
stevenn committed
95
  })
96
  
svolant's avatar
svolant committed
97

98
  
svolant's avatar
svolant committed
99
100
101
102
103
104
105
  ## Unifrac File (tree)
  dataInputTree <-reactive({ 
    
    data = NULL
    inFile <- input$fileTree
    
    if (is.null(inFile)) return(NULL)
106
    try(read.tree(inFile$datapath)->data, silent=T)
svolant's avatar
svolant committed
107
108
    CheckTree = CheckTreeFile(data)
    data = CheckTree$tree
109
110
    try(readLines(inFile$datapath)->treeseq, silent=T)
    return(list(data=data, Error=CheckTree$Error, Warning=CheckTree$Warning, treeseq=treeseq))
svolant's avatar
svolant committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  })
  
  
  # Infobox Tree (Unifrac)
  output$InfoTreePhylo_box <- renderInfoBox({
    input$fileTree
    tree_tmp = isolate(dataInputTree())
    tree = tree_tmp$data
    
    res = infoBox(h6(strong("Phylogenetic tree")), subtitle = h6(strong("Load the phylogenetic tree (optional)")) ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("upload"))
    if(!is.null(tree)){
      if(!is.null(isolate(input$fileTree))){
        res = infoBox(h6(strong("Phylogenetic tree")), subtitle = h6("The phylogenetic has been loaded") ,color = "green",width=NULL,fill=TRUE, icon = icon("thumbs-o-up"))
        if(!is.null(tree_tmp$Warning)){      
          res = infoBox(h6(strong("Phylogenetic tree")), subtitle = h6(tree_tmp$Warning) ,color = "orange",width=NULL,fill=TRUE, icon = icon("warning"))
        }
        if(!is.null(tree_tmp$Error)){      
          res = infoBox(h6(strong("Phylogenetic tree")), subtitle = h6(tree_tmp$Error),color = "red",width=NULL,fill=TRUE, icon = icon("thumbs-o-down"))
        }
      }
    } 
    return(res)
  })
134

135
  
stevenn's avatar
stevenn committed
136
137
  ## Input data
  dataInput <-reactive({ 
stevenn's avatar
stevenn committed
138
    
stevenn's avatar
stevenn committed
139
    data = NULL
Stevenn Volant's avatar
Stevenn Volant committed
140
141
    check = NULL
    percent = NULL
svolant's avatar
svolant committed
142
143
    Taxo = NULL
    Counts = NULL
svolant's avatar
svolant committed
144
145
    inputData = NULL
    
stevenn's avatar
stevenn committed
146
    if(input$FileFormat=="fileCounts")
stevenn's avatar
stevenn committed
147
    {
stevenn's avatar
stevenn committed
148
      Counts = dataInputCounts()
svolant's avatar
svolant committed
149
150
151
      if(!input$NoTaxoFile) Taxo = dataInputTaxo()
      if(!is.null(Counts) && input$NoTaxoFile) {Taxo = data.frame(rownames(Counts),row.names = rownames(Counts));names(Taxo)=NA}
      
Stevenn Volant's avatar
Stevenn Volant committed
152
153
      if(!is.null(Counts) && !is.null(Taxo))
      { 
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
154
        tmp = GetDataFromCT(Counts,Taxo, ifelse(input$TypeTable=="MGS" && input$FileFormat!="fileBiom", TRUE, FALSE))
Stevenn Volant's avatar
Stevenn Volant committed
155
156
157
158
        data = list(counts=tmp$counts,taxo=tmp$taxo)
        check = list(CheckCounts=tmp$CheckCounts,CheckTaxo=tmp$CheckTaxo,CheckPercent=tmp$CheckPercent)
        percent = tmp$Percent
      }    
stevenn's avatar
stevenn committed
159
160
    }
    
stevenn's avatar
stevenn committed
161
    if(input$FileFormat=="fileBiom")
stevenn's avatar
stevenn committed
162
    {
stevenn's avatar
stevenn committed
163
      tmpBIOM = dataInputBiom()
Stevenn Volant's avatar
Stevenn Volant committed
164
165
166
167
168
169
170
      if(!is.null(tmpBIOM))
      {
        tmp = GetDataFromBIOM(tmpBIOM)
        data = list(counts=tmp$counts,taxo=tmp$taxo)
        check = list(CheckCounts=tmp$CheckCounts,CheckTaxo=tmp$CheckTaxo,CheckPercent=tmp$CheckPercent)
        percent = tmp$Percent
      }
stevenn's avatar
stevenn committed
171
172
    }
    
svolant's avatar
svolant committed
173
174
175
176
177
178
179
180
181
182
183
#     if(input$FileFormat=="fileRData")
#     {
#       inFile <- input$fileRData
#       load(inFile)
#       if(!is.null(inputData)){
#         data = inputData$data
#         check = inputData$check
#         percent = inputData$percent
#       }
#     }
    
Stevenn Volant's avatar
Stevenn Volant committed
184
    return(list(data=data,check=check,percent=percent))
stevenn's avatar
stevenn committed
185
186
187
  })
  
  
188
189
190
191
192
193
194
  ## Size factor file (optional)
  dataSizeFactors <-reactive({ 
    
    inFile <- input$fileSizeFactors
    
    if (is.null(inFile)) return(NULL)
    
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
195
    data = read.csv(inFile$datapath,sep=input$sepsize,header=TRUE)
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
    return(as.data.frame(data))
  })
  
  
  ## Size factor file (optional)
  SizeFactors_fromFile <-reactive({ 
    
    Error = NULL
    Check = TRUE
    
    data = dataSizeFactors()
    normFactors = dataMergeCounts()$normFactors
    
    if(!is.null(data)){
      ## Check the format
      
      tmp = as.numeric(data)
      names(tmp) = colnames(data)
      
      if(length(tmp)!=length(normFactors)){Error = "The number of samples is not the same than in the target file, size factors will be estimated"; Check = FALSE}
      if(!identical(names(tmp),names(normFactors))){Error = "The names are not the same or in the same order than in the target file, size factors will be estimated"; Check = FALSE}
217
      
218
219
220
221
222
223
224
225
226
227
228
      if(Check) normFactors = tmp
    }
    
    return(list(Check = Check,Error = Error,normFactors=normFactors))
  })
  
  
  
  
  
  
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
229
  ## Merge counts data
230
  dataMergeCounts <-reactive({
Stevenn Volant's avatar
Stevenn Volant committed
231
    input$RunDESeq
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
232
233
234
    
    counts = NULL
    CheckTarget = FALSE
235
    normFactors = NULL
Stevenn Volant's avatar
Stevenn Volant committed
236
    CT_noNorm = NULL
237
    CT_Norm = NULL
238
    ChTM = NULL
239
    data = isolate(dataInput()$data)
240
241
    target = isolate(values$TargetWorking)
    labeled= isolate(values$labeled)
242
    taxo = isolate(input$TaxoSelect)
243
    withProgress(
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
244
245
    if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && !is.null(taxo) && taxo!="..." && !is.null(target)) 
    {
svolant's avatar
svolant committed
246
      design = GetDesign(isolate(input),target)
247
248
      ChTM = CheckTargetModel(input,target,labeled,data$counts)$Error
      if(!is.null(design) && is.null(ChTM))
249
      {
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        tmp = isolate(GetCountsMerge(input,data,taxo,target,design))
        counts = tmp$counts
        ## Filtering the counts
        if(isolate(input$AddFilter) && !is.null(isolate(input$SliderThSamp)) && !is.null(isolate(input$SliderThAb)))
        {
          ind.filter =Filtered_feature(counts,isolate(input$SliderThSamp),isolate(input$SliderThAb))$ind
          counts = counts[-ind.filter,]
        }
        CheckTarget = tmp$CheckTarget
        #target = tmp$target
        #labeled = tmp$labeled
        normFactors = tmp$normFactors
        ## OTU table, norm and no norm
        CT_noNorm = tmp$CT_noNorm
        CT_Norm = tmp$CT_Norm
265
      }
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
266
    }
267
    ,message="Merging the counts ...")
268
    return(list(counts=counts,CheckTarget=CheckTarget,normFactors=normFactors,CT_noNorm=CT_noNorm, CT_Norm=CT_Norm))
269
    #return(list(counts=counts,target=target,labeled=labeled,normFactors=normFactors,CT_noNorm=CT_noNorm))
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
270
  })
271
272
  
  
Stevenn Volant's avatar
Stevenn Volant committed
273
274
275
276
277
278
279
  # Infobox Error counts
  output$InfoErrorCounts <- renderInfoBox({
    
    tmp = dataInput()
    data = tmp$data
    check = tmp$check
    cond = (!is.null(data$counts) && nrow(data$counts)>0)
280
    res =infoBox(h6(strong("Count table")), subtitle = h6("Load the count table") ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("upload"))
Stevenn Volant's avatar
Stevenn Volant committed
281
282
283
    
    if(cond)
    {
284
285
286
      if(!is.null(check$CheckCounts$Warning)) res = infoBox(h6(strong("Count table")), subtitle = h6(check$CheckCounts$Warning), icon = icon("warning"),color = "orange",width=NULL,fill=TRUE)
      if(!is.null(check$CheckCounts$Error)) res = infoBox(h6(strong("Count table")), subtitle = h6(check$CheckCounts$Error), icon = icon("thumbs-o-down"),color = "red",width=NULL,fill=TRUE)
      if(is.null(check$CheckCounts$Error) && is.null(check$CheckCounts$Warning)) res = infoBox(h6(strong("Count table")), subtitle = h6(paste("Format of the count table seems to be OK")), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
Stevenn Volant's avatar
Stevenn Volant committed
287
288
289
290
    }
    
    return(res)
  })
291
  
Stevenn Volant's avatar
Stevenn Volant committed
292
293
294
295
296
297
298
  # Infobox Error counts
  output$InfoErrorTaxo <- renderInfoBox({
    
    tmp = dataInput()
    data = tmp$data
    check = tmp$check
    cond = (!is.null(data$taxo) && nrow(data$taxo)>0)
svolant's avatar
svolant committed
299
    res = infoBox(h6(strong("Taxonomy table")), subtitle = h6("Load the taxonomy table") ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("upload"))
Stevenn Volant's avatar
Stevenn Volant committed
300
301
302
303
304
305
306
307
    
    if(cond)
    {
      if(!is.null(check$CheckTaxo$Warning)) res = infoBox(h6(strong("Taxonomy table")), subtitle = h6(check$CheckTaxo$Warning), icon = icon("warning"),color = "orange",width=NULL,fill=TRUE)
      if(!is.null(check$CheckTaxo$Error)) res = infoBox(h6(strong("Taxonomy table")), subtitle = h6(check$CheckTaxo$Error), icon = icon("thumbs-o-down"),color = "red",width=NULL,fill=TRUE)
      if(is.null(check$CheckTaxo$Error) && is.null(check$CheckTaxo$Warning)) res = infoBox(h6(strong("Taxonomy table")), subtitle = h6(paste("Format of the taxonomy table seems to be OK")), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
    }
    
svolant's avatar
svolant committed
308
    if(input$NoTaxoFile && input$FileFormat=="fileCounts") res = infoBox(h6(strong("Taxonomy table")), subtitle = h6("No taxonomy table has been uploaded, the analysis can only be done at the OTU/gene level"), icon = icon("warning"),color = "orange",width=NULL,fill=TRUE)
Stevenn Volant's avatar
Stevenn Volant committed
309
310
    return(res)
  })
311
312
  
  
Stevenn Volant's avatar
Stevenn Volant committed
313
314
315
316
317
318
319
320
  # Infobox Error counts
  output$valueErrorPercent <- renderInfoBox({
    
    tmp = dataInput()
    data = tmp$data
    check = tmp$check
    cond = (!is.null(data$counts) && nrow(data$counts)>0 && !is.null(data$taxo) && nrow(data$taxo)>0)
    res = valueBox(paste0(0, "%"),h6(strong("Annotated features")), color = "light-blue",width=NULL,icon = icon("list"))
svolant's avatar
svolant committed
321

Stevenn Volant's avatar
Stevenn Volant committed
322
323
324
325
326
327
328
329
330
331
    if(cond)
    {
      percent = round(100*tmp$percent,2)
      if(percent==0) res = valueBox(paste0(percent, "%"),h6(strong("Annotated features")), color = "red",width=NULL,icon = icon("list"))  
      if(percent!=0) res = valueBox(paste0(percent, "%"),h6(strong("Annotated features")), color = "green",width=NULL,icon = icon("list"))  
      
    }
    
    return(res)
  })
stevenn's avatar
stevenn committed
332
  
333
  
334
335
336
337
338
339
340
341
  ####### Filtering the counts (sliders)
  
  output$ThAb <- renderUI({
    input$AddFilter
    
    res = NULL
    counts = isolate(dataMergeCounts()$counts)
    tot = rowSums(counts)
342
    #save(counts,tot,file="testFilter.RData")
343
    withProgress({tmp = SelectThreshAb(counts,lambda=max(round(sum(counts)/nrow(counts)*0.05),min(tot)+1),graph=FALSE)},message="Loading...")
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
    
    res = sliderInput("SliderThAb","Threshold on the total abundance (in log)",min=0,max=round(max(log(tot+1)),1),value = log(tmp+1))
    return(res)
  })
  
  
  output$ThSamp <- renderUI({
    input$AddFilter
    
    res = NULL
    counts = isolate(dataMergeCounts()$counts)
    counts.bin = as.matrix(counts)
    counts.bin[which(counts>0)] = 1
    nbSampByFeat = rowSums(counts.bin)
    
    ## Default value
    val = round(max(nbSampByFeat)*0.2)
    
    res = sliderInput("SliderThSamp","Threshold on the minimal number of samples",min=0,max=max(nbSampByFeat),value = val)
    return(res)
  })
  
  
  ## Plot for the filtering step$
  
  # plot_filter(counts,th.samp,th.abund,type="Scatter")
  
371
  output$Plot_ThAb <- renderPlot({
372
373
374
375
376
377
    counts = dataMergeCounts()$counts
    ## output of plot_filter is ggplot class
    plot_filter(counts,input$SliderThSamp,input$SliderThAb,type="Abundance")
    
  })
    
378
  output$Plot_ThSamp <- renderPlot({
379
380
381
382
    counts = dataMergeCounts()$counts
    ## output of plot_filter is ggplot class
    plot_filter(counts,input$SliderThSamp,input$SliderThAb,type="Samples")
  })
383
  
384
385
386
387
388
  output$Plot_Scatter_Filter <- renderScatterD3({
    counts = dataMergeCounts()$counts
    ## output of plot_filter is ggplot class
    plot_filter(counts,input$SliderThSamp,input$SliderThAb,type="Scatter")
  })
389
390
391
392
393
  #####################################################
  ##
  ##                DYNAMIC MENU
  ##
  #####################################################
stevenn's avatar
stevenn committed
394
395
396
397
398
  
  
  
  output$dymMenu <- renderMenu({
    
Stevenn Volant's avatar
Stevenn Volant committed
399
400
401
    tmp = dataInput()
    data = tmp$data
    check = tmp$check
stevenn's avatar
stevenn committed
402
    
Stevenn Volant's avatar
Stevenn Volant committed
403
404
405
    ## Check error in the counts and taxonomy table 
    CheckOK = (is.null(check$CheckCounts$Error) && is.null(check$CheckTaxo$Error)  && is.null(check$CheckPercent))
    if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && CheckOK)
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
406
    {
svolant's avatar
svolant committed
407

svolant's avatar
svolant committed
408
      sidebarMenu(id = "side",
stevenn's avatar
stevenn committed
409
410
        menuItem("Statistical analysis",
                 menuSubItem("Run differential analysis",tabName="RunDiff"),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
411
                 menuSubItem("Diagnostic plots",tabName="DiagPlotTab"),
stevenn's avatar
stevenn committed
412
                 menuSubItem("Tables",tabName="TableDiff"),
413
414
                 icon = icon("bar-chart-o"), tabName = "AnaStat"
        ),
415
416
417
        menuItem("Visualization",icon = icon("area-chart"),
                 menuSubItem("Global views",tabName="GlobVisu"),
                 menuSubItem("Comparison plots",tabName="CompPlot"),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
418
419
                 tabName = "Visu")
        #menuItem("Perspective plots", icon = icon("pie-chart"), tabName = "Krona")
stevenn's avatar
stevenn committed
420
      )
svolant's avatar
svolant committed
421
    } else{ sidebarMenu(id = "side",NULL)}
svolant's avatar
svolant committed
422

stevenn's avatar
stevenn committed
423
424
425
  })
  
  
426
  
stevenn's avatar
stevenn committed
427
428
429
430
431
432
433
  #####################################################
  ##
  ##                DATA TABLE
  ##
  #####################################################
  
  ## Counts Table
434
  output$DataCounts <- DT::renderDataTable(
Stevenn Volant's avatar
Stevenn Volant committed
435
    dataInput()$data$counts, 
stevenn's avatar
stevenn committed
436
    options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
437
                   pageLength = 10,scrollX=TRUE, processing=FALSE
stevenn's avatar
stevenn committed
438
439
    ))
  
440
  ## Counts Table
441
442
443
444
445
446
447
  output$DataVenn<- DT::renderDataTable(#{
    #SelContrast = input$ContrastList_table_FC
    #resDiff = ResDiffAnal()
    #BaseContrast = read.table(namesfile,header=TRUE)
    GetData_venn(input,input$ContrastList_table_FC,read.table(namesfile,header=TRUE),ResDiffAnal())$df.tot,
  #}
   options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
448
                    pageLength = 10,scrollX=TRUE, processing=FALSE
449
  ))
450
451
  
  
stevenn's avatar
stevenn committed
452
  ## Taxonomy table
453
  output$DataTaxo <- DT::renderDataTable(
Stevenn Volant's avatar
Stevenn Volant committed
454
    dataInput()$data$taxo, 
stevenn's avatar
stevenn committed
455
    options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
svolant's avatar
svolant committed
456
                   pageLength = 10,scrollX=TRUE, processing=FALSE
stevenn's avatar
stevenn committed
457
    ))
458
  
stevenn's avatar
stevenn committed
459
  
stevenn's avatar
stevenn committed
460
  ## Tab box for data visualisation
stevenn's avatar
stevenn committed
461
  output$TabBoxData <- renderUI({
462
    tree = dataInputTree()$data
Stevenn Volant's avatar
Stevenn Volant committed
463
    data=dataInput()$data
464
465
466
467
468
469
470
471
472
473
474
    if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && !is.null(tree))
    {
      tabBox(width = NULL, selected = "Count table",
             tabPanel("Count table",DT::dataTableOutput("DataCounts")),
             tabPanel("Taxonomy",DT::dataTableOutput("DataTaxo")),
             tabPanel("Summary",h5(strong("Percentage of annotation")),htmlOutput("SummaryView"),
                      br(),h5(strong("Number of features by level:")),plotOutput("SummaryViewBarplot",width = 1200,height=500)),
             tabPanel("Phylogeny", PhyloTreeMetaROutput('PhyloTreeMetaR'))
      )
    }
    else if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0)
stevenn's avatar
stevenn committed
475
    {
476
      tabBox(width = NULL, selected = "Count table",
477
478
             tabPanel("Count table",DT::dataTableOutput("DataCounts")),
             tabPanel("Taxonomy",DT::dataTableOutput("DataTaxo")),
svolant's avatar
svolant committed
479
480
             tabPanel("Summary",h5(strong("Percentage of annotation")),htmlOutput("SummaryView"),
                      br(),h5(strong("Number of features by level:")),plotOutput("SummaryViewBarplot",width = 1200,height=500))
stevenn's avatar
stevenn committed
481
      )
stevenn's avatar
stevenn committed
482
    }
stevenn's avatar
stevenn committed
483
    
stevenn's avatar
stevenn committed
484
  })
485
  
486
487
488
489
  output$PhyloTreeMetaR <- renderPhyloTreeMetaR({
    PhyloTreeMetaR(dataInputTree()$treeseq,NULL)
  })
  
svolant's avatar
svolant committed
490
491
492
493
494
495
496
  output$SummaryView <- renderGvis({
    data = dataInput()$data
    taxo = data$taxo
    counts = data$counts
    res = NULL
    if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0)
    {
svolant's avatar
svolant committed
497
      taxo = rbind(taxo,rep(NA,ncol(taxo)))
498
499
500
501
502
503
504
505
506
507
508
509
510
511
      #tmpPercent = round(apply(is.na(taxo),2,table)["FALSE",]/(nrow(taxo)-1)*100,2)
      
      tmp = apply(is.na(taxo),2,table)
      
      if (class(tmp) == "list") {
        tmp2 = sapply(tmp, function (x) {if (! "FALSE" %in% names(x)) {x["FALSE"] = 0} ; return(x["FALSE"])})
      }
      else
      {
        tmp2 = tmp["FALSE",]
      }
      
      tmpPercent = round(tmp2/(nrow(taxo)-1)*100,2)
      
512
      
svolant's avatar
svolant committed
513
      df <- data.frame(Label = colnames(taxo),Value = tmpPercent)
514
      
svolant's avatar
svolant committed
515
      res = gvisGauge(df,options=list(min=0, max=100, greenFrom=80,
516
517
                                      greenTo=100, yellowFrom=60, yellowTo=80,
                                      redFrom=0, redTo=60, width=1200, height=300))
svolant's avatar
svolant committed
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
    }
    return(res)
  })
  
  
  output$SummaryViewBarplot <- renderPlot({
    data = dataInput()$data
    taxo = data$taxo
    counts = data$counts
    res = NULL
    if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0)
    {
      colors=rep(c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78", "#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b",
                   "#c49c94","#e377c2","#f7b6d2","#7f7f7f", "#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"),ceiling(ncol(taxo)/20))
      tmp = apply(taxo,2,unique)
      nbfeatures = as.numeric(lapply(tmp,length)) -as.numeric(lapply(lapply(tmp,is.na),any))
      df <- data.frame(Label = colnames(taxo),Count = nbfeatures)
      df$Label = factor(df$Label,levels =colnames(taxo) )
      res = ggplot(df,aes(x=Label,y=Count,fill=Label))+geom_bar(stat="identity")
      res = res + theme_bw() + xlab("Taxonomy") + scale_fill_manual(values=colors) + guides(fill=FALSE)
    }
    return(res)
  })
  
stevenn's avatar
stevenn committed
542
543
544
545
546
  #####################################################
  ##
  ##                TARGET FILE
  ##
  #####################################################
stevenn's avatar
stevenn committed
547
  
548
  
stevenn's avatar
stevenn committed
549
  ## Load target file
550
  observe({ 
stevenn's avatar
stevenn committed
551
552
    
    inFile <- input$fileTarget
Stevenn Volant's avatar
Stevenn Volant committed
553
    counts = dataInput()$data$counts
svolant's avatar
svolant committed
554
    labeled = 0
svolant's avatar
svolant committed
555
    data = NULL
556
    
stevenn's avatar
stevenn committed
557
558
    if (is.null(inFile)) return(NULL)
    
svolant's avatar
svolant committed
559
560
    ## Read the data
    try(read.csv(inFile$datapath,sep=input$septarget,header=TRUE)->data,silent=TRUE)
stevenn's avatar
stevenn committed
561
    
svolant's avatar
svolant committed
562
563
564
565
566
567
    if(!is.null(data))
    {
      data = as.data.frame(data)
      names = colnames(data)
      
      ## Change the rownames
svolant's avatar
svolant committed
568
      if(!TRUE%in%duplicated(data[,1])) rownames(data)=gsub(pattern = "-",replacement = ".",as.character(data[,1]))
svolant's avatar
svolant committed
569
570
571
572
573
      
      ## Keep only the row which are in the count table
      ind = which(rownames(data)%in%colnames(counts))
      data = as.data.frame(data[ind,])
      colnames(data) = names
svolant's avatar
svolant committed
574
575
      
      
svolant's avatar
svolant committed
576
577
578
579
580
581
582
583
584
      ## Replace "-" by "."
      if(ncol(data)>1 && nrow(data)>1){
        ind_num = which(sapply(as.data.frame(data[,-1]),is.numeric)) + 1
        if(length(ind_num)>0){
          data_tmp =cbind( as.data.frame(apply(as.data.frame(data[,-ind_num]),2,gsub,pattern = "-",replacement = ".")),data[,ind_num])
          colnames(data_tmp) = c(colnames(data)[-ind_num],colnames(data)[ind_num])
          data = data_tmp
        }
        if(length(ind_num)==0){data = as.data.frame(apply(data,2,gsub,pattern = "-",replacement = "."))}
585
      }
svolant's avatar
svolant committed
586
      
587
588
589
      values$TargetWorking = as.data.frame(data)
#       ind_sel = Target_selection()
#       if(length(ind))
svolant's avatar
svolant committed
590
591
592
593
594
595
596
597
598
599
600
      # target = as.data.frame(apply(target,2,gsub,pattern = "-",replacement = "."))
      
      #ord = order(rownames(data))
      #data = data[ord,]
      ### A SUPPRIMER 
      #rownames(data) <- colnames(counts)
      
      # Percent annotated
      #     print(ind)
      #     print(colnames(counts))
      #     print(rownames(data))
601
      values$labeled = length(ind)/length(colnames(counts))*100.0
svolant's avatar
svolant committed
602
    }
603
    
604
605
606
607
608
609
610
611
612
613
614
615
616
    # return(list(target = target, labeled=labeled))
  })
  
  
  observeEvent(input$deleteRows,{
    
    if (!is.null(input$DataTarget_rows_selected)) {
      
      if(nrow(values$TargetWorking)!=0) values$labeled <- (nrow(values$TargetWorking)-length(input$DataTarget_rows_selected))*values$labeled/nrow(values$TargetWorking)
      else values$labeled <- 0
      values$TargetWorking <- values$TargetWorking[-as.numeric(input$DataTarget_rows_selected),]
      
    }
stevenn's avatar
stevenn committed
617
  })
618
619
620
  
  
  
621
622
  
  
stevenn's avatar
stevenn committed
623
624
  ## Interest Variables
  output$SelectInterestVar <- renderUI({
625
    
626
    target=values$TargetWorking
stevenn's avatar
stevenn committed
627
628
629
    if(!is.null(target)) 
    {
      namesTarget = colnames(target)[2:ncol(target)]
Stevenn Volant's avatar
Stevenn Volant committed
630
      selectInput("InterestVar",h6(strong("Select the variables")),namesTarget,selected=namesTarget,multiple=TRUE)
stevenn's avatar
stevenn committed
631
    }
632
    
stevenn's avatar
stevenn committed
633
  })
634
  
stevenn's avatar
stevenn committed
635
636
  ## Interactions
  output$SelectInteraction2 <- renderUI({
637
    
638
    target = values$TargetWorking
639
640
641
    VarInt = input$InterestVar
    res = NULL
    if(!is.null(target) && length(input$InterestVar)>1) 
stevenn's avatar
stevenn committed
642
    {
643
644
      Interac = GetInteraction2(target,VarInt)
      res = selectInput("Interaction2",h6(strong("Add interactions")),Interac,selected=NULL,multiple=TRUE)
stevenn's avatar
stevenn committed
645
    }
646
    if(length(input$InterestVar)==1) res = NULL
stevenn's avatar
stevenn committed
647
    
648
    return(res)
stevenn's avatar
stevenn committed
649
650
651
  })


svolant's avatar
svolant committed
652
653
654
  ## Var for normalization
  output$SelectVarNorm <- renderUI({
    
655
    target=values$TargetWorking
svolant's avatar
svolant committed
656
657
658
659
660
661
662
663
664
665
666
667
668
669
    res = selectInput("VarNorm",h6(strong("Normalization by:")),NULL,multiple=TRUE)
    if(!is.null(target)) 
    {
      namesTarget = colnames(target)[2:ncol(target)]
      ind = which(apply(as.data.frame(target[,namesTarget]),2,is.numeric))
      if(length(ind)>=1) namesTarget = namesTarget[-ind]
      res = selectInput("VarNorm",h6(strong("Normalization by:")),c(NULL,namesTarget),multiple=TRUE)
    }
    return(res)
    
  })
  
  
  
stevenn's avatar
stevenn committed
670
671
  ## Reference radio buttons
  output$RefSelect <- renderUI({
stevenn's avatar
stevenn committed
672
    
673
    target = values$TargetWorking
stevenn's avatar
stevenn committed
674
675
    RB=list()
    if(!is.null(target)) 
stevenn's avatar
stevenn committed
676
    {
stevenn's avatar
stevenn committed
677
678
679
680
      InterVar = input$InterestVar
      if(length(InterVar)>0)
      {
        names = paste0("Ref",InterVar)
681
682
683
684
685
        for(i in 1:length(names))
        {
          val = unique(target[,InterVar[i]])
          RB[[i]] = selectInput(names[i],paste("Reference for",InterVar[i]),as.vector(val))
        }
stevenn's avatar
stevenn committed
686
      }
stevenn's avatar
stevenn committed
687
    }
stevenn's avatar
stevenn committed
688
    return(RB)
stevenn's avatar
stevenn committed
689
    
stevenn's avatar
stevenn committed
690
  })
691
692
  
  
stevenn's avatar
stevenn committed
693
694
  # Infobox design
  output$RowTarget <- renderInfoBox({
695
696
    #target = dataInputTarget()
    #labeled = dataMergeCounts()$labeled
697
    labeled = values$labeled
698
    if(!is.null(labeled)) 
stevenn's avatar
stevenn committed
699
700
    {
      #### Ajout fontion check target
701
702
703
704
      #infoBox(h6(strong("Target file")), subtitle = h6("Your target file is OK"), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
      labeled = round(labeled,2)
      if(labeled>0) res = valueBox(paste0(labeled, "%"),h6(strong("Labeled features")), color = "green",width=NULL,icon = icon("list"))
      else res = valueBox(paste0(labeled, "%"),h6(strong("Labeled features")), color = "red",width=NULL,icon = icon("list"))  
stevenn's avatar
stevenn committed
705
    }
706
707
708
709
710
    #else infoBox(h6(strong("Target file")), subtitle = h6("Label of the target file must correspond to count table column names") ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("warning"))
    else res = valueBox(paste0(0, "%"),h6(strong("Labeled features")), color = "light-blue",width=NULL,icon = icon("list"))
    return(res)
  }
  )
711
712
713
714
  
  
  
  
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
715
  ## target table
716
  output$DataTarget <- DT::renderDataTable(
717
    values$TargetWorking,
718
    options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
719
                   pageLength = 10,scrollX=TRUE, processing=FALSE,server=TRUE
720
721
    ))
  
722
723
724
725
726
727
  Target_selection <- reactive ({
    input$DataTarget_rows_selected
  })
  
   
  
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
728
  ## Counts table for the selected taxonomy level
729
  output$CountsMerge <- DT::renderDataTable(
730
    round(counts(ResDiffAnal()$dds,normalized=TRUE)),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
731
    options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
732
                   pageLength = 10,scrollX=TRUE, processing=FALSE
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
733
    ))
734
735
  
  
Stevenn Volant's avatar
Stevenn Volant committed
736
  ## Box for merged counts
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
737
  output$BoxCountsMerge <- renderUI({
738
    input$RunDESeq
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
739
740
    #counts = isolate(dataMergeCounts()$counts)
    counts = isolate(dataMergeCounts()$CT_Norm)
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
741
742
743
744
    taxo = input$TaxoSelect
    
    if(!is.null(counts) && taxo != "...")
    {
745
      box(title=paste("Count table (",taxo,")",sep=""),width = NULL, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,
746
          DT::dataTableOutput("CountsMerge"),
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
747
748
749
750
751
752
          downloadButton('ExportCounts', 'Export normalised counts'),
          downloadButton('ExportRelative', 'Export relative abundance')
      )  
    }
    
  })
753
  
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
754
755
  ## Export in .csv
  output$ExportCounts <- downloadHandler(
Stevenn Volant's avatar
Stevenn Volant committed
756
    filename = function() { 'NormCounts.csv' },
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
757
758
    #content = function(file){write.csv(dataMergeCounts()$counts, file)}
    content = function(file){write.csv(dataMergeCounts()$CT_Norm, file)}
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
759
  )
760
  
stevenn's avatar
stevenn committed
761
762
763
  ## Export in .csv
  output$ExportRelative <- downloadHandler(
    filename = function() { 'RelativeAb.csv' },
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
764
    content = function(file){write.csv(sweep(dataMergeCounts()$CT_Norm,2,colSums(dataMergeCounts()$CT_Norm),`/`), file)}
stevenn's avatar
stevenn committed
765
  )
766
  
767
768
  ## Export size factors
  output$ExportSizeFactor <- downloadHandler(
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
769
770
    filename = function() { if (input$sepsizef == "\t") 'SHAMAN_sizefactors.tsv' else 'SHAMAN_sizefactors.csv' },
    content = function(file){write.table(SizeFactor_table(), file,quote=FALSE,row.names = FALSE,sep=input$sepsizef)}
771
772
  )
  
773
774
775
776
777
  ## Export in .csv
  output$ExportTarget <- downloadHandler(
    filename = function() { 'Target.csv' },
    content = function(file){write.table(values$TargetWorking, file,sep="\t",quote=FALSE,row.names = FALSE,col.names = TRUE)}
  )
778
  
stevenn's avatar
stevenn committed
779
780
781
  ## Box for target visualisation
  output$BoxTarget <- renderUI({
    
782
    target = values$TargetWorking
783
    
stevenn's avatar
stevenn committed
784
785
786
    if(!is.null(target) &&  nrow(target)>0)
    {
      box(title="Target file overview",width = NULL, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,
787
788
789
          DT::dataTableOutput("DataTarget"),
          actionButton("deleteRows", "Delete samples"),
          downloadButton('ExportTarget', 'Export target file')
stevenn's avatar
stevenn committed
790
791
792
793
      )  
    }
    
  })
794
795
796
797
798
799
800
801
  
  
  
  #####################################################
  ##
  ##            DEFINE CONTRAST
  ##
  #####################################################
stevenn's avatar
stevenn committed
802
803
804
  
  output$contrastMat <- renderUI({
    
stevenn's avatar
stevenn committed
805
806
807
    resDiff = ResDiffAnal()
    dds = resDiff$dds
    names = resultsNames(dds)
808
    
stevenn's avatar
stevenn committed
809
810
    Contrast=list()
    
811
    for(i in 1:length(names)){Contrast[[i]] = numericInput(names[i],names[i],0,step=1,min=-1,max=1)}
812
    
stevenn's avatar
stevenn committed
813
814
815
    return(Contrast)
    
  })
816
817
  
  
stevenn's avatar
stevenn committed
818
819
820
821
822
  output$ContrastOverview <- renderPrint({
    
    resDiff = ResDiffAnal()
    dds = resDiff$dds
    names = resultsNames(dds)
stevenn's avatar
stevenn committed
823
824
    
    cont = input$ContrastList
stevenn's avatar
stevenn committed
825
    filesize = file.info(namesfile)[,"size"]
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
826
    if(is.na(filesize)){filesize=0}
stevenn's avatar
stevenn committed
827
828
829
830
831
832
    if(filesize!=0)
    { 
      ContrastBase = read.table(namesfile,header=TRUE)
      ind = which(colnames(ContrastBase)%in%cont)
      div(HTML(PrintContrasts(names,sapply(ContrastBase[,ind],as.numeric),cont)))
    }
stevenn's avatar
stevenn committed
833
  })
834
835
  
  
stevenn's avatar
stevenn committed
836
837
838
839
840
841
  ## Add contrast function
  AddCont <-eventReactive(input$AddContrast,{
    
    resDiff = ResDiffAnal()
    dds = resDiff$dds
    names = resultsNames(dds)
842
    
stevenn's avatar
stevenn committed
843
    BaseContrast(input,names,namesfile)
Stevenn Volant's avatar
Stevenn Volant committed
844
845
846
    filesize = file.info(namesfile)[,"size"]
    if(is.na(filesize)){filesize=0}
    if(filesize!=0) tmp = read.table(namesfile,header=TRUE)
stevenn's avatar
stevenn committed
847
848
    Contrast = colnames(as.matrix(tmp))
    updateSelectInput(session, "ContrastList","Contrasts",Contrast)
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
849
    updateSelectInput(session, "ContrastList_table","Contrasts",Contrast)
850
    updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",Contrast)
851
    updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",Contrast)
852
    updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",Contrast)
stevenn's avatar
stevenn committed
853
  })
854
  
stevenn's avatar
stevenn committed
855
856
  ## Add contrast 
  observeEvent(input$AddContrast,{  
stevenn's avatar
stevenn committed
857
    
stevenn's avatar
stevenn committed
858
    AddCont()
stevenn's avatar
stevenn committed
859
    
Stevenn Volant's avatar
Stevenn Volant committed
860
  },priority=1)
861

862
  
863
864
865
866
867
  ## Add contrast function
  AddContEasy <-eventReactive(input$AddContrastEasy,{
    
    resDiff = ResDiffAnal()
    dds = resDiff$dds
868
    target = resDiff$target
869
    names = resultsNames(dds)
870
871
872
873
874
875
876
    
    BaseContrastEasy(input,names,namesfile,target)
    filesize = file.info(namesfile)[,"size"]
    if(is.na(filesize)){filesize=0}
    if(filesize!=0) tmp = read.table(namesfile,header=TRUE)
    Contrast = colnames(as.matrix(tmp))
    
877
878
    updateSelectInput(session, "ContrastList","Contrasts",Contrast)
    updateSelectInput(session, "ContrastList_table","Contrasts",Contrast)
879
    updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",Contrast)
880
    updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",Contrast)
881
    updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",Contrast)
882
  })
stevenn's avatar
stevenn committed
883
  
884
885
886
887
888
  ## Add contrast 
  observeEvent(input$AddContrastEasy,{  
    
    AddContEasy()
    
svolant's avatar
svolant committed
889
  },priority=1)
890
891
  
  
892
893
894
  AddContFromFile <-eventReactive(input$fileContrast,{ 
    
    res = ReadContrastFile()
svolant's avatar
svolant committed
895
896
897
    resDiff = ResDiffAnal()
    dds = resDiff$dds
    CheckCont = CheckContrast(res,dds)
898
    
svolant's avatar
svolant committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
    if(is.null(CheckCont$Error))
    {
      res = CheckCont$contrastFile
      createdCont = NULL
      if(!is.null(res))
      { 
        filesize = file.info(namesfile)[,"size"]
        if(is.na(filesize)){filesize=0}
        if(filesize!=0){ createdCont = read.table(namesfile,header=TRUE) }
      
        if(!is.null(createdCont)) res = cbind(res,createdCont)
        updateSelectInput(session, "ContrastList","Contrasts",colnames(res))
        updateSelectInput(session, "ContrastList_table","Contrasts",colnames(res))
        updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",colnames(res))
        updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",colnames(res))
        updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",colnames(res))
        write.table(res,namesfile,row.names=FALSE)
      }
917
918
    }
  })
919
920
  
  observeEvent(input$fileContrast,{ 
921
    
922
    AddContFromFile()
Stevenn Volant's avatar
Stevenn Volant committed
923
  },priority=1)
924
925
  
  
stevenn's avatar
stevenn committed
926
927
928
929
930
  ## Remove contrast function
  RemoveCont <-eventReactive(input$RemoveContrast,{
    
    ## get the size of the contrast base file
    filesize = file.info(namesfile)[,"size"]
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
931
    if(is.na(filesize)){filesize=0}
stevenn's avatar
stevenn committed
932
933
934
935
936
937
    if(filesize!=0)
    { 
      tmp = read.table(namesfile,header=TRUE)
      ind = which(colnames(tmp)%in%input$ContrastList)
      matKept = as.matrix(tmp[,-ind])
      ContrastKept = colnames(tmp)[-ind]
stevenn's avatar
stevenn committed
938
      
stevenn's avatar
stevenn committed
939
940
941
      if(ncol(matKept)>0) write.table(matKept,namesfile,row.names=FALSE,col.names = ContrastKept)
      else file.create(namesfile,showWarnings=FALSE)
      updateSelectInput(session, "ContrastList","Contrasts",ContrastKept)
Amine  GHOZLANE's avatar
Amine GHOZLANE committed
942
      updateSelectInput(session, "ContrastList_table","Contrasts",ContrastKept)
943
      updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",ContrastKept)
944
      updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",ContrastKept)
945
      updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",ContrastKept)
stevenn's avatar
stevenn committed
946
    }
stevenn's avatar
stevenn committed
947
948
949
950
951
952
953
954
955
  })
  
  
  
  ## Remove contrast
  observeEvent(input$RemoveContrast,{  
    
    RemoveCont()
    
Stevenn Volant's avatar
Stevenn Volant committed
956
  },priority=1)
957
  
Stevenn Volant's avatar
Stevenn Volant committed
958
959
960
  ## Remove all contrasts
  RemoveAllCont <-eventReactive(input$RunDESeq,{
    
961
962