File size: 3,677 Bytes
c038271
8e7c9f6
c038271
 
 
8e7c9f6
 
c038271
8e7c9f6
c038271
7c52e86
c038271
 
 
 
 
 
 
 
 
8e7c9f6
 
c038271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f4ff44
 
 
c038271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e7c9f6
c038271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8e7c9f6
 
 
c038271
 
 
 
8e7c9f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c038271
8e7c9f6
 
 
c038271
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
box::use(
  shiny[...],
  bs4Dash[box, dashboardPage, tabItems, tabItem, sidebarMenu, menuItem, dashboardHeader, column, dashboardBrand, dashboardSidebar, dashboardBody],
  thematic[thematic_shiny],
  shinyjs[useShinyjs, runjs],
  gargoyle[init],
  utils[globalVariables]
)
globalVariables(c("mutation.table.df", "hgnc2pfam.df"))

library(g3viz)
box::use(
  app/logic/data_preprocessor[preprocess_data],
  app/logic/data_preprocessor[preprocess_maf_data]
)

box::use(
  app/view/table,
  app/view/sankey,
  app/view/lollipop,
  app/view/browser,
  app/view/plot_options
)

thematic_shiny()

#' @export
ui <- function(id) {
  ns <- NS(id)
  dashboardPage(
    header = dashboardHeader(
      title = "VarWiz",
      skin = "dark",
      status = "white"
    ),
    dark = NULL,
    help = NULL,
    sidebar = dashboardSidebar(
      collapsed = TRUE,
      status = "navy",
      skin = "dark",
      sidebarMenu(
        id = "side_menu",
        div(class = "menu-tab", menuItem("Visualization", tabName = "visualization_tab", icon = icon("chart-line"))),
        div(class = "menu-tab", menuItem("Browse data", tabName = "browse_tab", icon = icon("table")))
       # div(class = "menu-tab", menuItem("About", tabName = "about_tab", icon = icon("book-open"))),
      #  div(class = "menu-tab", menuItem("Start Tutorial", tabName = "tutorial", icon = icon("play")))
      )
    ),
    body = dashboardBody(
      tags$head(
        tags$script(
          "$(function() {
              $('[data-card-widget=\"maximize\"]').on('click', function() {
                setTimeout(function() {
                  var isMaximized = $('html').hasClass('maximized-card');
                  if (isMaximized) {
                    $('#app-sankey-sankey').css('height', '1000px');
                  } else {
                    $('#app-sankey-sankey').css('height', '400px');
                  }
                }, 300);
                $('#app-sankey-sankey').trigger('resize');
              });
            });
            "
        )
      ),
      
      useShinyjs(),
      tabItems(
        tabItem(
          tabName = "visualization_tab",
          fluidRow(
            column(
              width = 9,
              plot_options$ui(ns("plot_options")),
              sankey$ui(ns("sankey")),
              lollipop$ui(ns("lollipop"))
            ),
            column(
              width = 3,
              table$ui(ns("table")),
            ),
          )
        ),
        
        tabItem(
          tabName = "browse_tab",
          browser$ui(ns("browser"))
          
        ),
        
        tabItem(
          tabName = "about_tab"
        )
      )
      
      
      
    )
  )
}


whole_dataset <- preprocess_maf_data()

#' @export
server <- function(id) {
  moduleServer(id, function(input, output, session) {
    init("reset_sankey")

    ns <- NS(id)
    data <- reactiveVal(whole_dataset)
    options <- plot_options$server("plot_options", unique(data()$Variant_Type), unique(data()$Consequence))
    observeEvent(options(), {
      req((length(options()[[1]]) > 0 || length(options()[[2]] > 0)))

      selected_var_types <- options()[[1]]
      selected_consequences <- options()[[2]]
      
      tab <- whole_dataset[Variant_Type %in% selected_var_types]
      data(tab[Consequence %in% selected_consequences])
      
    })

    # data <- preprocess_data()
    browser$server("browser", data())
    
    selected_features <- table$server("table", data())
    selected_gene_rval <- sankey$server("sankey", data, selected_features()[[1]], selected_features()[[2]], selected_features()[[3]])
    lollipop$server("lollipop", data, selected_gene_rval)
  })
}