Browse code

adapt tmt plotly plots on shiny

deril2605 authored on 25/04/2024 17:28:43
Showing 1 changed files
... ...
@@ -411,18 +411,20 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
411 411
 
412 412
     } else if(loadpage_input()$DDA_DIA=="TMT"){
413 413
       tryCatch({
414
-        plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
415
-                                                    type=input$typeplot,
416
-                                                    sig=input$sig,
417
-                                                    FCcutoff=input$FC,
418
-                                                    logBase.pvalue=input$logp,
419
-                                                    ProteinName=input$pname,
420
-                                                    numProtein=input$nump, 
421
-                                                    clustering=input$cluster, 
422
-                                                    which.Comparison=input$whichComp,
423
-                                                    which.Protein = input$whichProt,
424
-                                                    address=path1(),
425
-                                                    savePDF=pdf)
414
+        # makes use of MSstats groupComparisonPlots function
415
+        plot1 = groupComparisonPlots(data=data_comparison()$ComparisonResult,
416
+                                     type=input$typeplot,
417
+                                     sig=input$sig,
418
+                                     FCcutoff=input$FC,
419
+                                     logBase.pvalue=as.numeric(input$logp),
420
+                                     ProteinName=input$pname,
421
+                                     numProtein=input$nump, 
422
+                                     clustering=input$cluster, 
423
+                                     which.Comparison=input$whichComp,
424
+                                     which.Protein = input$whichProt,
425
+                                     height = input$height,
426
+                                     address="Ex_",
427
+                                     isPlotly = TRUE)[[1]]
426 428
       remove_modal_spinner()
427 429
       },
428 430
       error = function(e){
... ...
@@ -715,8 +717,8 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
715 717
 
716 718
   observeEvent(input$viewresults, {
717 719
     ns <- session$ns
718
-    # TMT and PTM plotly plots are still under development
719
-    if ((loadpage_input()$DDA_DIA == "TMT") || (loadpage_input()$BIO == "PTM")) {
720
+    # PTM plotly plots are still under development
721
+    if (loadpage_input()$BIO == "PTM") {
720 722
       output$comp_plots = renderPlot({
721 723
         group_comparison(FALSE, FALSE)
722 724
       })
Browse code

fix documentation

deril2605 authored on 29/02/2024 23:46:24
Showing 1 changed files
... ...
@@ -14,6 +14,7 @@
14 14
 #' 
15 15
 #' @return list object with user selected options and matrix build
16 16
 #'
17
+#' @export
17 18
 #' @examples
18 19
 #' NA
19 20
 #' 
Browse code

merge ready changes

deril2605 authored on 29/02/2024 23:32:57
Showing 1 changed files
... ...
@@ -14,24 +14,9 @@
14 14
 #' 
15 15
 #' @return list object with user selected options and matrix build
16 16
 #'
17
-#' @export
18 17
 #' @examples
19
-#' \dontrun{
20
-#' library(shiny)
18
+#' NA
21 19
 #' 
22
-#' # Define UI for app that calls the Expdes Server
23
-#' ui <- fluidPage(
24
-#'   # UI elements for Expdes Server inputs
25
-#' )
26
-#'
27
-#' # Define server logic required to call Expdes Server
28
-#' server <- function(input, output, session) {
29
-#'   callModule(statmodelServer, "statmodel", parent_session = session)
30
-#' }
31
-#'
32
-#' # Run the application 
33
-#' shinyApp(ui = ui, server = server)
34
-#' }
35 20
 statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input,get_data,preprocess_data) {
36 21
   ######### UI #########
37 22
   
Browse code

adjust changes for new MSstats

deril2605 authored on 18/02/2024 17:05:13
Showing 1 changed files
... ...
@@ -15,6 +15,23 @@
15 15
 #' @return list object with user selected options and matrix build
16 16
 #'
17 17
 #' @export
18
+#' @examples
19
+#' \dontrun{
20
+#' library(shiny)
21
+#' 
22
+#' # Define UI for app that calls the Expdes Server
23
+#' ui <- fluidPage(
24
+#'   # UI elements for Expdes Server inputs
25
+#' )
26
+#'
27
+#' # Define server logic required to call Expdes Server
28
+#' server <- function(input, output, session) {
29
+#'   callModule(statmodelServer, "statmodel", parent_session = session)
30
+#' }
31
+#'
32
+#' # Run the application 
33
+#' shinyApp(ui = ui, server = server)
34
+#' }
18 35
 statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input,get_data,preprocess_data) {
19 36
   ######### UI #########
20 37
   
... ...
@@ -329,7 +346,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
329 346
       codes = paste(codes, "groupComparisonPlots(data=model$ComparisonResult,
330 347
                            type=\"Enter VolcanoPlot, Heatmap, or ComparisonPlot\",
331 348
                            which.Comparison=\"all\",
332
-                           which.Protein=\"all\",
349
+                           which.Protein=\"all\",isPlotly=FALSE,
333 350
                            address=\"\")\n", sep="")
334 351
     }
335 352
 
Browse code

plotly and ggplot in statmodel distinction

deril2605 authored on 28/01/2024 04:54:27
Showing 1 changed files
... ...
@@ -448,6 +448,8 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
448 448
                                    height = input$height,
449 449
                                    address="Ex_",
450 450
                                    isPlotly = TRUE)[[1]]
451
+      remove_modal_spinner()
452
+      return(plot1)
451 453
       }, error = function(e){
452 454
         remove_modal_spinner()
453 455
         message("An error occurred: ", conditionMessage(e))
... ...
@@ -455,7 +457,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
455 457
       )
456 458
     }
457 459
 
458
-    remove_modal_spinner()
460
+    
459 461
 
460 462
     if(saveFile1) {
461 463
       return(id_address1)
... ...
@@ -710,10 +712,22 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
710 712
 
711 713
   observeEvent(input$viewresults, {
712 714
     ns <- session$ns
715
+    # TMT and PTM plotly plots are still under development
716
+    if ((loadpage_input()$DDA_DIA == "TMT") || (loadpage_input()$BIO == "PTM")) {
717
+      output$comp_plots = renderPlot({
718
+        group_comparison(FALSE, FALSE)
719
+      })
720
+      op <- plotOutput(ns("comp_plots"))
721
+    } else {
722
+      output$comp_plots = renderPlotly({
723
+        group_comparison(FALSE, FALSE)
724
+      })
725
+      op <- plotlyOutput(ns("comp_plots"), height = input$height)
726
+    }
713 727
     insertUI(
714 728
       selector = paste0("#", ns("comparison_plots")),
715 729
       ui=tags$div(
716
-        plotlyOutput(ns("comp_plots"), height = input$height),
730
+        op,
717 731
         conditionalPanel(condition = "input['statmodel-typeplot'] == 'VolcanoPlot' && input['loadpage-DDA_DIA']!='TMT'",
718 732
                          h5("Click on plot for details"),
719 733
                          verbatimTextOutput(ns("info2"))),
... ...
@@ -723,12 +737,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
723 737
     )
724 738
   }
725 739
   )
726
-  
727
-  observe({output$comp_plots = renderPlotly({
728
-    group_comparison(FALSE, FALSE)
729
-    }
730
-  )
731
-  })
732 740
 
733 741
   plotset = reactive({
734 742
 
Browse code

clean statmodel server

deril2605 authored on 28/01/2024 01:37:13
Showing 1 changed files
... ...
@@ -429,23 +429,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
429 429
 
430 430
 
431 431
     } else{
432
-      # tryCatch({
433
-      print("lets seee comppp")
434
-      print(input$whichComp)
435
-      print(input$whichProt)
436
-      print("lets seee comppp")
437
-      # plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
438
-      #                                                       type=input$typeplot,
439
-      #                                                       sig=input$sig,
440
-      #                                                       FCcutoff=input$FC,
441
-      #                                                       logBase.pvalue=input$logp,
442
-      #                                                       ProteinName=input$pname,
443
-      #                                                       numProtein=input$nump,
444
-      #                                                       clustering=input$cluster,
445
-      #                                                       which.Comparison=input$whichComp,
446
-      #                                                       which.Protein = input$whichProt,
447
-      #                                                       address=path1(),
448
-      #                                                       savePDF=pdf)
432
+      tryCatch({                                                   
449 433
       if(toupper(input$typeplot) == "VOLCANOPLOT" && input$whichComp == "all") {
450 434
         remove_modal_spinner()
451 435
         stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )
... ...
@@ -464,11 +448,11 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
464 448
                                    height = input$height,
465 449
                                    address="Ex_",
466 450
                                    isPlotly = TRUE)[[1]]
467
-      # }, error = function(e){
468
-      #   remove_modal_spinner()
469
-      #   message("An error occurred: ", conditionMessage(e))
470
-      #   stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
471
-      # )
451
+      }, error = function(e){
452
+        remove_modal_spinner()
453
+        message("An error occurred: ", conditionMessage(e))
454
+        stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
455
+      )
472 456
     }
473 457
 
474 458
     remove_modal_spinner()
... ...
@@ -482,8 +466,8 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
482 466
 
483 467
   }
484 468
   
469
+  # On Heatmap page to display the num of proteins, bound the input range
485 470
   observe({
486
-    # Check if the input is NA or not a number
487 471
     if(is.na(input$nump) || !is.numeric(input$nump) || input$nump <= 0) {
488 472
       # Reset to default value or handle the error as needed
489 473
       updateNumericInput(session, "nump", value = 100)
... ...
@@ -525,21 +509,11 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
525 509
 
526 510
   ########## output ##########
527 511
   
528
-  # 
529 512
   output$plotresults = downloadHandler(
530 513
     filename = function() {
531 514
       paste("SummaryPlot-", Sys.Date(), ".zip", sep="")
532 515
     },
533 516
     content = function(file) {
534
-      # pdf(file)
535
-      # group_comparison(TRUE, TRUE)
536
-      # dev.off()
537
-      # doc = .get.plotly.plot.html(list(group_comparison(FALSE, FALSE)),800,600)
538
-      # print(doc)
539
-      # writeLines(doc, file)
540
-      # print(file)
541
-      # .save.plotly.plot.html(list(group_comparison(FALSE, FALSE)),"",file,800,600)
542
-      # group_comparison(FALSE, FALSE)
543 517
       files <- list.files(getwd(), pattern = "^Ex_", full.names = TRUE)
544 518
       file_info <- file.info(files)
545 519
       latest_file <- files[which.max(file_info$mtime)]
... ...
@@ -547,22 +521,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
547 521
       file.copy(latest_file, file)
548 522
     }
549 523
   )
550
-  # 
551
-  # observeEvent(input$plotresults, {
552
-  #   # print("IN DOWNLOADDD 111")
553
-  #   # tryCatch({
554
-  #     MSstats::.save.plotly.plot.html(list(group_comparison(FALSE, FALSE)),"",paste("SummaryPlot-", Sys.Date(), sep=""),800,600)
555
-  #     print("IN DOWNLOADDD 222")
556
-  #     showNotification("File downloaded successfully in your local directory")
557
-  #     print("IN DOWNLOADDD 333")
558
-  #   # },
559
-  #   # error=function(cond) {
560
-  #   #   showNotification("File download failed", type='error')
561
-  #   #   message(cond)
562
-  #   #   stop("why")
563
-  #   # })
564
-  #   print("IN DOWNLOADDD 444")
565
-  # })
566 524
 
567 525
   # download comparison data
568 526
 
Browse code

Merge branch 'main' into fix-plotly-plots-deril

Deril Raju authored on 28/01/2024 01:22:01 • GitHub committed on 28/01/2024 01:22:01
Showing 0 changed files
Browse code

input for adjusting proteins on heatmap

deril2605 authored on 17/01/2024 13:48:39
Showing 1 changed files
... ...
@@ -474,6 +474,14 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
474 474
     }
475 475
 
476 476
   }
477
+  
478
+  observe({
479
+    # Check if the input is NA or not a number
480
+    if(is.na(input$nump) || !is.numeric(input$nump) || input$nump <= 0) {
481
+      # Reset to default value or handle the error as needed
482
+      updateNumericInput(session, "nump", value = 100)
483
+    }
484
+  })
477 485
 
478 486
   # model assumptions plots
479 487
 
Browse code

shiny changes adapting mssstats

deril2605 authored on 11/01/2024 16:11:43
Showing 1 changed files
... ...
@@ -509,6 +509,45 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
509 509
 
510 510
 
511 511
   ########## output ##########
512
+  
513
+  # 
514
+  output$plotresults = downloadHandler(
515
+    filename = function() {
516
+      paste("SummaryPlot-", Sys.Date(), ".zip", sep="")
517
+    },
518
+    content = function(file) {
519
+      # pdf(file)
520
+      # group_comparison(TRUE, TRUE)
521
+      # dev.off()
522
+      # doc = .get.plotly.plot.html(list(group_comparison(FALSE, FALSE)),800,600)
523
+      # print(doc)
524
+      # writeLines(doc, file)
525
+      # print(file)
526
+      # .save.plotly.plot.html(list(group_comparison(FALSE, FALSE)),"",file,800,600)
527
+      # group_comparison(FALSE, FALSE)
528
+      files <- list.files(getwd(), pattern = "^Ex_", full.names = TRUE)
529
+      file_info <- file.info(files)
530
+      latest_file <- files[which.max(file_info$mtime)]
531
+      print(latest_file)
532
+      file.copy(latest_file, file)
533
+    }
534
+  )
535
+  # 
536
+  # observeEvent(input$plotresults, {
537
+  #   # print("IN DOWNLOADDD 111")
538
+  #   # tryCatch({
539
+  #     MSstats::.save.plotly.plot.html(list(group_comparison(FALSE, FALSE)),"",paste("SummaryPlot-", Sys.Date(), sep=""),800,600)
540
+  #     print("IN DOWNLOADDD 222")
541
+  #     showNotification("File downloaded successfully in your local directory")
542
+  #     print("IN DOWNLOADDD 333")
543
+  #   # },
544
+  #   # error=function(cond) {
545
+  #   #   showNotification("File download failed", type='error')
546
+  #   #   message(cond)
547
+  #   #   stop("why")
548
+  #   # })
549
+  #   print("IN DOWNLOADDD 444")
550
+  # })
512 551
 
513 552
   # download comparison data
514 553
 
... ...
@@ -873,16 +912,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
873 912
   )
874 913
 
875 914
   
876
-  output$plotresults = downloadHandler(
877
-    filename = function() {
878
-      paste("SummaryPlot-", Sys.Date(), ".pdf", sep="")
879
-    },
880
-    content = function(file) {
881
-      pdf(file)
882
-      group_comparison(TRUE, TRUE)
883
-      dev.off()
884
-    }
885
-  )
886 915
 
887 916
   observeEvent(input$calculate,{
888 917
     enable("Design")
Browse code

major changes

deril2605 authored on 09/12/2023 20:46:05
Showing 1 changed files
... ...
@@ -422,24 +422,46 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
422 422
 
423 423
 
424 424
     } else{
425
-      tryCatch({
426
-      plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
427
-                                                            type=input$typeplot,
428
-                                                            sig=input$sig,
429
-                                                            FCcutoff=input$FC,
430
-                                                            logBase.pvalue=input$logp,
431
-                                                            ProteinName=input$pname,
432
-                                                            numProtein=input$nump, 
433
-                                                            clustering=input$cluster, 
434
-                                                            which.Comparison=input$whichComp,
435
-                                                            which.Protein = input$whichProt,
436
-                                                            address=path1(),
437
-                                                            savePDF=pdf)
438
-      }, error = function(e){
425
+      # tryCatch({
426
+      print("lets seee comppp")
427
+      print(input$whichComp)
428
+      print(input$whichProt)
429
+      print("lets seee comppp")
430
+      # plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
431
+      #                                                       type=input$typeplot,
432
+      #                                                       sig=input$sig,
433
+      #                                                       FCcutoff=input$FC,
434
+      #                                                       logBase.pvalue=input$logp,
435
+      #                                                       ProteinName=input$pname,
436
+      #                                                       numProtein=input$nump,
437
+      #                                                       clustering=input$cluster,
438
+      #                                                       which.Comparison=input$whichComp,
439
+      #                                                       which.Protein = input$whichProt,
440
+      #                                                       address=path1(),
441
+      #                                                       savePDF=pdf)
442
+      if(toupper(input$typeplot) == "VOLCANOPLOT" && input$whichComp == "all") {
439 443
         remove_modal_spinner()
440
-        message("An error occurred: ", conditionMessage(e))
441
-        stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
442
-      )
444
+        stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )
445
+      }
446
+      
447
+      plot1 = groupComparisonPlots(data=data_comparison()$ComparisonResult,
448
+                                   type=input$typeplot,
449
+                                   sig=input$sig,
450
+                                   FCcutoff=input$FC,
451
+                                   logBase.pvalue=as.numeric(input$logp),
452
+                                   ProteinName=input$pname,
453
+                                   numProtein=input$nump, 
454
+                                   clustering=input$cluster, 
455
+                                   which.Comparison=input$whichComp,
456
+                                   which.Protein = input$whichProt,
457
+                                   height = input$height,
458
+                                   address="Ex_",
459
+                                   isPlotly = TRUE)[[1]]
460
+      # }, error = function(e){
461
+      #   remove_modal_spinner()
462
+      #   message("An error occurred: ", conditionMessage(e))
463
+      #   stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
464
+      # )
443 465
     }
444 466
 
445 467
     remove_modal_spinner()
... ...
@@ -679,7 +701,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
679 701
     insertUI(
680 702
       selector = paste0("#", ns("comparison_plots")),
681 703
       ui=tags$div(
682
-        plotlyOutput(ns("comp_plots"), height = "100%"),
704
+        plotlyOutput(ns("comp_plots"), height = input$height),
683 705
         conditionalPanel(condition = "input['statmodel-typeplot'] == 'VolcanoPlot' && input['loadpage-DDA_DIA']!='TMT'",
684 706
                          h5("Click on plot for details"),
685 707
                          verbatimTextOutput(ns("info2"))),
Browse code

minor bug fix to differential results table

devonjkohler authored on 06/11/2023 21:01:22
Showing 1 changed files
... ...
@@ -365,9 +365,15 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
365 365
         data_comp$ComparisonResult$adj.pvalue < input$signif, ]
366 366
 
367 367
     } else {
368
-      significant = with(data_comparison(), round_df(ComparisonResult[
369
-        ComparisonResult$adj.pvalue < input$signif, ]))
370
-
368
+      # significant = with(data_comparison(), round_df(ComparisonResult[
369
+      #   ComparisonResult$adj.pvalue < input$signif & 
370
+      #     !is.na(ComparisonResult$Protein), ]))
371
+      # print(significant)
372
+      
373
+      data_comp = data_comparison()
374
+      significant = data_comp$ComparisonResult[
375
+        which(data_comp$ComparisonResult$adj.pvalue < input$signif), ]
376
+      print(significant)
371 377
     }
372 378
     return(significant)
373 379
   })
Browse code

exported functions for Run App button

devonjkohler authored on 20/10/2023 14:47:13
Showing 1 changed files
... ...
@@ -14,6 +14,7 @@
14 14
 #' 
15 15
 #' @return list object with user selected options and matrix build
16 16
 #'
17
+#' @export
17 18
 statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input,get_data,preprocess_data) {
18 19
   ######### UI #########
19 20
   
Browse code

merging for checksMerge branch 'feature-plot-graph' into fix-plotly-plots-deril

deril2605 authored on 27/09/2023 22:21:24
Showing 0 changed files
Browse code

minor bug fixes

devonjkohler authored on 08/09/2023 14:59:22
Showing 1 changed files
... ...
@@ -346,13 +346,14 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
346 346
 
347 347
   SignificantProteins = eventReactive(input$calculate,{
348 348
     if (loadpage_input()$BIO == "PTM"){
349
+      
349 350
       data_comp = data_comparison()
350 351
       sig_unadj = data_comp$PTM.Model[
351
-        data_comp$PTM.Model$adj.pvalue < input$signif]
352
+        data_comp$PTM.Model$adj.pvalue < input$signif,]
352 353
       sig_prot = data_comp$PROTEIN.Model[
353
-        data_comp$PROTEIN.Model$adj.pvalue < input$signif]
354
+        data_comp$PROTEIN.Model$adj.pvalue < input$signif,]
354 355
       sig_adj = data_comp$ADJUSTED.Model[
355
-        data_comp$ADJUSTED.Model$adj.pvalue < input$signif]
356
+        data_comp$ADJUSTED.Model$adj.pvalue < input$signif,]
356 357
       significant = list(PTM.Model=sig_unadj,
357 358
                          PROTEIN.Model=sig_prot,
358 359
                          ADJUSTED.Model=sig_adj)
Browse code

Interactive Graph changes

vasumathi298 authored on 09/08/2023 06:33:38
Showing 1 changed files
... ...
@@ -436,6 +436,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
436 436
                                                             savePDF=pdf)
437 437
       }, error = function(e){
438 438
         remove_modal_spinner()
439
+        message("An error occurred: ", conditionMessage(e))
439 440
         stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
440 441
       )
441 442
     }
... ...
@@ -677,7 +678,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
677 678
     insertUI(
678 679
       selector = paste0("#", ns("comparison_plots")),
679 680
       ui=tags$div(
680
-        plotOutput(ns("comp_plots"), height = "100%", click = "click1"),
681
+        plotlyOutput(ns("comp_plots"), height = "100%"),
681 682
         conditionalPanel(condition = "input['statmodel-typeplot'] == 'VolcanoPlot' && input['loadpage-DDA_DIA']!='TMT'",
682 683
                          h5("Click on plot for details"),
683 684
                          verbatimTextOutput(ns("info2"))),
... ...
@@ -688,8 +689,9 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
688 689
   }
689 690
   )
690 691
   
691
-  observe({output$comp_plots = renderPlot({
692
-    group_comparison(FALSE, FALSE)}, height = input$height
692
+  observe({output$comp_plots = renderPlotly({
693
+    group_comparison(FALSE, FALSE)
694
+    }
693 695
   )
694 696
   })
695 697
 
... ...
@@ -847,6 +849,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
847 849
     }
848 850
   )
849 851
 
852
+  
850 853
   output$plotresults = downloadHandler(
851 854
     filename = function() {
852 855
       paste("SummaryPlot-", Sys.Date(), ".pdf", sep="")
Browse code

Refactoring code base

vasumathi298 authored on 17/07/2023 05:28:00
Showing 1 changed files
... ...
@@ -20,9 +20,9 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
20 20
   # choices of groups for contrast matrix
21 21
   
22 22
   choices = reactive({
23
-    if (loadpage_input()$BIO == "PTM" & (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil')){
23
+    if (loadpage_input()$BIO == "PTM" & ((loadpage_input()$BIO == "PTM" & loadpage_input()$DDA_DIA == "TMT") | loadpage_input()$filetype=='phil')){
24 24
       levels(preprocess_data()$PTM$ProteinLevelData$Condition)
25
-    } else if(loadpage_input()$BIO == "PTM" & loadpage_input()$PTMTMT == "No"){
25
+    } else if(loadpage_input()$BIO == "PTM" & (loadpage_input()$BIO == "PTM" & loadpage_input()$DDA_DIA != "TMT")){
26 26
       levels(preprocess_data()$PTM$ProteinLevelData$GROUP)
27 27
     } else if(loadpage_input()$DDA_DIA=="TMT"){
28 28
       levels(preprocess_data()$ProteinLevelData$Condition)
... ...
@@ -303,7 +303,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
303 303
                    remove_empty_channel = TRUE
304 304
                    )\n", sep = "")
305 305
     } else if (loadpage_input()$BIO == "PTM"){
306
-      if (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil'){
306
+      if ((loadpage_input()$BIO == "PTM" & loadpage_input()$DDA_DIA == "TMT") | loadpage_input()$filetype=='phil'){
307 307
         dt = "TMT"
308 308
       } else {
309 309
         dt = "LabelFree"
Browse code

Frontend Refactoring

vasumathi298 authored on 13/07/2023 07:24:51
Showing 1 changed files
... ...
@@ -20,9 +20,9 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
20 20
   # choices of groups for contrast matrix
21 21
   
22 22
   choices = reactive({
23
-    if (loadpage_input()$DDA_DIA == "PTM" & (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil')){
23
+    if (loadpage_input()$BIO == "PTM" & (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil')){
24 24
       levels(preprocess_data()$PTM$ProteinLevelData$Condition)
25
-    } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
25
+    } else if(loadpage_input()$BIO == "PTM" & loadpage_input()$PTMTMT == "No"){
26 26
       levels(preprocess_data()$PTM$ProteinLevelData$GROUP)
27 27
     } else if(loadpage_input()$DDA_DIA=="TMT"){
28 28
       levels(preprocess_data()$ProteinLevelData$Condition)
... ...
@@ -39,7 +39,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
39 39
   
40 40
   
41 41
   observe({
42
-    if(loadpage_input()$DDA_DIA == "TMT" | loadpage_input()$DDA_DIA == "PTM"){
42
+    if(loadpage_input()$DDA_DIA == "TMT" | loadpage_input()$BIO == "PTM"){
43 43
       hide("Design")
44 44
     }
45 45
     else{
... ...
@@ -302,7 +302,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
302 302
                    remove_norm_channel = TRUE,
303 303
                    remove_empty_channel = TRUE
304 304
                    )\n", sep = "")
305
-    } else if (loadpage_input()$DDA_DIA == "PTM"){
305
+    } else if (loadpage_input()$BIO == "PTM"){
306 306
       if (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil'){
307 307
         dt = "TMT"
308 308
       } else {
... ...
@@ -318,7 +318,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
318 318
       codes = paste(codes, "\n# Model-based comparison\n", sep = "")
319 319
       codes = paste(codes,"model = MSstats::groupComparison(contrast.matrix, summarized)\n", sep = "")
320 320
     }
321
-    if (loadpage_input()$DDA_DIA == "PTM"){
321
+    if (loadpage_input()$BIO == "PTM"){
322 322
       codes = paste(codes, "groupComparisonPlotsPTM(data=model,
323 323
                            type=\"Enter VolcanoPlot, Heatmap, or ComparisonPlot\",
324 324
                            which.Comparison=\"all\",
... ...
@@ -345,7 +345,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
345 345
   }
346 346
 
347 347
   SignificantProteins = eventReactive(input$calculate,{
348
-    if (loadpage_input()$DDA_DIA == "PTM"){
348
+    if (loadpage_input()$BIO == "PTM"){
349 349
       data_comp = data_comparison()
350 350
       sig_unadj = data_comp$PTM.Model[
351 351
         data_comp$PTM.Model$adj.pvalue < input$signif]
... ...
@@ -387,7 +387,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
387 387
       return(path1_id)
388 388
     }
389 389
 
390
-    if (loadpage_input()$DDA_DIA=="PTM"){
390
+    if (loadpage_input()$BIO=="PTM"){
391 391
       plot1 = groupComparisonPlotsPTM(data_comparison(),
392 392
                                       input$typeplot,
393 393
                                       sig=input$sig,
Browse code

bug fix

devonjkohler authored on 12/06/2023 11:30:47
Showing 1 changed files
... ...
@@ -20,7 +20,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
20 20
   # choices of groups for contrast matrix
21 21
   
22 22
   choices = reactive({
23
-    if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
23
+    if (loadpage_input()$DDA_DIA == "PTM" & (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil')){
24 24
       levels(preprocess_data()$PTM$ProteinLevelData$Condition)
25 25
     } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
26 26
       levels(preprocess_data()$PTM$ProteinLevelData$GROUP)
... ...
@@ -303,7 +303,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
303 303
                    remove_empty_channel = TRUE
304 304
                    )\n", sep = "")
305 305
     } else if (loadpage_input()$DDA_DIA == "PTM"){
306
-      if (loadpage_input()$PTMTMT == "Yes"){
306
+      if (loadpage_input()$PTMTMT == "Yes" | loadpage_input()$filetype=='phil'){
307 307
         dt = "TMT"
308 308
       } else {
309 309
         dt = "LabelFree"
... ...
@@ -412,7 +412,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
412 412
                                                     which.Protein = input$whichProt,
413 413
                                                     address=path1(),
414 414
                                                     savePDF=pdf)
415
-        # remove_modal_spinner()
415
+      remove_modal_spinner()
416 416
       },
417 417
       error = function(e){
418 418
         remove_modal_spinner()
Browse code

minor bug fixes for release

devonjkohler authored on 22/05/2023 17:26:14
Showing 1 changed files
... ...
@@ -421,7 +421,8 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
421 421
 
422 422
 
423 423
     } else{
424
-      tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
424
+      tryCatch({
425
+      plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
425 426
                                                             type=input$typeplot,
426 427
                                                             sig=input$sig,
427 428
                                                             FCcutoff=input$FC,
... ...
@@ -437,7 +438,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
437 438
         remove_modal_spinner()
438 439
         stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
439 440
       )
440
-
441 441
     }
442 442
 
443 443
     remove_modal_spinner()
Browse code

few documentation fixes

deril2605 authored on 14/04/2023 19:26:52
Showing 1 changed files
... ...
@@ -9,6 +9,8 @@
9 9
 #' @param parent_session session of the main calling module
10 10
 #' @param loadpage_input input object from loadpage UI
11 11
 #' @param qc_input input object from QC UI
12
+#' @param get_data stored function that returns the data from loadpage
13
+#' @param preprocess_data stored function that returns preprocessed data
12 14
 #' 
13 15
 #' @return list object with user selected options and matrix build
14 16
 #'
Browse code

code fixes and improve function calls

deril2605 authored on 14/04/2023 17:22:55
Showing 1 changed files
... ...
@@ -12,21 +12,21 @@
12 12
 #' 
13 13
 #' @return list object with user selected options and matrix build
14 14
 #'
15
-statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input) {
15
+statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input,get_data,preprocess_data) {
16 16
   ######### UI #########
17 17
   
18 18
   # choices of groups for contrast matrix
19 19
   
20 20
   choices = reactive({
21 21
     if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
22
-      levels(preprocessData(qc_input(),loadpage_input())$PTM$ProteinLevelData$Condition)
22
+      levels(preprocess_data()$PTM$ProteinLevelData$Condition)
23 23
     } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
24
-      levels(preprocessData(qc_input(),loadpage_input())$PTM$ProteinLevelData$GROUP)
24
+      levels(preprocess_data()$PTM$ProteinLevelData$GROUP)
25 25
     } else if(loadpage_input()$DDA_DIA=="TMT"){
26
-      levels(preprocessData(qc_input(),loadpage_input())$ProteinLevelData$Condition)
26
+      levels(preprocess_data()$ProteinLevelData$Condition)
27 27
     }
28 28
     else{
29
-      levels(preprocessData(qc_input(),loadpage_input())$ProteinLevelData$GROUP)
29
+      levels(preprocess_data()$ProteinLevelData$GROUP)
30 30
     }
31 31
     
32 32
   })
... ...
@@ -94,13 +94,13 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
94 94
   output$WhichProt = renderUI ({
95 95
     ns <- session$ns
96 96
     selectInput(ns("whichProt"),
97
-                label = h4("which protein to plot"), unique(getData(loadpage_input())[[1]]))
97
+                label = h4("which protein to plot"), unique(get_data()[[1]]))
98 98
   })
99 99
 
100 100
   output$WhichProt1 = renderUI ({
101 101
     ns <- session$ns
102 102
     selectizeInput(ns("whichProt1"),
103
-                   label = h4("which protein to plot"), c("", unique(getData(loadpage_input())[[1]])))
103
+                   label = h4("which protein to plot"), c("", unique(get_data()[[1]])))
104 104
   })
105 105
 
106 106
 
... ...
@@ -272,7 +272,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
272 272
       input
273 273
     })
274 274
     matrix = matrix_build()
275
-    dataComparison(statmodel_input(),qc_input(),loadpage_input(),matrix)
275
+    dataComparison(statmodel_input(),qc_input(),loadpage_input(),matrix,preprocess_data())
276 276
   })
277 277
 
278 278
   data_comparison_code = eventReactive(input$calculate, {
... ...
@@ -866,7 +866,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
866 866
   return(
867 867
     list(
868 868
       input = input,
869
-      matrix = matrix_build
869
+      dataComparison = data_comparison
870 870
     )
871 871
   )
872 872
 }
873 873
\ No newline at end of file
Browse code

fix redundant calls summ 1 and 2

deril2605 authored on 14/04/2023 16:15:36
Showing 1 changed files
... ...
@@ -865,7 +865,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
865 865
   
866 866
   return(
867 867
     list(
868
-      ip = input,
868
+      input = input,
869 869
       matrix = matrix_build
870 870
     )
871 871
   )
Browse code

reorganized package and fixed bugs related to reorg

devonjkohler authored on 13/04/2023 18:27:48
Showing 1 changed files
... ...
@@ -856,34 +856,13 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
856 856
     }
857 857
   )
858 858
 
859
-# observeEvent(input$plotresults, {
860
-#   insertUI(
861
-#     selector = "#comparison_plots",
862
-#     ui=tags$div(
863
-#       if (input$typeplot == "VolcanoPlot") {
864
-#         js = paste("window.open('", group_comparison(TRUE, TRUE), "VolcanoPlot.pdf')", sep="")
865
-#         print(js)
866
-#         runjs(js);
867
-#       }
868
-#       else if (input$typeplot == "Heatmap") {
869
-#         js = paste("window.open('", group_comparison(TRUE, TRUE), "Heatmap.pdf')", sep="")
870
-#         runjs(js);
871
-#       }
872
-#       else if (input$typeplot == "ComparisonPlot") {
873
-#         js = paste("window.open('", group_comparison(TRUE, TRUE), "ComparisonPlot.pdf')", sep="")
874
-#         runjs(js);
875
-#       }
876
-#     )
877
-#   )
878
-# })
879
-
880 859
   observeEvent(input$calculate,{
881 860
     enable("Design")
882 861
     enable("typeplot")
883 862
     enable("WhichComp")
884 863
     enable("download_code")
885 864
   })
886
-
865
+  
887 866
   return(
888 867
     list(
889 868
       ip = input,
Browse code

biocheck fixes partial

Deril Raju authored on 11/04/2023 14:38:11
Showing 1 changed files
... ...
@@ -254,11 +254,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
254 254
       }
255 255
     }
256 256
     enable("calculate")
257
-    print("THIS IS THE MATRIX")
258
-    print(contrast$matrix)
259
-    print(class(contrast$matrix))
260
-    print(typeof(contrast$matrix))
261
-    print("THIS IS THE MATRIX")
262 257
     return(contrast$matrix)
263 258
   })
264 259
 
Browse code

documentation and fixes

Deril Raju authored on 31/03/2023 20:04:32
Showing 1 changed files
... ...
@@ -1,3 +1,17 @@
1
+#' Statmodel Server module for stat inference
2
+#'
3
+#' This function sets up the Statmodel server to process data based on user
4
+#' selected inputs
5
+#'
6
+#' @param input input object to capture different ui element values
7
+#' @param output to render and create elements
8
+#' @param session session current module
9
+#' @param parent_session session of the main calling module
10
+#' @param loadpage_input input object from loadpage UI
11
+#' @param qc_input input object from QC UI
12
+#' 
13
+#' @return list object with user selected options and matrix build
14
+#'
1 15
 statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input) {
2 16
   ######### UI #########
3 17
   
Browse code

improvements

Deril Raju authored on 24/03/2023 15:08:06
Showing 1 changed files
... ...
@@ -1,11 +1,4 @@
1
-statmodelServer <- function(input, output, session,parent_session, loadpage_inputs, qc_inputs) {
2
-  
3
-  loadpage_input <- reactive({
4
-    loadpage_inputs
5
-  })
6
-  qc_input <- reactive({
7
-    qc_inputs
8
-  })
1
+statmodelServer <- function(input, output, session,parent_session, loadpage_input, qc_input) {
9 2
   ######### UI #########
10 3
   
11 4
   # choices of groups for contrast matrix
Browse code

major changes

Deril Raju authored on 24/03/2023 06:06:40
Showing 1 changed files
... ...
@@ -12,14 +12,14 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
12 12
   
13 13
   choices = reactive({
14 14
     if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
15
-      levels(preprocessData(qc_input,loadpage_input)$PTM$ProteinLevelData$Condition)
15
+      levels(preprocessData(qc_input(),loadpage_input())$PTM$ProteinLevelData$Condition)
16 16
     } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
17
-      levels(preprocessData(qc_input,loadpage_input)$PTM$ProteinLevelData$GROUP)
17
+      levels(preprocessData(qc_input(),loadpage_input())$PTM$ProteinLevelData$GROUP)
18 18
     } else if(loadpage_input()$DDA_DIA=="TMT"){
19
-      levels(preprocessData(qc_input,loadpage_input)$ProteinLevelData$Condition)
19
+      levels(preprocessData(qc_input(),loadpage_input())$ProteinLevelData$Condition)
20 20
     }
21 21
     else{
22
-      levels(preprocessData(qc_input,loadpage_input)$ProteinLevelData$GROUP)
22
+      levels(preprocessData(qc_input(),loadpage_input())$ProteinLevelData$GROUP)
23 23
     }
24 24
     
25 25
   })
... ...
@@ -270,12 +270,12 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
270 270
       input
271 271
     })
272 272
     matrix = matrix_build()
273
-    dataComparison(statmodel_input,qc_input,loadpage_input,matrix)
273
+    dataComparison(statmodel_input(),qc_input(),loadpage_input(),matrix)
274 274
   })
275 275
 
276 276
   data_comparison_code = eventReactive(input$calculate, {
277 277
     
278
-    codes = preprocessDataCode(qc_input,loadpage_input)
278
+    codes = preprocessDataCode(qc_input(),loadpage_input())
279 279
     comp.mat = matrix_build()
280 280
 
281 281
     codes = paste(codes, "\n# Create the contrast matrix\n", sep = "")
Browse code

integrate new converter

Deril Raju authored on 11/03/2023 18:15:56
Showing 1 changed files
... ...
@@ -395,20 +395,24 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
395 395
 
396 396
 
397 397
     } else if(loadpage_input()$DDA_DIA=="TMT"){
398
-      tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
399
-                                                            type=input$typeplot,
400
-                                                            sig=input$sig,
401
-                                                            FCcutoff=input$FC,
402
-                                                            logBase.pvalue=input$logp,
403
-                                                            ProteinName=input$pname,
404
-                                                            numProtein=input$nump,
405
-                                                            clustering=input$cluster,
406
-                                                            which.Comparison=input$whichComp,
407
-                                                            which.Protein = input$whichProt,
408
-                                                            address=path1(),
409
-                                                            savePDF=pdf)},
410
-               error = function(e){remove_modal_spinner()
411
-                 print("All plots cannot be shown in browser. Please select and individual comparison or download pdf.")}
398
+      tryCatch({
399
+        plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
400
+                                                    type=input$typeplot,
401
+                                                    sig=input$sig,
402
+                                                    FCcutoff=input$FC,
403
+                                                    logBase.pvalue=input$logp,
404
+                                                    ProteinName=input$pname,
405
+                                                    numProtein=input$nump, 
406
+                                                    clustering=input$cluster, 
407
+                                                    which.Comparison=input$whichComp,
408
+                                                    which.Protein = input$whichProt,
409
+                                                    address=path1(),
410
+                                                    savePDF=pdf)
411
+        # remove_modal_spinner()
412
+      },
413
+      error = function(e){
414
+        remove_modal_spinner()
415
+        stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf. **' )}
412 416
       )
413 417
 
414 418
 
... ...
@@ -419,14 +423,15 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
419 423
                                                             FCcutoff=input$FC,
420 424
                                                             logBase.pvalue=input$logp,
421 425
                                                             ProteinName=input$pname,
422
-                                                            numProtein=input$nump,
423
-                                                            clustering=input$cluster,
426
+                                                            numProtein=input$nump, 
427
+                                                            clustering=input$cluster, 
424 428
                                                             which.Comparison=input$whichComp,
425 429
                                                             which.Protein = input$whichProt,
426 430
                                                             address=path1(),
427
-                                                            savePDF=pdf)},
428
-               error = function(e){remove_modal_spinner()
429
-                 print("All plots cannot be shown in browser. Please select and individual comparison or download pdf.")}
431
+                                                            savePDF=pdf)
432
+      }, error = function(e){
433
+        remove_modal_spinner()
434
+        stop( '** Cannnot generate multiple plots in a screen. Please refine selection or save to a pdf.**' )}
430 435
       )
431 436
 
432 437
     }
Browse code

major tests

Deril Raju authored on 08/03/2023 18:56:13
Showing 1 changed files
... ...
@@ -247,6 +247,11 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
247 247
       }
248 248
     }
249 249
     enable("calculate")
250
+    print("THIS IS THE MATRIX")
251
+    print(contrast$matrix)
252
+    print(class(contrast$matrix))
253
+    print(typeof(contrast$matrix))
254
+    print("THIS IS THE MATRIX")
250 255
     return(contrast$matrix)
251 256
   })
252 257
 
Browse code

fix code, refactor

Deril Raju authored on 22/02/2023 22:14:00
Showing 1 changed files
... ...
@@ -267,36 +267,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
267 267
     matrix = matrix_build()
268 268
     dataComparison(statmodel_input,qc_input,loadpage_input,matrix)
269 269
   })
270
-  
271
-  # data_comparison = eventReactive(input$calculate, {
272
-  #   input_data = preprocessData(qc_input,loadpage_input)
273
-  #   contrast.matrix = matrix_build()
274
-  #   if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
275
-  #     model_ptm = MSstatsShiny::tmt_model(input_data$PTM, input, contrast.matrix)
276
-  #     model_protein = MSstatsShiny::tmt_model(input_data$PROTEIN, input, contrast.matrix)
277
-  #     model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
278
-  #                                         model_protein$ComparisonResult)
279
-  #     model = list('PTM.Model' = model_ptm$ComparisonResult,
280
-  #                  'PROTEIN.Model' = model_protein$ComparisonResult,
281
-  #                  'ADJUSTED.Model' = model_adj)
282
-  # 
283
-  #   } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
284
-  #     model_ptm = MSstatsShiny::lf_model(input_data$PTM, contrast.matrix)
285
-  #     model_protein = MSstatsShiny::lf_model(input_data$PROTEIN, contrast.matrix)
286
-  #     model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
287
-  #                                         model_protein$ComparisonResult)
288
-  #     model = list('PTM.Model' = model_ptm$ComparisonResult,
289
-  #                  'PROTEIN.Model' = model_protein$ComparisonResult,
290
-  #                  'ADJUSTED.Model' = model_adj)
291
-  # 
292
-  #   } else if(loadpage_input()$DDA_DIA=="TMT"){
293
-  #     model = MSstatsShiny::tmt_model(input_data, input, contrast.matrix)
294
-  #   }
295
-  #   else{
296
-  #     model = MSstatsShiny::lf_model(input_data, contrast.matrix)
297
-  #   }
298
-  #   return(model)
299
-  # })
300 270
 
301 271
   data_comparison_code = eventReactive(input$calculate, {
302 272
     
... ...
@@ -420,7 +390,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
420 390
 
421 391
 
422 392
     } else if(loadpage_input()$DDA_DIA=="TMT"){
423
-
424 393
       tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
425 394
                                                             type=input$typeplot,
426 395
                                                             sig=input$sig,
... ...
@@ -439,7 +408,6 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
439 408
 
440 409
 
441 410
     } else{
442
-
443 411
       tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
444 412
                                                             type=input$typeplot,
445 413
                                                             sig=input$sig,
Browse code

first level of modules

Deril Raju authored on 15/02/2023 20:13:56
Showing 1 changed files
... ...
@@ -136,6 +136,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
136 136
       )}
137 137
   })
138 138
 
139
+
139 140
   matrix_build = eventReactive(input$submit | input$submit1 | input$submit2 | input$submit3, {
140 141
     req(input$def_comp)
141 142
     req(loadpage_input()$DDA_DIA)
... ...
@@ -258,35 +259,44 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
258 259
   })
259 260
 
260 261
   # Run Models
261
-  data_comparison = eventReactive(input$calculate, {
262
-    input_data = preprocessData(qc_input,loadpage_input)
263
-    contrast.matrix = matrix_build()
264
-    if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
265
-      model_ptm = MSstatsShiny::tmt_model(input_data$PTM, input, contrast.matrix)
266
-      model_protein = MSstatsShiny::tmt_model(input_data$PROTEIN, input, contrast.matrix)
267
-      model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
268
-                                          model_protein$ComparisonResult)
269
-      model = list('PTM.Model' = model_ptm$ComparisonResult,
270
-                   'PROTEIN.Model' = model_protein$ComparisonResult,
271
-                   'ADJUSTED.Model' = model_adj)
272
-
273
-    } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
274
-      model_ptm = MSstatsShiny::lf_model(input_data$PTM, contrast.matrix)
275
-      model_protein = MSstatsShiny::lf_model(input_data$PROTEIN, contrast.matrix)
276
-      model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
277
-                                          model_protein$ComparisonResult)
278
-      model = list('PTM.Model' = model_ptm$ComparisonResult,
279
-                   'PROTEIN.Model' = model_protein$ComparisonResult,
280
-                   'ADJUSTED.Model' = model_adj)
281
-
282
-    } else if(loadpage_input()$DDA_DIA=="TMT"){
283
-      model = MSstatsShiny::tmt_model(input_data, input, contrast.matrix)
284
-    }
285
-    else{
286
-      model = MSstatsShiny::lf_model(input_data, contrast.matrix)
287
-    }
288
-    return(model)
262
+  
263
+  data_comparison <- eventReactive(input$calculate,{
264
+    statmodel_input <- reactive({
265
+      input
266
+    })
267
+    matrix = matrix_build()
268
+    dataComparison(statmodel_input,qc_input,loadpage_input,matrix)
289 269
   })
270
+  
271
+  # data_comparison = eventReactive(input$calculate, {
272
+  #   input_data = preprocessData(qc_input,loadpage_input)
273
+  #   contrast.matrix = matrix_build()
274
+  #   if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
275
+  #     model_ptm = MSstatsShiny::tmt_model(input_data$PTM, input, contrast.matrix)
276
+  #     model_protein = MSstatsShiny::tmt_model(input_data$PROTEIN, input, contrast.matrix)
277
+  #     model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
278
+  #                                         model_protein$ComparisonResult)
279
+  #     model = list('PTM.Model' = model_ptm$ComparisonResult,
280
+  #                  'PROTEIN.Model' = model_protein$ComparisonResult,
281
+  #                  'ADJUSTED.Model' = model_adj)
282
+  # 
283
+  #   } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
284
+  #     model_ptm = MSstatsShiny::lf_model(input_data$PTM, contrast.matrix)
285
+  #     model_protein = MSstatsShiny::lf_model(input_data$PROTEIN, contrast.matrix)
286
+  #     model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
287
+  #                                         model_protein$ComparisonResult)
288
+  #     model = list('PTM.Model' = model_ptm$ComparisonResult,
289
+  #                  'PROTEIN.Model' = model_protein$ComparisonResult,
290
+  #                  'ADJUSTED.Model' = model_adj)
291
+  # 
292
+  #   } else if(loadpage_input()$DDA_DIA=="TMT"){
293
+  #     model = MSstatsShiny::tmt_model(input_data, input, contrast.matrix)
294
+  #   }
295
+  #   else{
296
+  #     model = MSstatsShiny::lf_model(input_data, contrast.matrix)
297
+  #   }
298
+  #   return(model)
299
+  # })
290 300
 
291 301
   data_comparison_code = eventReactive(input$calculate, {
292 302
     
... ...
@@ -695,7 +705,7 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
695 705
     )
696 706
   }
697 707
   )
698
-  # 
708
+  
699 709
   observe({output$comp_plots = renderPlot({
700 710
     group_comparison(FALSE, FALSE)}, height = input$height
701 711
   )
... ...
@@ -894,5 +904,10 @@ statmodelServer <- function(input, output, session,parent_session, loadpage_inpu
894 904
     enable("download_code")
895 905
   })
896 906
 
897
-
907
+  return(
908
+    list(
909
+      ip = input,
910
+      matrix = matrix_build
911
+    )
912
+  )
898 913
 }
899 914
\ No newline at end of file
Browse code

3 mods

Deril Raju authored on 14/02/2023 21:22:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,898 @@
1
+statmodelServer <- function(input, output, session,parent_session, loadpage_inputs, qc_inputs) {
2
+  
3
+  loadpage_input <- reactive({
4
+    loadpage_inputs
5
+  })
6
+  qc_input <- reactive({
7
+    qc_inputs
8
+  })
9
+  ######### UI #########
10
+  
11
+  # choices of groups for contrast matrix
12
+  
13
+  choices = reactive({
14
+    if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
15
+      levels(preprocessData(qc_input,loadpage_input)$PTM$ProteinLevelData$Condition)
16
+    } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
17
+      levels(preprocessData(qc_input,loadpage_input)$PTM$ProteinLevelData$GROUP)
18
+    } else if(loadpage_input()$DDA_DIA=="TMT"){
19
+      levels(preprocessData(qc_input,loadpage_input)$ProteinLevelData$Condition)
20
+    }
21
+    else{
22
+      levels(preprocessData(qc_input,loadpage_input)$ProteinLevelData$GROUP)
23
+    }
24
+    
25
+  })
26
+  row = reactive({rep(0, length(choices()))})
27
+  contrast = reactiveValues()
28
+  comp_list = reactiveValues()
29
+  significant = reactiveValues()
30
+  
31
+  
32
+  observe({
33
+    if(loadpage_input()$DDA_DIA == "TMT" | loadpage_input()$DDA_DIA == "PTM"){
34
+      hide("Design")
35
+    }
36
+    else{
37
+      shinyjs::show("Design")
38
+    }
39
+  })
40
+
41
+  output$choice1 = renderUI({
42
+    ns <- session$ns
43
+    selectInput(ns("group1"), "Group 1", choices())
44
+  })
45
+
46
+  output$choice2 = renderUI({
47
+    ns <- session$ns
48
+    selectInput(ns("group2"), "Group 2", choices())
49
+  })
50
+
51
+  output$choice3 = renderUI({
52
+    ns <- session$ns
53
+    selectInput(ns("group3"), "", choices())
54
+  })
55
+
56
+  output$comp_name = renderUI({
57
+    ns <- session$ns
58
+    textInput(ns("comp_name"), label = "Comparison Name", value = "")
59
+  })
60
+
61
+  output$weights = renderUI({
62
+    ns <- session$ns
63
+    lapply(1:length(choices()), function(i) {
64
+      list(
65
+        numericInput(ns(paste0("weight", i)), label = choices()[i], value=0))
66
+    })
67
+  })
68
+
69
+  # rownames for matrix
70
+
71
+  Rownames = eventReactive(input$submit | input$submit1 | input$submit2 | input$submit3, {
72
+    req(input$def_comp)
73
+    req(loadpage_input()$DDA_DIA)
74
+    tryCatch({
75
+      rownames(matrix_build())},
76
+      error=function(e){})
77
+  })
78
+
79
+  # choices of comparisons/proteins to plot
80
+
81
+  output$WhichComp = renderUI ({
82
+    ns <- session$ns
83
+    selectInput(ns("whichComp"),
84
+                label = h5("Select comparison to plot"), c("all", Rownames()), selected = "all")
85
+  })
86
+
87
+  output$WhichProt = renderUI ({
88
+    ns <- session$ns
89
+    selectInput(ns("whichProt"),
90
+                label = h4("which protein to plot"), unique(getData(loadpage_input())[[1]]))
91
+  })
92
+
93
+  output$WhichProt1 = renderUI ({
94
+    ns <- session$ns
95
+    selectizeInput(ns("whichProt1"),
96
+                   label = h4("which protein to plot"), c("", unique(getData(loadpage_input())[[1]])))
97
+  })
98
+
99
+
100
+  ########## functions ########
101
+
102
+  # build matrix
103
+
104
+  observeEvent(input$def_comp, {
105
+    contrast$matrix = NULL
106
+    comp_list$dList = NULL
107
+  })
108
+
109
+  observeEvent(loadpage_input()$proceed1, {
110
+    contrast$matrix = NULL
111
+    comp_list$dList = NULL
112
+    significant$result = NULL
113
+  })
114
+  
115
+  
116
+
117
+  ## Check contrast matrix was created correctly
118
+  check_cond = eventReactive(input$submit | input$submit1 | input$submit2 | input$submit3, {
119
+    req(input$def_comp)
120
+    req(loadpage_input()$DDA_DIA)
121
+    if(input$def_comp == "custom") {
122
+      validate(
123
+        need(input$group1 != input$group2, "Please select different groups")
124
+      )}
125
+
126
+    else if(input$def_comp == "custom_np") {
127
+
128
+      wt_sum = 0
129
+      for (index in 1:length(choices())){
130
+        wt_sum = wt_sum + input[[paste0("weight", index)]]
131
+      }
132
+
133
+      validate(
134
+        need( wt_sum == 0,
135
+              "The contrast weights should sum up to 0")
136
+      )}
137
+  })
138
+
139
+  matrix_build = eventReactive(input$submit | input$submit1 | input$submit2 | input$submit3, {
140
+    req(input$def_comp)
141
+    req(loadpage_input()$DDA_DIA)
142
+    if(input$def_comp == "custom") {
143
+      if(input$group1 == input$group2){
144
+        return(contrast$matrix)
145
+      }
146
+      index1 = reactive({which(choices() == input$group1)})
147
+      index2 = reactive({which(choices() == input$group2)})
148
+      comp_list$dList = unique(c(isolate(comp_list$dList), paste(input$group1, "vs",
149
+                                                                 input$group2, sep = " ")))
150
+      contrast$row = matrix(row(), nrow=1)
151
+      contrast$row[index1()] = 1
152
+      contrast$row[index2()] = -1
153
+      if (is.null(contrast$matrix)) {
154
+        contrast$matrix = contrast$row
155
+      }
156
+      else {
157
+        contrast$matrix = rbind(contrast$matrix, contrast$row)
158
+        contrast$matrix = rbind(contrast$matrix[!duplicated(contrast$matrix),])
159
+      }
160
+      rownames(contrast$matrix) = comp_list$dList
161
+      colnames(contrast$matrix) = choices()
162
+    }
163
+
164
+    else if(input$def_comp == "custom_np") {
165
+
166
+      wt_sum = 0
167
+      for (index in 1:length(choices())){
168
+        wt_sum = wt_sum + input[[paste0("weight", index)]]
169
+      }
170
+
171
+      if(wt_sum != 0){
172
+        return(contrast$matrix)
173
+      }
174
+
175
+      comp_list$dList = unique(c(isolate(comp_list$dList), input$comp_name))
176
+      contrast$row = matrix(row(), nrow=1)
177
+
178
+      for (index in 1:length(choices())){
179
+        contrast$row[index] = input[[paste0("weight", index)]]
180
+      }
181
+
182
+      if (is.null(contrast$matrix)) {
183
+        contrast$matrix = contrast$row
184
+      } else {
185
+        contrast$matrix = rbind(contrast$matrix, contrast$row)
186
+        contrast$matrix = rbind(contrast$matrix[!duplicated(contrast$matrix),])
187
+      }
188
+      rownames(contrast$matrix) = comp_list$dList
189
+      colnames(contrast$matrix) = choices()
190
+    }
191
+
192
+    else if (input$def_comp == "all_one") {
193
+      for (index in 1:length(choices())) {
194
+        index3 = reactive({which(choices() == input$group3)})
195
+        if(index == index3()) next
196
+        if(loadpage_input()$DDA_DIA=="TMT"){
197
+          comp_list$dList = c(isolate(comp_list$dList),
198
+                              paste(choices()[index], " vs ",
199
+                                    input$group3, sep = ""))
200
+        } else{
201
+          comp_list$dList = c(isolate(comp_list$dList),
202
+                              paste(choices()[index], " vs ",
203
+                                    input$group3, sep = ""))
204
+        }
205
+
206
+        contrast$row = matrix(row(), nrow=1)
207
+        contrast$row[index] = 1
208
+        contrast$row[index3()] = -1
209
+        if (is.null(contrast$matrix)) {
210
+          contrast$matrix = contrast$row
211
+        } else {
212
+          contrast$matrix = rbind(contrast$matrix, contrast$row)
213
+        }
214
+        rownames(contrast$matrix) = comp_list$dList
215
+        colnames(contrast$matrix) = choices()
216
+      }
217
+    }
218
+    else if (input$def_comp == "all_pair") {
219
+      contrast$matrix = NULL
220
+      for (index in 1:length(choices())) {
221
+        for (index1 in 1:length(choices())) {
222
+          if (index == index1) next
223
+          if (index < index1) {
224
+            if(loadpage_input()$DDA_DIA=="TMT"){
225
+              comp_list$dList = c(isolate(comp_list$dList),
226
+                                  paste(choices()[index], " vs ",
227
+                                        choices()[index1], sep = ""))
228
+            } else{
229
+              comp_list$dList = c(isolate(comp_list$dList),
230
+                                  paste(choices()[index], " vs ",
231
+                                        choices()[index1], sep = ""))
232
+            }
233
+            contrast$row = matrix(row(), nrow=1)
234
+            contrast$row[index] = 1
235
+            contrast$row[index1] = -1
236
+            if (is.null(contrast$matrix)) {
237
+              contrast$matrix = contrast$row
238
+            } else {
239
+              contrast$matrix = rbind(contrast$matrix, contrast$row)
240
+              contrast$matrix = rbind(contrast$matrix[!duplicated(contrast$matrix),])
241
+            }
242
+            rownames(contrast$matrix) = comp_list$dList
243
+            colnames(contrast$matrix) = choices()
244
+          }
245
+        }
246
+      }
247
+    }
248
+    enable("calculate")
249
+    return(contrast$matrix)
250
+  })
251
+
252
+  # clear matrix
253
+
254
+  observeEvent({input$clear | input$clear1 | input$clear2 | input$clear3},  {
255
+    disable("calculate")
256
+    comp_list$dList = NULL
257
+    contrast$matrix = NULL
258
+  })
259
+
260
+  # Run Models
261
+  data_comparison = eventReactive(input$calculate, {
262
+    input_data = preprocessData(qc_input,loadpage_input)
263
+    contrast.matrix = matrix_build()
264
+    if (loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "Yes"){
265
+      model_ptm = MSstatsShiny::tmt_model(input_data$PTM, input, contrast.matrix)
266
+      model_protein = MSstatsShiny::tmt_model(input_data$PROTEIN, input, contrast.matrix)
267
+      model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
268
+                                          model_protein$ComparisonResult)
269
+      model = list('PTM.Model' = model_ptm$ComparisonResult,
270
+                   'PROTEIN.Model' = model_protein$ComparisonResult,
271
+                   'ADJUSTED.Model' = model_adj)
272
+
273
+    } else if(loadpage_input()$DDA_DIA == "PTM" & loadpage_input()$PTMTMT == "No"){
274
+      model_ptm = MSstatsShiny::lf_model(input_data$PTM, contrast.matrix)
275
+      model_protein = MSstatsShiny::lf_model(input_data$PROTEIN, contrast.matrix)
276
+      model_adj = MSstatsShiny::apply_adj(model_ptm$ComparisonResult,
277
+                                          model_protein$ComparisonResult)
278
+      model = list('PTM.Model' = model_ptm$ComparisonResult,
279
+                   'PROTEIN.Model' = model_protein$ComparisonResult,
280
+                   'ADJUSTED.Model' = model_adj)
281
+
282
+    } else if(loadpage_input()$DDA_DIA=="TMT"){
283
+      model = MSstatsShiny::tmt_model(input_data, input, contrast.matrix)
284
+    }
285
+    else{
286
+      model = MSstatsShiny::lf_model(input_data, contrast.matrix)
287
+    }
288
+    return(model)
289
+  })
290
+
291
+  data_comparison_code = eventReactive(input$calculate, {
292
+    
293
+    codes = preprocessDataCode(qc_input,loadpage_input)
294
+    comp.mat = matrix_build()
295
+
296
+    codes = paste(codes, "\n# Create the contrast matrix\n", sep = "")
297
+    codes = paste(codes, "contrast.matrix = NULL\n", sep = "")
298
+    for(i in 1:nrow(comp.mat)){
299
+      codes = paste(codes, "comparison = matrix(c(", toString(comp.mat[i,]),"),nrow=1)\n", sep = "")
300
+      codes = paste(codes, "contrast.matrix = rbind(contrast.matrix, comparison)\n", sep = "")
301
+
302
+    }
303
+
304
+    codes = paste(codes, "row.names(contrast.matrix)=c(\"", paste(row.names(comp.mat), collapse='","'),"\")\n", sep = "")
305
+    codes = paste(codes, "colnames(contrast.matrix)=c(\"", paste(colnames(comp.mat), collapse='","'),"\")\n", sep = "")
306
+
307
+    if(loadpage_input()$DDA_DIA == "TMT"){
308
+      codes = paste(codes, "\n# Model-based comparison\n", sep = "")
309
+      codes = paste(codes,"model = MSstatsTMT::groupComparisonTMT(summarized,
310
+                   contrast.matrix = contrast.matrix,
311
+                   moderated = ", input$moderated,",\t\t\t\t
312
+                   adj.method = \"BH\",
313
+                   remove_norm_channel = TRUE,
314
+                   remove_empty_channel = TRUE
315
+                   )\n", sep = "")
316
+    } else if (loadpage_input()$DDA_DIA == "PTM"){
317
+      if (loadpage_input()$PTMTMT == "Yes"){
318
+        dt = "TMT"
319
+      } else {
320
+        dt = "LabelFree"
321
+      }
322
+      codes = paste(codes, "\n# Model-based comparison\n", sep = "")
323
+      codes = paste(codes,"model = MSstatsPTM::groupComparisonPTM(summarized, '",
324
+                    dt, "', \t\t\t\t
325
+                  contrast.matrix = contrast.matrix)\n", sep = "")
326
+    }
327
+    else{
328
+
329
+      codes = paste(codes, "\n# Model-based comparison\n", sep = "")
330
+      codes = paste(codes,"model = MSstats::groupComparison(contrast.matrix, summarized)\n", sep = "")
331
+    }
332
+    if (loadpage_input()$DDA_DIA == "PTM"){
333
+      codes = paste(codes, "groupComparisonPlotsPTM(data=model,
334
+                           type=\"Enter VolcanoPlot, Heatmap, or ComparisonPlot\",
335
+                           which.Comparison=\"all\",
336
+                           which.PTM=\"all\",
337
+                           address=\"\")\n", sep="")
338
+    } else {
339
+      codes = paste(codes, "groupComparisonPlots(data=model$ComparisonResult,
340
+                           type=\"Enter VolcanoPlot, Heatmap, or ComparisonPlot\",
341
+                           which.Comparison=\"all\",
342
+                           which.Protein=\"all\",
343
+                           address=\"\")\n", sep="")
344
+    }
345
+
346
+    return(codes)
347
+  })
348
+
349
+
350
+  round_df = function(df) {
351
+    nums = vapply(df, is.numeric, FUN.VALUE = logical(1))
352
+
353
+    df[,nums] = round(df[,nums], digits = 4)
354
+
355
+    (df)
356
+  }
357
+
358
+  SignificantProteins = eventReactive(input$calculate,{
359
+    if (loadpage_input()$DDA_DIA == "PTM"){
360
+      data_comp = data_comparison()
361
+      sig_unadj = data_comp$PTM.Model[
362
+        data_comp$PTM.Model$adj.pvalue < input$signif]
363
+      sig_prot = data_comp$PROTEIN.Model[
364
+        data_comp$PROTEIN.Model$adj.pvalue < input$signif]
365
+      sig_adj = data_comp$ADJUSTED.Model[
366
+        data_comp$ADJUSTED.Model$adj.pvalue < input$signif]
367
+      significant = list(PTM.Model=sig_unadj,
368
+                         PROTEIN.Model=sig_prot,
369
+                         ADJUSTED.Model=sig_adj)
370
+
371
+    } else if(loadpage_input()$DDA_DIA=="TMT"){
372
+      data_comp = data_comparison()
373
+      significant = data_comp$ComparisonResult[
374
+        data_comp$ComparisonResult$adj.pvalue < input$signif, ]
375
+
376
+    } else {
377
+      significant = with(data_comparison(), round_df(ComparisonResult[
378
+        ComparisonResult$adj.pvalue < input$signif, ]))
379
+
380
+    }
381
+    return(significant)
382
+  })
383
+
384
+  group_comparison = function(saveFile1, pdf) {
385
+
386
+    show_modal_spinner()
387
+
388
+    id1 = as.character(UUIDgenerate(FALSE))
389
+    id_address1 = paste(tempdir(), "\\", id1, sep = "")
390
+
391
+    path1 = function() {
392
+      if (saveFile1) {
393
+        path1_id = paste(tempdir(), "\\", id1, sep = "")
394
+      }
395
+      else {
396
+        path1_id = FALSE
397
+      }
398
+      return(path1_id)
399
+    }
400
+
401
+    if (loadpage_input()$DDA_DIA=="PTM"){
402
+      plot1 = groupComparisonPlotsPTM(data_comparison(),
403
+                                      input$typeplot,
404
+                                      sig=input$sig,
405
+                                      FCcutoff=input$FC,
406
+                                      logBase.pvalue=as.integer(input$logp),
407
+                                      ProteinName = input$pname,
408
+                                      which.Comparison = input$whichComp,
409
+                                      address = FALSE)
410
+
411
+
412
+    } else if(loadpage_input()$DDA_DIA=="TMT"){
413
+
414
+      tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
415
+                                                            type=input$typeplot,
416
+                                                            sig=input$sig,
417
+                                                            FCcutoff=input$FC,
418
+                                                            logBase.pvalue=input$logp,
419
+                                                            ProteinName=input$pname,
420
+                                                            numProtein=input$nump,
421
+                                                            clustering=input$cluster,
422
+                                                            which.Comparison=input$whichComp,
423
+                                                            which.Protein = input$whichProt,
424
+                                                            address=path1(),
425
+                                                            savePDF=pdf)},
426
+               error = function(e){remove_modal_spinner()
427
+                 print("All plots cannot be shown in browser. Please select and individual comparison or download pdf.")}
428
+      )
429
+
430
+
431
+    } else{
432
+
433
+      tryCatch({plot1 = MSstatsShiny::groupComparisonPlots2(data=data_comparison()$ComparisonResult,
434
+                                                            type=input$typeplot,
435
+                                                            sig=input$sig,
436
+                                                            FCcutoff=input$FC,
437
+                                                            logBase.pvalue=input$logp,
438
+                                                            ProteinName=input$pname,
439
+                                                            numProtein=input$nump,
440
+                                                            clustering=input$cluster,
441
+                                                            which.Comparison=input$whichComp,
442
+                                                            which.Protein = input$whichProt,
443
+                                                            address=path1(),
444
+                                                            savePDF=pdf)},
445
+               error = function(e){remove_modal_spinner()
446
+                 print("All plots cannot be shown in browser. Please select and individual comparison or download pdf.")}
447
+      )
448
+
449
+    }
450
+
451
+    remove_modal_spinner()
452
+
453
+    if(saveFile1) {
454
+      return(id_address1)
455
+    }
456
+    else {
457
+      return(plot1)
458
+    }
459
+
460
+  }
461
+
462
+  # model assumptions plots
463
+
464
+  assumptions1 = function(saveFile3, protein) {
465
+    if (input$whichProt1 != "") {
466
+      id2 = as.character(UUIDgenerate(FALSE))
467
+      id_address2 = paste("tmp/",id2, sep = "")
468
+      path2 = function(saveFile3)  {
469
+        if (saveFile3) {
470
+          path_id2 = paste("www/", id_address2, sep = "")
471
+        }
472
+        else {
473
+          path_id2 = FALSE
474
+        }
475
+        return (path_id2)
476
+      }
477
+
478
+      plots = modelBasedQCPlots(data=data_comparison(), type=input$assum_type,
479
+                                which.Protein = protein, address = path2())
480
+
481
+      if(saveFile3) {
482
+        return(path2())
483
+      }
484
+      else {
485
+        return(plots)
486
+      }
487
+    }
488
+    else {
489
+      return(NULL)
490
+    }
491
+  }
492
+
493
+
494
+
495
+  ########## output ##########
496
+
497
+  # download comparison data
498
+
499
+  output$compar = downloadHandler(
500
+    filename = function() {
501
+      paste("comparison-", Sys.Date(), ".csv", sep="")
502
+    },
503
+    content = function(file) {
504
+      write.csv(data_comparison()$ComparisonResult, file)
505
+    })
506
+
507
+  output$model_QC = downloadHandler(
508
+    filename = function() {
509
+      paste("ModelQC-", Sys.Date(), ".csv", sep="")
510
+    },
511
+    content = function(file) {
512
+      write.csv(data_comparison()$ModelQC, file)
513
+    })
514
+
515
+  output$fitted_v = downloadHandler(
516
+    filename = function() {
517
+      paste("model_summary-", Sys.Date(), ".csv", sep="")
518
+    },
519
+    content = function(file) {
520
+      write.csv(capture.output(data_comparison()$fittedmodel), file)
521
+    })
522
+
523
+  # matrix
524
+
525
+  output$message = renderText({
526
+    check_cond()
527
+  })
528
+  observeEvent(input$calculate, {output$code.button = renderUI({
529
+    ns <- session$ns
530
+    downloadButton(ns("download_code"), "Download analysis code", icon("download"),
531
+                   style="color: #000000; background-color: #75ba82; border-color: #000000")
532
+  })})
533
+
534
+  output$matrix = renderUI({
535
+    ns <- session$ns
536
+    tagList(
537
+      h2("Comparison matrix"),
538
+      br(),
539
+      textOutput(ns("message")),
540
+      br(),
541
+      if (is.null(contrast$matrix)) {
542
+        ""
543
+      } else {
544
+        dataTableOutput(ns("table"))
545
+      }
546
+    )
547
+  })
548
+
549
+  output$table = renderDataTable({
550
+    matrix_build()
551
+  }
552
+  )
553
+
554
+  # table of significant proteins
555
+  output$table_results = renderUI({
556
+    ns <- session$ns
557
+    req(data_comparison())
558
+    req(SignificantProteins())
559
+
560
+    if (is.null(significant)) {
561
+
562
+      tagList(
563
+        tags$br())
564
+    } else {
565
+      tagList(
566
+        tags$br(),
567
+        h2("Results"),
568
+        h5("There are ",textOutput(ns("number"), inline = TRUE),"significant proteins"),
569
+        tags$br(),
570
+        dataTableOutput(ns("significant")),
571
+        downloadButton(ns("download_compar"), "Download all modeling results"),
572
+        downloadButton(ns("download_signif"), "Download significant proteins")
573
+
574
+      )
575
+    }
576
+  })
577
+
578
+  output$adj_table_results = renderUI({
579
+    ns <- session$ns
580
+    req(data_comparison())
581
+    req(SignificantProteins())
582
+    significant = SignificantProteins()
583
+    if (is.null(significant$ADJUSTED.Model)) {
584
+      tagList(
585
+        tags$br())
586
+    } else {
587
+      tagList(
588
+        tags$br(),
589
+        h2("Adjusted PTM Modeling Results"),
590
+        h5("There are ",textOutput(ns("number_adj"), inline = TRUE),"significant PTMs"),
591
+        tags$br(),
592
+        dataTableOutput(ns("adj_significant")),
593
+        downloadButton(ns("download_compar_adj"), "Download all modeling results"),
594
+        downloadButton(ns("download_signif_adj"), "Download significant PTMs")
595
+      )
596
+    }
597
+  })
598
+
599
+  output$unadj_table_results = renderUI({
600
+    ns <- session$ns
601
+    req(data_comparison())
602
+    req(SignificantProteins())
603
+    significant = SignificantProteins()
604
+    if (is.null(significant$PTM.Model)) {
605
+      tagList(
606
+        tags$br())
607
+    } else {
608
+      tagList(
609
+        tags$br(),
610
+        h2("Unadjusted PTM Modeling Results"),
611
+        h5("There are ",textOutput(ns("number_unadj"), inline = TRUE),"significant PTMs"),
612
+        tags$br(),
613
+        dataTableOutput(ns("unadj_significant")),
614
+        downloadButton(ns("download_compar_unadj"), "Download all modeling results"),
615
+        downloadButton(ns("download_signif_unadj"), "Download significant PTMs")
616
+      )
617
+    }
618
+  })
619
+
620
+  output$prot_table_results = renderUI({
621
+    ns <- session$ns
622
+    req(data_comparison())
623
+    req(SignificantProteins())
624
+    significant = SignificantProteins()
625
+    if (is.null(significant$PTM.Model)) {
626
+      tagList(
627
+        tags$br())
628
+    } else {
629
+      tagList(
630
+        tags$br(),
631
+        h2("Protein Modeling Results"),
632
+        h5("There are ",textOutput(ns("number_prot"), inline = TRUE),"significant proteins"),
633
+        tags$br(),
634
+        dataTableOutput(ns("prot_significant")),
635
+        downloadButton(ns("download_compar_prot"), "Download all modeling results"),
636
+        downloadButton(ns("download_signif_prot"), "Download significant proteins")
637
+      )
638
+    }
639
+  })
640
+
641
+  output$significant = renderDataTable({
642
+    SignificantProteins()
643
+  }
644
+  )
645
+
646
+  output$adj_significant = renderDataTable({
647
+    SignificantProteins()$ADJUSTED.Model
648
+  }
649
+  )
650
+
651
+  output$unadj_significant = renderDataTable({
652
+    SignificantProteins()$PTM.Model
653
+  }
654
+  )
655
+
656
+  output$prot_significant = renderDataTable({
657
+    SignificantProteins()$PROTEIN.Model
658
+  }
659
+  )
660
+
661
+  # number of significant proteins
662
+  output$number = renderText({
663
+    nrow(SignificantProteins())
664
+  })
665
+
666
+  output$number_adj = renderText({
667
+    nrow(SignificantProteins()$ADJUSTED.Model)
668
+  })
669
+
670
+  output$number_unadj = renderText({
671
+    nrow(SignificantProteins()$PTM.Model)
672
+  })
673
+
674
+  output$number_prot = renderText({
675
+    nrow(SignificantProteins()$PROTEIN.Model)
676
+  })
677
+
678
+  # plot in browser
679
+  observeEvent(input$typeplot, {
680
+    updateSelectInput(session, "whichComp", selected = "all")
681
+  })
682
+
683
+  observeEvent(input$viewresults, {
684
+    ns <- session$ns
685
+    insertUI(
686
+      selector = paste0("#", ns("comparison_plots")),
687
+      ui=tags$div(
688
+        plotOutput(ns("comp_plots"), height = "100%", click = "click1"),
689
+        conditionalPanel(condition = "input['statmodel-typeplot'] == 'VolcanoPlot' && input['loadpage-DDA_DIA']!='TMT'",
690
+                         h5("Click on plot for details"),
691
+                         verbatimTextOutput(ns("info2"))),
692
+        conditionalPanel(condition = "input['statmodel-typeplot'] == 'Heatmap'",
693
+                         sliderInput(ns("height"), "Plot height", value = 500, min = 200, max = 1300, post = "px"))
694
+      )
695
+    )
696
+  }
697
+  )
698
+  # 
699
+  observe({output$comp_plots = renderPlot({
700
+    group_comparison(FALSE, FALSE)}, height = input$height
701
+  )
702
+  })
703
+
704
+  plotset = reactive({
705
+
706
+    if(loadpage_input()$DDA_DIA=="TMT"){
707
+      data_comp = data_comparison()$ComparisonResult
708
+      v1 = data_comp[,1]
709
+      v2 = round(data_comp[,3], 10)
710
+      v3 = round(data_comp[,8], 10)
711
+      v4 = data_comp[,2]
712
+
713
+    } else{
714
+      v1 = data_comparison()$ComparisonResult[,1]
715
+      v2 = round(data_comparison()$ComparisonResult[,3], 10)
716
+      v3 = round(data_comparison()$ComparisonResult[,8], 10)
717
+      v4 = data_comparison()$ComparisonResult[,2]
718
+
719
+    }
720
+
721
+    if (input$logp == "2") {
722
+      v3 = -log2(v3)
723
+    }
724
+    else if (input$logp == "10") {
725
+      v3 = - log10(v3)
726
+    }
727
+
728
+    df = data.frame(v1,v2,v3,v4)
729
+    df = df[df$v4 == input$whichComp,]
730
+    colnames(df) = c("Protein", "logFC", "logadj.pvalue", "comparison")
731
+    return(df)
732
+  })
733
+
734
+  output$info2 = renderPrint({
735
+    print(nearPoints(plotset(), input$click1, xvar = "logFC", yvar = "logadj.pvalue"))
736
+  })
737
+
738
+  # Assumption plots in browser
739
+
740
+  output$verify = renderUI ({
741
+    ns <- session$ns
742
+    tagList(
743
+      plotOutput(ns("assum_plots"), width = "800px", height = "600px"),
744
+      conditionalPanel(condition = "input['statmodel-whichProt1'] != ''",
745
+                       actionButton(ns("saveone1"), "Save this plot"),
746
+                       bsTooltip(id = ns("saveone1"), title = "Open plot as pdf.  Popups must be enabled", placement = "bottom", trigger = "hover"),
747
+                       actionButton(ns("saveall1"), "Save all plots"),
748
+                       bsTooltip(id = ns("saveall1"), title = "Open pdf of all plots.  Popups must be enabled", placement = "bottom", trigger = "hover")
749
+      )
750
+    )
751
+  })
752
+
753
+  output$assum_plots = renderPlot({
754
+    assumptions1(FALSE, input$whichProt1)})
755
+
756
+
757
+  # downloads
758
+  observeEvent(input$saveone1, {
759
+    path = assumptions1(TRUE, input$whichProt1)
760
+    if (input$assum_type == "QQPlots") {
761
+      js = paste("window.open('", path, "QQPlot.pdf')", sep="")
762
+      runjs(js);
763
+    }
764
+    else if (input$type == "ResidualPlots") {
765
+      js = paste("window.open('", path, "ResidualPlots.pdf')", sep="")
766
+      runjs(js);
767
+    }
768
+  })
769
+
770
+  observeEvent(input$saveall1, {
771
+    path = assumptions1(TRUE, "all")
772
+    if (input$assum_type == "QQPlots") {
773
+      js = paste("window.open('", path, "QQPlot.pdf')", sep="")
774
+      runjs(js);
775
+    }
776
+    else if (input$type == "ResidualPlots") {
777
+      js = paste("window.open('", path, "ResidualPlots.pdf')", sep="")
778
+      runjs(js);
779
+    }
780
+  })
781
+
782
+
783
+  output$download_compar = downloadHandler(
784
+    filename = function() {
785
+      paste("test_result-", Sys.Date(), ".csv", sep="")
786
+    },
787
+    content = function(file) {
788
+      write.csv(data_comparison()$ComparisonResult, file)
789
+    }
790
+  )
791
+  output$download_compar_adj = downloadHandler(
792
+    filename = function() {
793
+      paste("adj_data-", Sys.Date(), ".csv", sep="")
794
+    },
795
+    content = function(file) {
796
+      write.csv(data_comparison()$ADJUSTED.Model, file)
797
+    }
798
+  )
799
+  output$download_compar_unadj = downloadHandler(
800
+    filename = function() {
801
+      paste("unadj_data-", Sys.Date(), ".csv", sep="")
802
+    },
803
+    content = function(file) {
804
+      write.csv(data_comparison()$PTM.Model, file)
805
+    }
806
+  )
807
+  output$download_compar_prot = downloadHandler(
808
+    filename = function() {
809
+      paste("prot_data-", Sys.Date(), ".csv", sep="")
810
+    },
811
+    content = function(file) {
812
+      write.csv(data_comparison()$PROTEIN.Model, file)
813
+    }
814
+  )
815
+
816
+  output$download_code = downloadHandler(
817
+    filename = function() {
818
+      paste("mstats-code-", Sys.Date(), ".R", sep="")
819
+    },
820
+    content = function(file) {
821
+      writeLines(paste(
822
+        data_comparison_code(), sep = ""), file)
823
+    })
824
+
825
+  output$download_signif = downloadHandler(
826
+    filename = function() {
827
+      paste("data-", Sys.Date(), ".csv", sep="")
828
+    },
829
+    content = function(file) {
830
+      write.csv(SignificantProteins(), file)
831
+    }
832
+  )
833
+  output$download_signif_adj = downloadHandler(
834
+    filename = function() {
835
+      paste("adj_data-", Sys.Date(), ".csv", sep="")
836
+    },
837
+    content = function(file) {
838
+      write.csv(SignificantProteins()$ADJUSTED.Model, file)
839
+    }
840
+  )
841
+  output$download_signif_unadj = downloadHandler(
842
+    filename = function() {
843
+      paste("unadj_data-", Sys.Date(), ".csv", sep="")
844
+    },
845
+    content = function(file) {
846
+      write.csv(SignificantProteins()$PTM.Model, file)
847
+    }
848
+  )
849
+  output$download_signif_prot = downloadHandler(
850
+    filename = function() {
851
+      paste("prot_data-", Sys.Date(), ".csv", sep="")
852
+    },
853
+    content = function(file) {
854
+      write.csv(SignificantProteins()$PROTEIN.Model, file)
855
+    }
856
+  )
857
+
858
+  output$plotresults = downloadHandler(
859
+    filename = function() {
860
+      paste("SummaryPlot-", Sys.Date(), ".pdf", sep="")
861
+    },
862
+    content = function(file) {
863
+      pdf(file)
864
+      group_comparison(TRUE, TRUE)
865
+      dev.off()
866
+    }
867
+  )
868
+
869
+# observeEvent(input$plotresults, {
870
+#   insertUI(
871
+#     selector = "#comparison_plots",
872
+#     ui=tags$div(
873
+#       if (input$typeplot == "VolcanoPlot") {
874
+#         js = paste("window.open('", group_comparison(TRUE, TRUE), "VolcanoPlot.pdf')", sep="")
875
+#         print(js)
876
+#         runjs(js);
877
+#       }
878
+#       else if (input$typeplot == "Heatmap") {
879
+#         js = paste("window.open('", group_comparison(TRUE, TRUE), "Heatmap.pdf')", sep="")
880
+#         runjs(js);
881
+#       }
882
+#       else if (input$typeplot == "ComparisonPlot") {
883
+#         js = paste("window.open('", group_comparison(TRUE, TRUE), "ComparisonPlot.pdf')", sep="")
884
+#         runjs(js);
885
+#       }
886
+#     )
887
+#   )
888
+# })
889
+
890
+  observeEvent(input$calculate,{
891
+    enable("Design")
892
+    enable("typeplot")
893
+    enable("WhichComp")
894
+    enable("download_code")
895
+  })
896
+
897
+
898
+}
0 899
\ No newline at end of file