-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
2214 lines (2013 loc) · 112 KB
/
app.R
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
library(shiny)
source("global.R") # Run once as app start
complex_table = complex_table_show_all()
PdbList = as.factor(sort(unique(complex_table$Pdb)))
ExperimentList = as.factor(sort(unique(complex_table$PDBExperiment)))
SpeciesList = as.factor(sort(unique(c(complex_table$HeavySpecies,complex_table$LightSpecies,complex_table$AntigenSpecies))))
chain_table = chain_table_show_all()
interaction_table = interaction_table_show_all()
options(error = traceback)
###################################################################################
# User interface (Main function) ----
ui <- function(){
#### Layout for specific pages ####
home_page = function(){
fluidRow(
column(10, offset = .5,
h3("Welcome to Ydb! - This page is under construction", style = "font-family: 'Source Sans Pro';")
)
)
}
#### Stats plots page ####
dbstats_charts = function(){
fluidPage(
#### opts ####
theme = shinytheme("yeti"),
useShinyjs(),
box(
title = "General Statistics",
status = "warning",
width = 12,
footer = withSpinner(tableOutput("general_stats_tbl"))
),
box(
title = "PDB Statistics",
status = "info",
width = 12,
collapsible = T,
collapsed = F,
billboarderOutput(outputId = "pdb_byyear_barplot"),
billboarderOutput(outputId = "pdbexperiment_piechart"),
billboarderOutput(outputId = "pdb_resolution_histogram")
),
box(
title = "Chain Statistics",
status = "info",
width = 12,
collapsible = T,
collapsed = F,
billboarderOutput(outputId = "heavy_species_piechart"),
billboarderOutput(outputId = "light_species_piechart"),
billboarderOutput(outputId = "antigen_species_piechart")
)
#,box(
# title = "Interaction Statistics",
# status = "info",
# width = 12,
# collapsible = T,
# collapsed = F,
# billboarderOutput(outputId = "interaction_by_residue_barplot"),
# billboarderOutput(outputId = "atominteraction_by_type_barplot"),
# billboarderOutput(outputId = "atominteraction_distances_by_type_histogram"),
# billboarderOutput(outputId = "atominteraction_distances_by_antigenresidue_histogram"),
# billboarderOutput(outputId = "atominteraction_distances_by_antibodyresidue_histogram")
#)
)
}
#### ####
#### Interaction plots page ####
interaction_charts = function(){
fluidPage(
#### opts ####
theme = shinytheme("yeti"),
useShinyjs(),
#### ####
fluidRow(
#### Select type of plot ####
column(12,
selectInput("int_plot_type",h4("Plot by"), width = '100%',
list('Frequency of Antibody amino acids by IMGT position' = "select_antibodyresidue_by_position_barplot",
'Number of interactions by antibody-antigen residues' = "select_atominteraction_residues_heatmap",
'Network' = 'select_network')
)
)
#### ####
),
fluidRow(
#### Plot area ####
tabBox(
title = "Explore interactions",
id = "interactionBox",
width = 8,
height = 600,
tabPanel("Plot", withSpinner(uiOutput("interaction_plots"))),
tabPanel("Data", withSpinner(uiOutput("interaction_plots_data")))
),
#### ####
#### General options for all kinds of charts ####
box(
title = "Selection info",
status = "primary",
collapsible = T,
width = 4,
materialSwitch(inputId = "interactionPlots_dataSelection_switch",
label = "Show only selected entries",
status = "primary", right = F, value=T),
withSpinner(htmlOutput("selection_info"))
),
#### ####
#### Plot options menu (Conditional) ####
box(
title = "Plot options",
status = "warning",
width = 4,
#### Options for plot by IMGT position ####
conditionalPanel(condition = 'input.int_plot_type == "select_antibodyresidue_by_position_barplot"',
# Select IMGT position
pickerInput(
inputId = "alignment_position_checkbox",
label = "Show by IMGT position:",
choices = c("CDR1", "CDR2", "CDR3",
"FR1","FR2","FR3","FR4"),
selected = "CDR1",
options = list(
'dropupAuto' = FALSE,
'actions-box' = TRUE,
size = 5
),
multiple = TRUE
),
# Show by count | percentage
radioButtons(inputId = "show_by_percentage_switch",
label = "Show frequency by",
choices = c("Raw counts","Proportion (%)"),
selected = "Raw counts"
),
# Color by aa | class
radioButtons(inputId = "resColor_imgtplot",
label = "Color residues",
choices = c("by Class","by Amino acids"),
selected = "by Class"
)
),
#### ####
#### Options for interaction heatmap ####
conditionalPanel(condition = 'input.int_plot_type == "select_atominteraction_residues_heatmap"',
# Select interaction type
pickerInput(
inputId = "interaction_type_picker",
label = "Filter by Atom Interaction type:",
choices = as.character(atom_interaction_type$type),
selected = as.character(atom_interaction_type$type),
options = list(
'dropupAuto' = FALSE,
'actions-box' = TRUE,
size = 5
),
multiple = TRUE
),
selectInput(
inputId = "interaction_heatmap_data",
label = "Show by:",
choices = c("Number of Interactions",
"Distance"),
selected = "Number of Interactions"
),
conditionalPanel(condition = 'input.interaction_heatmap_data == "Distance"',
radioButtons(
inputId = "interaction_heatmap_data_summary",
label = "Summarized by:",
choices = c("Sum","Median","Mean"),
selected="Sum"
)
)
),
#### ####
#### Options for interaction network ####
conditionalPanel(condition = 'input.int_plot_type == "select_network"',
pickerInput(
inputId = "interacNet_type_picker",
label = "Filter by Atom Interaction type:",
choices = as.character(atom_interaction_type$type),
selected = as.character(atom_interaction_type$type),
options = list(
'dropupAuto' = FALSE,
'actions-box' = TRUE,
size = 5
),
multiple = TRUE
),
sliderInput(
inputId = "interacNet_slider",
label = "Minimum number of interactions to show:",
min = 0, max = 50,
value = 0
)
)
#### ####
)
)
)
}
#### ####
#### Custom graphs page ####
custom_charts = function(){
fluidPage(
#### opts ####
theme = shinytheme("yeti"),
useShinyjs(),
#### ####
sidebarLayout(position = 'right',
sidebarPanel(width = 4,
h4("Plot options"),
#### Data Filter/Selection ####
selectInput("dataset","Data:",
list(Complexes = "complex", Chains = "chain", Interactions = "interaction")),
radioButtons("plot_mode",
"Number of Continuous Variables",
choices = c("One", "Two"),
inline = TRUE),
#### ####
uiOutput("variable"), # depends on dataset ( set by output$variable in server.R)
conditionalPanel(
condition = "input.plot_mode == 'Two'",
uiOutput("variable2")
),
uiOutput("group"), # depends on dataset ( set by output$group in server.R)
uiOutput("plot_type"),
radioButtons("dataset1",
"Data to show:",
choices = c("All", "Selected"),
inline = TRUE),
# Options for boxplot (Conditional)
conditionalPanel(condition = 'input.plot_type == "Box Plot"',
uiOutput("show_points")
)
),
#### Plot area ####
mainPanel(width = 8, tabBox(
title = "Explore the data",
id = "customplotBox",
width = 12,
tabPanel("Plot", withSpinner(plotlyOutput("cplot")))
))
#### ####
)
)
}
#### ####
#### Complex table page ####
complex_table_view = function(){
fluidPage(
#### Opts ####
theme = shinytheme("yeti"),
useShinyjs(),
#### ####
#### Table ####
fluidRow(
column(12,
#### Row on top - (options) ####
fixedRow(
column(12
,div(style="display:inline-block",downloadButton("downloadData", "Download",class = "btn btn-primary"))
,div(style="display:inline-block",dropdownButton(inputId = "columnsToShow", label = "Show columns",
circle = F, status = "primary",
selectizeInput("complex_tbl_columnSelection_by_complex", label = h5("PDB"), multiple = T, width = '100%',
choices = as.character(complex_tbl_dic[which(complex_tbl_dic$class=="Complex"),c("desc")]),
selected = "PDB"),
selectizeInput("complex_tbl_columnSelection_by_chain", label = h5("Chain"), multiple = T,
choices = as.character(complex_tbl_dic[which(complex_tbl_dic$class=="Chain"),c("desc")]),
selected = c("Chain Name (Heavy)","Chain Name (Light)","Chain Name (Antigen)")),
selectizeInput("complex_tbl_columnSelection_by_ss", label = h5("Secondary Structure"), multiple = T,
choices = as.character(complex_tbl_dic[which(complex_tbl_dic$class=="SS"),c("desc")]))
))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",actionButton("showComplexesForSelection","See complexes",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("showChainsForSelection","See chains",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("showInteractionsForSelection","See interactions",class = "btn btn-success"))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",dropdownButton(inputId = "complex_table_seegraphs", label = "Plot interactions",
circle = F, status = "warning", icon = icon("bar-chart-o"),
actionButton("select_antibodyresidue_by_position_barplot","Frequency of Antibody amino acids by IMGT position",class = "btn btn-warning",width = '100%'),
actionButton("select_atominteraction_residues_heatmap","Number of interactions by antibody-antigen residues",class = "btn btn-warning", width = '100%'),
actionButton("select_atominteraction_residues_network","Network",class = "btn btn-warning", width = '100%')))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block;text-align:right",dropdownButton(
tags$h4("Selection info"),
div(style="font-size: small;font-weight: normal",htmlOutput("selection_info_complexTableView")),hr(),
div(style="font-size: small;font-weight: normal",materialSwitch(inputId = "complex_selection_switch",label = "Show only selected entries", status = "primary", right = F)),
circle = TRUE, status = "info", icon = icon("info")
))
#,infoBox(title = div(style="font-size: small;font-weight: normal",htmlOutput("selection_info_complexTableView")),
# div(style="font-size: small;font-weight: normal",materialSwitch(inputId = "complex_selection_switch",label = "Show only selected entries", status = "primary", right = F)),
# icon = icon("info"), fill = T)
)
)
#### ####
,br(),
#### Table and filter sidebar ####
box(
title = "Complexes Explorer",
id = "complexExplorerBox",
collapsible = T,
width = 10,
withSpinner(dataTableOutput("tbl"))
),
box(
title = "Filter data by",
id = "dataFilterBox_Complex",
collapsible = T,
width = 2,
selectizeInput("filter_pdb", "PDB Id:",
choices = as.character(PdbList),
multiple = TRUE,
options = list(placeholder = 'All')),
selectizeInput("filter_experiment", "PDB Experiment:",
choices = as.character(ExperimentList),
multiple = TRUE,
options = list(placeholder = 'All')),
selectizeInput("filter_species", "Species:",
choices = as.character(SpeciesList),
multiple = TRUE,
options = list(placeholder = 'All')),
sliderInput("filter_resolution", "PDB Resolution",
min = min(complex_table$PDBResolution),
max = max(complex_table$PDBResolution),
value = c(min(complex_table$PDBResolution),
max(complex_table$PDBResolution))),
actionButton("select_all_button", "Select all", width = "100%"),
actionButton("deselect_all_button", "Deselect all", width = "100%"),
actionButton("reset_button", "Reset", width = "100%")
)
#### ####
)
)
)
}
#### ####
#### Chain table page ####
chain_table_view = function(){
fluidPage(
#### Opts ####
theme = shinytheme("yeti"),
useShinyjs(),
#### ####
#### Table ####
fluidRow(
column(12,
#### Row on top - (options) ####
fixedRow(
column(12
,div(style="display:inline-block",downloadButton("downloadData_chain", "Download",class = "btn btn-primary"))
,div(style="display:inline-block",dropdownButton(inputId = "chain_columnsToShow", label = "Show columns",
circle = F, status = "primary",
selectizeInput("chain_tbl_columnSelection_by_chain", label = h5("Chain"), multiple = T,
choices = as.character(chain_tbl_dic[which(chain_tbl_dic$class=="Chain"),c("desc")]),
selected = c("PDB","Chain Name","Chain Type","Chain Species")),
selectizeInput("chain_tbl_columnSelection_by_ss", label = h5("Secondary Structure"), multiple = T,
choices = as.character(chain_tbl_dic[which(chain_tbl_dic$class=="SS"),c("desc")]))
))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",actionButton("chain_showComplexesForSelection","See complexes",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("chain_showChainsForSelection","See chains",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("chain_showInteractionsForSelection","See interactions",class = "btn btn-success"))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",dropdownButton(inputId = "chain_table_seegraphs", label = "Plot interactions",
circle = F, status = "warning", icon = icon("bar-chart-o"),
actionButton("chain_select_antibodyresidue_by_position_barplot","Frequency of Antibody amino acids by IMGT position",class = "btn btn-warning",width = '100%'),
actionButton("chain_select_atominteraction_residues_heatmap","Number of interactions by antibody-antigen residues",class = "btn btn-warning", width = '100%'),
actionButton("chain_select_atominteraction_residues_network","Network",class = "btn btn-warning", width = '100%')))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block;text-align:right",dropdownButton(
tags$h4("Selection info"),
div(style="font-size: small;font-weight: normal",htmlOutput("selection_info_chainTableView")),hr(),
div(style="font-size: small;font-weight: normal",materialSwitch(inputId = "chain_selection_switch",label = "Show only selected entries", status = "primary", right = F)),
circle = TRUE, status = "info", icon = icon("info")
))
)
)
#### ####
,br(),
#### Table and filter sidebar ####
box(
title = "Chains Explorer",
id = "chainExplorerBox",
collapsible = T,
width = 10,
withSpinner(dataTableOutput("chain_tbl"))
),
box(
title = "Filter data by",
id = "dataFilterBox_Chain",
collapsible = T,
width = 2,
selectizeInput("chain_filter_pdb", "PDB Id:",
choices = as.character(PdbList),
multiple = TRUE,
options = list(placeholder = 'All')),
selectizeInput("chain_filter_species", "Species:",
choices = as.character(SpeciesList),
multiple = TRUE,
options = list(placeholder = 'All')),
actionButton("select_all_button_chain", "Select all", width = "100%"),
actionButton("deselect_all_button_chain", "Deselect all", width = "100%"),
actionButton("reset_button_chain", "Reset", width = "100%")
)
#### ####
)
)
)
}
#### ####
#### Interaction table page ####
interaction_table_view = function(){
fluidPage(
#### Opts ####
theme = shinytheme("yeti"),
useShinyjs(),
#### ####
#### Table ####
fluidRow(
column(12,
#### Row on top - (options) ####
fixedRow(
column(12,div(style="display:inline-block",downloadButton("downloadData_interaction", "Download",class = "btn btn-primary"))
,div(style="display:inline-block",dropdownButton(inputId = "interaction_columnsToShow", label = "Show columns",
circle = F, status = "primary",
selectizeInput("interaction_tbl_columnSelection_by_antibody", label = h5("Antibody"), multiple = T,
choices = as.character(interaction_tbl_dic[which(interaction_tbl_dic$class=="Antibody"),c("desc")]),
selected = c("Antibody Atom","Amino acid (Antibody)")),
selectizeInput("interaction_tbl_columnSelection_by_antigen", label = h5("Antigen"), multiple = T,
choices = as.character(interaction_tbl_dic[which(interaction_tbl_dic$class=="Antigen"),c("desc")]),
selected = c("Antigen Atom","Amino acid (Antigen)")),
selectizeInput("interaction_tbl_columnSelection_by_interaction", label = h5("Interaction"), multiple = T,
choices = as.character(interaction_tbl_dic[which(interaction_tbl_dic$class=="Interaction"),c("desc")]),
selected = c("Interaction Type","Interaction Distance"))
))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",actionButton("interaction_showComplexesForSelection","See complexes",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("interaction_showChainsForSelection","See chains",class = "btn btn-success"))
,div(style="display:inline-block",actionButton("interaction_showInteractionsForSelection","See interactions",class = "btn btn-success"))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block",dropdownButton(inputId = "interaction_table_seegraphs", label = "Plot interactions",
circle = F, status = "warning", icon = icon("bar-chart-o"),
actionButton("interaction_select_antibodyresidue_by_position_barplot","Frequency of Antibody amino acids by IMGT position",class = "btn btn-warning",width = '100%'),
actionButton("interaction_select_atominteraction_residues_heatmap","Number of interactions by antibody-antigen residues",class = "btn btn-warning", width = '100%'),
actionButton("interaction_select_atominteraction_residues_network","Network",class = "btn btn-warning", width = '100%')))
,div(style="display:inline-block",HTML("<span>|</span>"))
,div(style="display:inline-block;text-align:right",dropdownButton(
tags$h4("Selection info"),
div(style="font-size: small;font-weight: normal",htmlOutput("selection_info_interactionTableView")),hr(),
div(style="font-size: small;font-weight: normal",materialSwitch(inputId = "interaction_selection_switch",label = "Show only selected entries", status = "primary", right = F)),
circle = TRUE, status = "info", icon = icon("info")
))
)
)
#### ####
,br(),
#### Table ####
box(
title = "Interactions Explorer",
id = "interactionExplorerBox",
collapsible = T,
width = 10,
withSpinner(dataTableOutput("interaction_tbl"))
),
box(
title = "Filter data by",
id = "dataFilterBox_Interaction",
collapsible = T,
width = 2,
selectizeInput("interaction_filter_pdb", "PDB Id:",
choices = as.character(PdbList),
multiple = TRUE,
options = list(placeholder = 'All')),
selectizeInput("interaction_filter_species", "Species:",
choices = as.character(SpeciesList),
multiple = TRUE,
options = list(placeholder = 'All')),
actionButton("select_all_button_interaction", "Select all", width = "100%"),
actionButton("deselect_all_button_interaction", "Deselect all", width = "100%"),
actionButton("reset_button_interaction", "Reset", width = "100%")
)
#### ####
)
)
)
}
#### ####
#### Dashboard page layout parts ----
# Include: Header + Sidebars + Body
#### Header ####
header <- shinydashboardPlus::dashboardHeader(
title = "Ydb"
)
#### ####
#### Sidebar ####
sidebar <- shinydashboardPlus::dashboardSidebar(
tags$head(tags$style(type = "text/css", ".shiny-input-container {padding-top: 0px !important;padding-bottom: 0px !important;}")),
sidebarMenu(id = "menu",
menuItem("Home", tabName = "home", icon = icon("home")),
menuItem("Database explorer", tabName = "database", icon = icon("database"),
menuSubItem("by Complex", tabName = "complex"),
menuSubItem("by Chain", tabName = "chain"),
menuSubItem("by Interaction", tabName = "interaction")
),
menuItem("Visualization", tabName = "charts_menu", icon = icon("bar-chart-o"),
menuSubItem("Database Statistics", tabName = "dbstats_charts"),
menuSubItem("Interactions", tabName = "interaction_charts"),
menuSubItem("Custom Graphs", tabName = "custom_charts")
)
)
)
#### ####
#### Body ####
body <- dashboardBody(
tags$head(tags$style(HTML('.main-header .logo { font-size: 16px; }'))),
tabItems(
tabItem(tabName = "home",
home_page()
),
tabItem(tabName = "complex",
complex_table_view()
),
tabItem(tabName = "chain",
chain_table_view()
),
tabItem(tabName = "interaction",
interaction_table_view()
),
tabItem(tabName = "custom_charts",
custom_charts()
),
tabItem(tabName = "interaction_charts",
interaction_charts()
),
tabItem(tabName = "dbstats_charts",
dbstats_charts()
)
)
)
#### ####
#### Page call (main function) ----
shinydashboardPlus::dashboardPage(title = "Ydb",
header,
sidebar,
body)
}
###################################################################################
# Server logic ----
server <- function(input, output, session) {
# Automatically stop a Shiny app when closing the browser tab
session$onSessionEnded(stopApp)
# Set this to "force" instead of TRUE for testing locally (without Shiny Server)
session$allowReconnect("force")
session$allowReconnect(TRUE)
# Default definitions
columns_to_show_complex_table = c("Pdb","HeavyChainName", "LightChainName", "AntigenChainName")
columns_to_show_chain_table = c("Pdb","ChainName","ChainType","Species")
columns_to_show_interaction_table = c("AtomInteraction_AntibodyAtom","AntibodyResidue_AminoAcid",
"AtomInteraction_AntigenAtom","AntigenResidue_AminoAcid",
"AtomInteraction_Type","AtomInteraction_Distance")
#################################################################################
#### HOME: Selection Menus ######################################################
#################################################################################
output$all_pdb_checkbox_sel <- renderPrint({ input$all_pdb_checkbox })
#################################################################################
#### Selection Control ##########################################################
#################################################################################
# All tables (Complex, Chain and Interaction) can be connected in the background
# This permits selection and filtering across each other.
# The following codes are to control it programmatically.
#### Reactive values to store selected rows ####
# This is a reactiveValue: When you read a value from it,
# the calling reactive expression takes a reactive dependency on that value,
# and when you write to it,
# it notifies any reactive functions that depend on that value.
# For complex_table
selection_all <- reactiveValues(
all = data.frame( # This contains a data.frame with all rownames in table ('ID') and which one is selected ('sel')
ID = rownames(complex_table), # Using rownames as reference *depends on the MySQL select' output order
sel = rep(F,nrow(complex_table))
)
)
# For chain_table (same as above)
selection_all_chain <- reactiveValues(
all = data.frame(
ID = chain_table$Id, # Using the ChainID as reference
sel = rep(F,nrow(chain_table))
)
)
# interaction_table does not have this control
# it relies on the selection in the complex/chain tables
#### ####
#### Currently selected dataset ####
curSelectedData_complex_table <- reactive({
# See what is selected
rows_selected = which(selection_all$all$sel==T)
if (length(rows_selected)==0){ # If nothing has been selected show all entries
table_selected = complex_table
}else{ # If something has been selected, show only selection
table_selected = complex_table[rows_selected,]
}
#switch(input$dataset1, All = complex_table, Selected = table_selected)
})
#### ####
#### Currently selected dataset ####
curSelectedData_chain_table <- reactive({
# See what is selected
rows_selected = which(selection_all_chain$all$sel==T)
if (length(rows_selected)==0){ # If nothing has been selected show all entries
table_selected = chain_table
}else{ # If something has been selected, show only selection
table_selected = chain_table[rows_selected,]
}
#switch(input$dataset1, All = chain_table, Selected = table_selected)
})
#### ####
#### Observer for selected rows ####
# For complex_table
observeEvent(input$tbl_cell_clicked$row,{
# This controls case a diferent data is being shown (e.g. after filtering)
data = curFilteredData_complex_table()
a_sel <- isolate(selection_all$all$sel[selection_all$all$ID %in% rownames(data)]) # Get what is already selected given the current data
a <- data.frame(IDs = rownames(data), sel = a_sel) # Temporary data.frame with selections for the current data
# Control of click (selection) on the current table
if (is.null(input$tbl_cell_clicked$row)) {
a[, 'sel'] <- F
return()
}
if (isTRUE(a[input$tbl_cell_clicked$row, 'sel'])){ # If complex was already selected. Deselect it.
a[input$tbl_cell_clicked$row, 'sel'] <- F
# Update values in the complete version of table
selection_all$all$sel[selection_all$all$ID %in% a$IDs] <- a$sel
# Update values for chains and interactions as well...
complex_rows_deselected = a[input$tbl_cell_clicked$row, 'IDs'] # Deselected complex
chain_ids = complex_table[which(rownames(complex_table)==complex_rows_deselected),c("HeavyChainId","LightChainId","AntigenChainId")] # Look chain ids in the complex table
selection_all_chain$all$sel[selection_all_chain$all$ID %in% chain_ids] <- F # Deselected chains related to complexes
return()
}
if (!isTRUE(a[input$tbl_cell_clicked$row, 'sel'])){
a[input$tbl_cell_clicked$row, 'sel'] <- T
# Update values in the complete version of table
selection_all$all$sel[selection_all$all$ID %in% a$IDs] <- a$sel
# Update values for chains and interactions as well...
complex_rows_selected = isolate(which(selection_all$all$sel==T)) # Get a list of selected complexes
chain_ids = complex_table[complex_rows_selected,c("HeavyChainId","LightChainId","AntigenChainId")] # Look chain ids in the complex table
chain_ids = chain_ids[!is.na(chain_ids)] # Remove NA entries
selection_all_chain$all$sel[selection_all_chain$all$ID %in% chain_ids] <- T # Set selected for chains related to complexes
return()
}
}, ignoreNULL = TRUE)
# For chain_table
observeEvent(input$chain_tbl_cell_clicked$row,{
# This controls case a diferent data is being shown (e.g. after filtering)
data = curFilteredData_chain_table()
a_sel <- isolate(selection_all_chain$all$sel[selection_all_chain$all$ID %in% data$Id])
a <- data.frame(IDs = data$Id, sel = a_sel)
if (is.null(input$chain_tbl_cell_clicked$row)) {
a[, 'sel'] <- F
} else if (isTRUE(a[input$chain_tbl_cell_clicked$row, 'sel'])){
a[input$chain_tbl_cell_clicked$row, 'sel'] <- F
} else if (!isTRUE(a[input$chain_tbl_cell_clicked$row, 'sel'])){
a[input$chain_tbl_cell_clicked$row, 'sel'] <- T
}
selection_all_chain$all$sel[selection_all_chain$all$ID %in% a$IDs] <- a$sel
}, ignoreNULL = TRUE)
#### ####
#### To be removed : Notification - Selected ####
#output$notif <- renderMenu({
# ids = which(selection_all$all$sel==T)
# nids = length(ids)
# chain_ids = selection_all_chain$all$ID[which(selection_all_chain$all$sel==T)]
# nchains = length(chain_ids)
# # If some chain was selected, count interactions
# if (nchains==0){
# ninteractions = 0
# }else{
# data <- interaction_table_by_chainid(chain_ids)
# ninteractions = nrow(data)
# }
# # Notification
# if (nids==1){
# dropdownMenu(type = "notifications",
# icon = icon("shopping-cart", lib = "glyphicon"),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(nids,'complex selected')
# ),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(nchains,'chains selected')
# ),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(ninteractions,'interactions selected')
# )
# )
# }else{
# if (nids>1){
# dropdownMenu(type = "notifications",
# icon = icon("shopping-cart", lib = "glyphicon"),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(nids,'complexes selected')
# ),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(nchains,'chains selected')
# ),
# notificationItem(icon = icon("ok", lib = "glyphicon"), status = "danger",
# paste(ninteractions,'interactions selected')
# )
# )
# }else{
# dropdownMenu(type = "notifications",
# icon = icon("shopping-cart", lib = "glyphicon"))
# }
# }
#})
#### ####
#### observer of select all button ####
# complex_table
observeEvent(input$select_all_button, {
data <- curFilteredData_complex_table()
a_sel <- selection_all$all$sel[selection_all$all$ID %in% rownames(data)]
a <- data.frame(IDs = rownames(data), sel = a_sel)
a[input$tbl_rows_all, 'sel'] <- T
selection_all$all$sel[selection_all$all$ID %in% a$IDs] <- a$sel
# Update values for chains and interactions as well...
complex_rows_selected = isolate(which(selection_all$all$sel==T)) # Get a list of selected complexes
chain_ids = complex_table[complex_rows_selected,c("HeavyChainId","LightChainId","AntigenChainId")] # Look chain ids in the complex table
chain_ids = chain_ids[!is.na(chain_ids)] # Remove NA entries
selection_all_chain$all$sel[selection_all_chain$all$ID %in% chain_ids] <- T # Set selected for chains related to complexes
})
# chain_table
observeEvent(input$select_all_button_chain, {
data <- curFilteredData_chain_table()
a_sel <- selection_all_chain$all$sel[selection_all_chain$all$ID %in% data$Id]
a <- data.frame(IDs = data$Id, sel = a_sel)
a[input$chain_tbl_rows_all, 'sel'] <- T
selection_all_chain$all$sel[selection_all_chain$all$ID %in% a$IDs] <- a$sel
})
# interaction_table
observeEvent(input$select_all_button_interaction, {
data <- curFilteredData_interaction_table()
a_sel <- selection_all_interaction$all$sel[selection_all_interaction$all$ID %in% rownames(data)]
a <- data.frame(IDs = rownames(data), sel = a_sel)
a[input$interaction_tbl_rows_all, 'sel'] <- T
selection_all_interaction$all$sel[selection_all_interaction$all$ID %in% a$IDs] <- a$sel
})
#### ####
#### observer of deselect all button ####
# complex_table
observeEvent(input$deselect_all_button, {
data <- curFilteredData_complex_table()
a_sel <- selection_all$all$sel[selection_all$all$ID %in% rownames(data)]
a <- data.frame(IDs = rownames(data), sel = a_sel)
a[input$tbl_rows_all, 'sel'] <- F
selection_all$all$sel[selection_all$all$ID %in% a$IDs] <- a$sel
# Update values for chains and interactions as well...
complex_rows_deselected = a[input$tbl_cell_clicked$row, 'IDs'] # Deselected complex
chain_ids = complex_table[which(rownames(complex_table)==complex_rows_deselected),c("HeavyChainId","LightChainId","AntigenChainId")] # Look chain ids in the complex table
selection_all_chain$all$sel[selection_all_chain$all$ID %in% chain_ids] <- F # Deselected chains related to complexes
})
# chain_table
observeEvent(input$deselect_all_button_chain, {
data <- curFilteredData_chain_table()
a_sel <- selection_all_chain$all$sel[selection_all_chain$all$ID %in% data$Id]
a <- data.frame(IDs = data$Id, sel = a_sel)
a[input$chain_tbl_rows_all, 'sel'] <- F
selection_all_chain$all$sel[selection_all_chain$all$ID %in% a$IDs] <- a$sel
})
# interaction_table
#observeEvent(input$deselect_all_button_interaction, {
# data <- curFilteredData_interaction_table()
# a_sel <- selection_all_interaction$all$sel[selection_all_interaction$all$ID %in% rownames(data)]
# a <- data.frame(IDs = rownames(data), sel = a_sel)
# a[input$interaction_tbl_rows_all, 'sel'] <- F
# selection_all_interaction$all$sel[selection_all_interaction$all$ID %in% a$IDs] <- a$sel
#})
#### ####
#################################################################################
#### Filtering Control ##########################################################
#################################################################################
# Each table webpage has it own filtering options
#### Current dataset (controls data after filtering) ####
# For complex_table
curFilteredData_complex_table <- reactive({
data = complex_table # Table is already loaded (from global.R)
# Filter by PDB
if (is.null(input$filter_pdb)){
data <- data
} else if (any(input$filter_pdb != "")){
data <- data[which(data$Pdb %in% input$filter_pdb),]
}
# Filter by PDB Experiment
if (is.null(input$filter_experiment)){
data <- data
} else if (any(input$filter_experiment != "")){
data <- data[which(data$PDBExperiment%in%input$filter_experiment),]
}
# Filter by PDB Resolution
if (is.null(input$filter_resolution)){
data <- data
} else if (any(input$filter_resolution != "")){
min_range = min(input$filter_resolution)
max_range = max(input$filter_resolution)
filt_idx = which(data$PDBResolution >= min_range & data$PDBResolution <= max_range)
data = data[filt_idx,]
}
# Filter by Species
if (is.null(input$filter_species)){
data <- data
} else if (any(input$filter_species != "")){
data = data[which(data$HeavySpecies%in%input$filter_species | data$LightSpecies%in%input$filter_species | data$AntigenSpecies%in%input$filter_species),]
}
return(data)
})
# For chain_table
curFilteredData_chain_table <- reactive({
data = chain_table # Table is already loaded (from global.R)
# Filter by PDB
if (is.null(input$chain_filter_pdb)){
data <- data
} else if (any(input$chain_filter_pdb != "")){
data <- data[which(data$Pdb%in%input$chain_filter_pdb),]
}
# Filter by Species
if (is.null(input$chain_filter_species)){
data <- data
} else if (any(input$chain_filter_species != "")){
data = data[which(data$Species%in%input$chain_filter_species),]
}
return(data)
})
# For interaction_table
curFilteredData_interaction_table <- reactive({
# The full interaction_table is huge. So, by default we only load interactions related to user-selected chains.
# So, depending on user selection, interaction_table is loaded directly from the MySQL database (using function interaction_table_by_chainid)
#chain_ids = which(selection_all_chain$all$sel==T)
#cat(chain_ids)
#data <- ifelse (length(chain_ids)==0,
# interaction_table_show_all(), # If none chain is selected, select the complete table (slow)
# interaction_table_by_chainid(chain_ids[!is.na(chain_ids)]))
data = interaction_table
# Filter by PDB
if (is.null(input$interaction_filter_pdb)){
data <- data
} else if (any(input$interaction_filter_pdb != "")){
data <- data[which(data$Pdb%in%input$interaction_filter_pdb),]
}
# Filter by Species
if (is.null(input$interaction_filter_species)){
data <- data
} else if (any(input$interaction_filter_species != "")){
data = data[which(data$Species%in%input$interaction_filter_species),]
}
})
#### ####
#### Reset filtering button ####
# complex_table
observeEvent(input$reset_button, {
shinyjs::reset("filter_pdb")
shinyjs::reset("filter_experiment")
shinyjs::reset("filter_resolution")
shinyjs::reset("filter_species")
})
# chain_table
observeEvent(input$reset_button_chain, {
shinyjs::reset("chain_filter_pdb")
shinyjs::reset("chain_filter_species")
})
# interaction_table
observeEvent(input$reset_button_interaction, {
shinyjs::reset("interaction_filter_pdb")
shinyjs::reset("interaction_filter_species")
})
#### ####
#################################################################################
#### TABLE: Complex #############################################################
#################################################################################
#### Render the table containing shiny inputs ####
output$tbl = DT::renderDataTable({
# Get current data
data <- curFilteredData_complex_table()
# Switch to show only selected entries
if (input$complex_selection_switch){
data <- data[which(selection_all$all$sel==T),]
}else{
data <- data
}
# Selected entries
selected_ids = which(rownames(data)%in%which(selection_all$all$sel==T))
# Convert by pretty colnames
colnames(data)=complex_tbl_dic$desc
# Columns to show
by_complex = as.character(unlist(input$complex_tbl_columnSelection_by_complex))
by_chain = as.character(unlist(input$complex_tbl_columnSelection_by_chain))
by_ss = as.character(unlist(input$complex_tbl_columnSelection_by_ss))
data = data[,c(by_complex,by_chain,by_ss)]
# The table
datatable(data,
style = 'bootstrap',
rownames= FALSE,
selection = list(mode = "multiple", target= 'row',
selected = selected_ids),
options = list(
pageLength = 10,
scrollX = TRUE,
deferRender = TRUE
)
)
}, server = T)
#### ####
#### Downloadable csv of selected dataset ####
output$downloadData <- downloadHandler(
filename = function() {
paste("ComplexesTable", ".csv", sep = "")
},
content = function(file) {
write.csv(curFilteredData_complex_table(), file, row.names = FALSE)