-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
1900 lines (1625 loc) · 84 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
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
# setwd("C:/Users/User/Documents/rowwisenorm_shiny")
# command line argument: 'local' can be set to include manual download options
# run in terminal: Rscript app.R local
# -> open link, stop with ctrl c
library(shiny)
library(rowwisenorm) # make available
library(pheatmap)
library(edgeR) # for VST
library(lumi) # for VSN
library(preprocessCore) # for Quantile normalization
library(sva) # for ComBat
library(shinyjs) # to handle command line parameter
# setting upload size to 100 MB max
options(shiny.maxRequestSize=100*1024^2)
# Define UI for application that draws a histogram
ui <- fluidPage(
useShinyjs(), # used to handle command line parameter
# graphic adjustment
tags$head(
tags$style(HTML("hr {border-top: 1px solid #000000;}")), # horizontal line thicker
),
# colors & line spacing of warnings/ errors inside notifications
tags$head(tags$style("#reading_warning{color: orange; margin-bottom: 20px;")),
tags$head(tags$style("#reading_error{color: red; margin-bottom: 20px;}")),
tags$head(tags$style("#normalize_row_warning{color: red; margin-bottom: 20px;}")),
tags$head(tags$style("#datafile_error{color: red; margin-bottom: 20px;}")),
tags$head(tags$style("#designfile_error{color: red; margin-bottom: 20px;}")),
# colors & line spacing of notifications of colors, symbols, M-ComBat center
tags$head(tags$style("#batch_colors_manually_notification{color: darkblue; margin-bottom: 20px;}")),
tags$head(tags$style("#condition_symbols_manually_notification{color: darkblue; margin-bottom: 20px;}")),
tags$head(tags$style("#m.combat_notification{color: darkblue; margin-bottom: 20px;}")),
# color and thickness of lines subtitles
tags$style(HTML(".title-hr {
background-color: rgba(0, 0, 139, 0.5); /* Transparent dark blue color */
height: 1.3px; /* Adjust thickness here */
}")),
# text style for PCA score titles and scores
tags$style("#score_title_raw{color: darkblue;
font-size: 14px;
font-weight: bold;}"),
tags$style("#score_title_raw_pre{color: darkblue;
font-size: 14px;
font-weight: bold;}"),
tags$style("#score_title_norm{color: darkblue;
font-size: 14px;
font-weight: bold;}"),
tags$style("#score_raw{color: black;
font-size: 16px;
font-weight: bold;}"),
tags$style("#score_raw_pre{color: black;
font-size: 16px;
font-weight: bold;}"),
tags$style("#score_norm{color: black;
font-size: 16px;
font-weight: bold;}"),
# color for feature finding checkboxes
tags$style(HTML("#onlyBySiteCheckbox { color: green;}")),
tags$style(HTML("#reverseCheckbox { color: green; }")),
tags$style(HTML("#contaminantCheckbox { color: green; }")),
# background
# tags$style(HTML('
# body {
# background: linear-gradient(135deg, rgba(135, 206, 235, 0.3), rgba(0, 191, 255, 0.6), rgba(30, 144, 255, 0.6), rgba(173, 216, 230, 0.6), rgba(135, 206, 235, 0.4));
# background-size: 200% 200%; /* Increase the size to make the background fit the whole window */
# }
# ')),
# bright grey, dark grey tabs:
# tags$style(HTML('
# body {
# background: #f5f5f5; /* Light gray background */
# }
# .navbar {
# background: #ccc; /* Subtle accent color for the navigation bar */
# }
# .nav-tabs li a {
# background: #ccc; /* Subtle accent color for tab headers */
# }
# .nav-tabs li.active a {
# background: #bbb; /* Slightly darker accent for the active tab */
# }
# .column { /* can be set as class ="column" into specific elements */
# background: #e0e0e0; /* Light tint for column backgrounds */
# border: 1px solid #ddd; /* Delicate gray border */
# }
# ')),
# same green:
# tags$style(HTML('
# body {
# background: #e6ffcc; /* Very bright pastel green for the general background */
# }
# .navbar {
# background: #ccff99; /* Slightly darker but still light green for the navigation bar */
# }
# .nav-tabs li a {
# background: #ccff99; /* Slightly darker but still light green for tab headers */
# }
# .nav-tabs li.active a {
# background: #aaff66; /* Slightly darker but still light green for the active tab */
# }
# .column {
# background: #e0e0e0; /* Light tint for column backgrounds */
# border: 1px solid #ddd; /* Delicate gray border */
# }
# ')),
# overall appearance
tags$style(HTML('
body {
background: rgba(204, 229, 255, 0.7); /* Blue transparent general background */
}
.navbar {
background: #99ccff; /* Slightly darker but still light blue for the navigation bar */
}
.nav-tabs {
border-bottom: 3px solid #66aaff; /* border between tab bar and content */
}
.nav-tabs li a {
background: #99ccff; /* tab headers */
}
.nav-tabs li.active a {
background: #66aaff; /* active tab */
}
table {
border: 2px solid #00008B; /* Dark blue border for the table */
}
th, td {
border: 1px solid #00008B; /* Dark blue border for table headers and data cells */
}
table thead th {
border: 1px solid #00008B; /* Dark blue border for lines between headers and data cells */
}
.fancy-title { /* design for the title */
font-family: "Arial Black", Gadget, sans-serif; /* Custom font */
font-size: 30px; /* Custom font size */
color: #E5E8E8; /* Text color */
background-color: #284D8E; /* Background color */
padding: 10px 20px; /* Padding to style the title area */
border-radius: 8px; /* Rounded corners */
}
.column {
background: #e0e0e0; /* Light tint for column backgrounds */
border: 1px solid #ddd; /* Delicate gray border */
}
')),
# fixed position of the title tab titles, and fixed width of view plots
tags$head(
tags$style(
HTML("
.fixed-height { /* used for first two tabs height */
height: 80vh; /* set height as 80% viewerport height (adjusted to the window) */
overflow-y: auto;
overflow-x: hidden; /* no horizontal scroll */
}
.fixed-height-width { /* used for third tab height and width */
height: 80vh; /* set height as 80% viewerport height (adjusted to the window) */
width: 1500px; /* fixed width */
overflow-y: auto;
overflow-x: hidden;
}
/* fix the position of the title */
.fixed-title {
position: sticky;
top: 0;
z-index: 1000; /* ensure that title stays on top */
}
")
)
),
# widths of view plots columns
tags$style(HTML(".view-plots-column { width: 500px; }")),
# Application title - fixed on top of app
div(class = "fixed-title",
titlePanel(
div(class = "fancy-title", "Omics Data Normalization"),
windowTitle = "Omics Data Normalization"
),
),
# part the ui in three parts
tabsetPanel(
# left tab
tabPanel("Input and Settings",
div(class = "fixed-height",
# fluid row for the numbers 1 to 3
fluidRow(
style = "margin-top: 10px;", # Add margin to the top of the fluidRow #284D8E
column(4, align = "center",
div(
style = "border: 3px solid #284D8E; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; background-color: rgba(0, 0, 139, 0.4);",
h2(
"1",
style = "line-height: 50px; margin: 0; color: white;"
)
)
), # First column with the number 1 inside a circle
column(4, align = "center",
div(
style = "border: 3px solid #284D8E; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; background-color: rgba(0, 0, 139, 0.4);",
h2(
"2",
style = "line-height: 50px; margin: 0; color: white;"
)
)
), # Second column with the number 2 inside a circle
column(4, align = "center",
div(
style = "border: 3px solid #284D8E; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; background-color: rgba(0, 0, 139, 0.4);",
h2(
"3",
style = "line-height: 50px; margin: 0; color: white;"
)
)
) # Third column with the number 3 inside a circle
),
fluidRow(
# left
column(4,
div(
h3("Data", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# upload files
fileInput(inputId = "data", label = "Upload your data",
accept = c(".csv, .tsv, .txt", "text/*")),
textOutput("file_name_data"),
fileInput(inputId = "exp_design", label = "Upload the experimental design for your data",
accept = c(".csv, .tsv, .txt", "text/*")),
textOutput("file_name_exp_design"),
),
# middle
column(4,
div(
h3("Settings", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"),
# choose method
div(
h3("Normalization Method", style = "font-size: 17px; font-weight:550;"),
class = "title-div"
),
hr(),
selectInput(inputId = "method", label = "Method",
choices = c("row-wise-normalization" = "row-wise-normalization",
"total-sum" = "total-sum", "VST" = "VST", "VSN" = "VSN",
"quantile-normalization" = "quantile-normalization",
"ComBat" = "ComBat", "M-ComBat" = "M-ComBat")),
textOutput("selected_method"),
# Preprocessing possible for all methods: - but log2 not for VST allowed (no negative values allowed)
div(
h3("Preprocessing", style = "font-size: 17px; font-weight:550;"),
class = "title-div"
),
hr(), # horizontal line
# filtering of features - only show a checkbox if feature is available in data
textOutput("feature_note"),
actionButton("generate_features", "Find Features", icon = icon("search")),
# status output with space above
uiOutput("generate_features_status", style = "margin-top: 20px;"),
uiOutput("feature_text"),
uiOutput("onlyBySiteCheckbox"),
uiOutput("reverseCheckbox"),
uiOutput("contaminantCheckbox"),
# log2
conditionalPanel(
condition = "input.method != 'VST' ",
checkboxInput(inputId = "log2_t", label = "Logarithmic transformation", value = TRUE),
textOutput("log2_transform"),
),
# filter_rows
checkboxInput(inputId = "filterrows", label = "Filter out rows", value = FALSE),
conditionalPanel(
condition = "input.filterrows == true",
#textInput(inputId = "filterrowsratio", label = "Optionally: Your desired ratio of valid values per row as a decimal between 0 and 1:", placeholder = "Default: 0.5"),
sliderInput(inputId = "filterrowsratio", label = "Your desired ratio of valid values per row:", min=0, max=1, value = 0.5, step = 0.01),
textOutput("filterrows_note"),
),
# sum normalize
conditionalPanel(
condition = "input.method != 'total-sum' ",
checkboxInput(inputId = "sum_norm", label = "Sum normalize", value = FALSE),
textOutput("sum_normal"),
),
# parameter for sum normalize - same IDs as for total sum since this preprocessing appears for all methods without total sum
conditionalPanel(
condition = "input.sum_norm & input.method != 'total-sum' ", # important: set off for method total-sum (otherwise, when clicked at a different method it still appears)
# refFunc
selectInput(inputId = "refFunc_sum", label = "Select the reference Function", choices = c("sum" = "sum", "median" = "median")),
# norm
checkboxInput(inputId = "norm_sum", label = "Normalize the total sum", value = TRUE),
# na.rm - this ID only here (needs to work for all methods, the other na_rm is used for total sum and row wise in specific setups)
checkboxInput(inputId = "na_rm_sum", label = "Exclude NA values inside reference function", value = TRUE),
),
# median normalize
checkboxInput(inputId = "median_norm", label = "Median normalize", value = FALSE),
### Setups for specific methods: - only for row-wise, total sum, and M-Combat
conditionalPanel(
condition = "input.method == 'row-wise-normalization' || input.method == 'total-sum' || input.method == 'M-ComBat' ",
div(
h3("Method-Specific Setups", style = "font-size: 17px; font-weight:550;"),
class = "title-div"
),
hr(), # horizontal line
),
# active mode - only for row-wise
conditionalPanel(
condition = "input.method == 'row-wise-normalization' ",
checkboxInput(inputId = "active_mode", label = "Manually setting reference channels", value = FALSE),
),
# if active is set: input of references - this input is later used for ref parameter
conditionalPanel(
condition = "input.active_mode == true & input.method == 'row-wise-normalization' ", # important: set only for row-wise (otherwise, when clicked at a different method it still appears)
textInput(inputId = "refs", label = "Please enter the condition names of the references, separated by a comma:"),
textOutput("possible_refs_note"),
),
# na.rm - only for row-wise and total-sum
conditionalPanel(
condition = "input.method == 'row-wise-normalization' || input.method == 'total-sum' ",
checkboxInput(inputId = "na_rm", label = "Exclude NA values inside reference function", value = TRUE),
),
# refFunc - only for row-wise (because other default)
conditionalPanel(
condition = "input.method == 'row-wise-normalization' ",
selectInput(inputId = "refFunc", label = "Select the reference Function", choices = c("median" = "median", "sum" = "sum")),
),
# specific parameters for total sum - only for total-sum
conditionalPanel(
condition = "input.method == 'total-sum' ",
# refFunc
selectInput(inputId = "refFunc_sum", label = "Select the reference Function", choices = c("sum" = "sum", "median" = "median")),
# norm
checkboxInput(inputId = "norm_sum", label = "Normalize the total sum", value = TRUE),
# na.rm - use the same as for row-wise
# checkboxInput(inputId = "na_rm_sum", label = "Remove NA values", value = TRUE),
),
# parameter center for M-ComBat
conditionalPanel(
condition = "input.method == 'M-ComBat' ",
numericInput("m.combat_center", label = "Center at this batch number:", value = 1, step = 1, min = 1),
textOutput("m.combat_center_note")
),
### Graphical adjustment
div(
h3("Plot Adjustment", style = "font-size: 17px; font-weight:550;"),
class = "title-div"
),
hr(),
# batch colors
selectInput("batch_colors_manually", "Optionally: Select colors to be used for the batches inside the PCA plots and the heatmaps",
choices = colors(), multiple = TRUE),
textOutput("batch_colors_manually_note"),
br(),
# condition symbols
selectInput("condition_symbols_manually", "Optionally: Select symbols to be used for the conditions inside the PCA plots",
choices = 0:18, multiple = TRUE),
textOutput("condition_symbols_manually_note"),
plotOutput("pca_symbols_plot", height = "200px", width = "60%"), # adjusted size
br(),
),
# right
column(4,
# process button
div(
h2("Start calculation", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"),
textOutput("process_note"),
actionButton("process", label = "Process", icon = icon("refresh")),
# status output with space above
uiOutput("process_status", style = "margin-top: 20px; font-size:15px"),
# Notifications (warning and error messages)
div(
h2("Notifications", style = "font-size: 17px; font-weight:550; color:darkblue"),
class = "title-div"
),
tags$hr(style="border-color: darkblue;"), # horizontal line
textOutput("reading_error"), # handle stop() call inside reading
textOutput("reading_warning"), # handle warning() inside reading
textOutput("normalize_row_warning"), # not valid reference entered
textOutput("datafile_error"),
textOutput("designfile_error"),
# notifications for PCA colors, symbols, and M-ComBat center
textOutput("batch_colors_manually_notification"),
textOutput("condition_symbols_manually_notification"),
uiOutput("m.combat_notification"), # ui so that color can be set inside renderUI in server
),
),
),
),
# middle tab
tabPanel("Download Results",
div(class = "fixed-height",
fluidRow(
# left
column(6,
# show normalized data
div(
h3("Preview Normalized Data", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# choice which rows to be shown
numericInput("start_row", "Row to start:", value = 1, step = 1),
numericInput("end_row", "Row to end:", value = 5, step = 1),
# button for showing data
actionButton(inputId = "show_data", label = "Show normalized data"),
div(style = "height: 20px;"), # Add 20px of space
# display data as a table, fill available space without overlapping right column
div(style = "max-width: 100%; max-height: 300px; overflow-x: auto;", tableOutput("data_output")),
textOutput("show_data_note")
),
# right
column(6,
# download
div(
h3("Write Into File", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# download button for outfile lowest-level
downloadButton("download_outfile", "Download Data on Lowest Level"),
# download button for outfile with additional columns
downloadButton("download_outfile_comp", "Download Data Complete"),
# only for local mode: download outfile - manually
div(
id = "local-content-1",
checkboxInput(inputId = "writeoutfile", div(icon("star"), "Manually: Download normalized data"), value = FALSE),
textOutput("writeout"),
conditionalPanel(
condition = "input.writeoutfile == true",
textInput(inputId = "filename_outfile", label = "Optionally: Your desired file name:"),
textInput(inputId = "dir_outfile", label = "Optionally: Your desired directory path:", placeholder = "current working directory"),
selectInput(inputId = "outfile_level", label = "Level of complexity",
choices = c("lowest-level" = "lowest-level", "all-columns" = "all-columns")),
actionButton(inputId = "save_outfile", label = "Submit"),
verbatimTextOutput("outfile_path")
),
),
div(
h3("Download Plots", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# show labels parameter for PCA labels
checkboxInput(inputId = "show_labels", label = "Show labels inside PCA plot", value = FALSE),
# svg parameter
checkboxInput(inputId = "svg", label = "Additionally create SVG files", value = FALSE),
# download button for PDF (and svg) raw
downloadButton("download_pdf_raw", "Download Plots Raw Data"),
# download button for PDF (and svg) raw pre-processed
downloadButton("download_pdf_raw_pre", "Download Plots Raw Data Pre-Processed"),
# download button for PDF (and svg) normalized
downloadButton("download_pdf_norm", "Download Plots Normalized Data"),
# only for local mode: manual downloads
div(
id = "local-content-2",
# download plots raw - manually
checkboxInput(inputId = "save_plots_raw", div(icon("star"), "Manually: Save plots for raw data"), value = FALSE),
textOutput("saving_plots_raw"),
conditionalPanel(
condition = "input.save_plots_raw == true",
textInput(inputId = "filename_raw", label = "Optionally: Your desired file name and plot title:"),
textInput(inputId = "dir_raw", label = "Optionally: Your desired directory path:", placeholder = "current working directory"),
actionButton(inputId = "save_pdf_raw", label = "Submit"),
verbatimTextOutput("pdf_path_raw")
),
# download plots raw pre-processed - manually
checkboxInput(inputId = "save_plots_raw_pre", div(icon("star"), "Manually: Save plots for raw data pre-processed"), value = FALSE),
textOutput("saving_plots_raw_pre"),
conditionalPanel(
condition = "input.save_plots_raw_pre == true",
textInput(inputId = "filename_raw_pre", label = "Optionally: Your desired file name and plot title:"),
textInput(inputId = "dir_raw_pre", label = "Optionally: Your desired directory path:", placeholder = "current working directory"),
actionButton(inputId = "save_pdf_raw_pre", label = "Submit"),
verbatimTextOutput("pdf_path_raw_pre")
),
# download plots normalized - manually
checkboxInput(inputId = "save_plots_norm", div(icon("star"), "Manually: Save plots for normalized data"), value = FALSE),
textOutput("saving_plots_norm"),
conditionalPanel(
condition = "input.save_plots_norm == true",
textInput(inputId = "filename_norm", label = "Optionally: Your desired file name and plot title:"),
textInput(inputId = "dir_norm", label = "Optionally: Your desired directory path:", placeholder = "current working directory"),
actionButton(inputId = "save_pdf_norm", label = "Submit"),
verbatimTextOutput("pdf_path_norm")
),
),
)
),
),
),
# right tab
tabPanel("View Plots",
div(class = "fixed-height-width",
fluidRow(
# note: both column widths as 6 instead 4 makes them fill the whole space of page, but plots have not correct height:width ratio then
# left - raw
column(4, class = "view-plots-column",
div(
h3("Plots of Raw Data", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# show labels parameter for PCA labels
checkboxInput(inputId = "show_labels_raw", label = "Show labels inside PCA plot", value = FALSE),
# button for showing plots raw data
actionButton(inputId = "show_plots_raw", label = "Show plots of raw data"),
div(style = "height: 20px;"), # Add 20px of space
textOutput("score_title_raw"),
textOutput("score_raw"),
br(),
plotOutput("plot1_raw"),
br(),
plotOutput("plot2_raw"),
br(),
plotOutput("plot3_raw"),
br(),
plotOutput("plot4_raw"),
br(),
),
# middle - raw pre-processed
column(4, class = "view-plots-column",
div(
h3("Plots of Raw Data Pre-Processed", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# show labels parameter for PCA labels
checkboxInput(inputId = "show_labels_raw_pre", label = "Show labels inside PCA plot", value = FALSE),
# button for showing plots raw data pre-processed
actionButton(inputId = "show_plots_raw_pre", label = "Show plots of raw data pre-processed"),
div(style = "height: 20px;"), # Add 20px of space
textOutput("score_title_raw_pre"),
textOutput("score_raw_pre"),
br(),
plotOutput("plot1_raw_pre"),
br(),
plotOutput("plot2_raw_pre"),
br(),
plotOutput("plot3_raw_pre"),
br(),
plotOutput("plot4_raw_pre"),
br(),
),
# right - normalized
column(4, class = "view-plots-column",
div(
h3("Plots of Normalized Data", style = "font-size: 20px; font-weight:750; color: darkblue;"),
class = "title-div"
),
hr(class = "title-hr"), # horizontal line
# show labels parameter for PCA labels
checkboxInput(inputId = "show_labels_norm", label = "Show labels inside PCA plot", value = FALSE),
# button for showing plots normalized
actionButton(inputId = "show_plots_norm", label = "Show plots of normalized data"),
div(style = "height: 20px;"), # Add 20px of space
textOutput("score_title_norm"),
textOutput("score_norm"),
br(),
plotOutput("plot1_norm"),
br(),
plotOutput("plot2_norm"),
br(),
plotOutput("plot3_norm"),
br(),
plotOutput("plot4_norm"),
br(),
),
),
),
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
# command line argument: 'local' can be set to include manual download options
args <- commandArgs(trailingOnly = TRUE)
is_local <- "local" %in% args
is_local_reactive <- reactive(is_local)
# watch if local is set, if so, show the additional content
observe({
if (is_local_reactive()) {
shinyjs::show("local-content-1") # Show content 1
shinyjs::show("local-content-2") # Show content 2
} else {
shinyjs::hide("local-content-1") # Hide content 1
shinyjs::hide("local-content-2") # Hide content 2
}
})
# initialize global variables - inside server makes them session specific
lowest_level_df <- data.frame() # data frame coming from reading function
exp_design <- data.frame()
additional_cols <- data.frame()
lowest_level_norm <- data.frame()
lowest_level_df_raw <- data.frame() # raw data without any modification (no features filtered)
lowest_level_df_pre <- data.frame() # raw data pre-processed (pre-processed lowest_level_df)
pca_colors <- c()
pca_symbols <- c()
max_choices_batches <- 1
max_choices_conds <- 1
output$selected_method <- renderText({
paste("Your selected method:", input$method)
})
output$process_note <- renderText({
"Click the button to load the data, update the settings, and perform normalization."
})
output$feature_note <- renderText({
"Click the button to search for features that can be filtered."
})
output$m.combat_center_note <- renderText({
"Please select the batch number based on the order inside the experimental design."
})
# make m combat notification reactive (changes whenever m combat function is called)
m.combat_notification_text <- reactiveVal(NULL)
output$m.combat_notification <- renderUI({
text_content <- m.combat_notification_text()
tags$div(
id = "m.combat_notification",
style = "color: darkblue;",
text_content
)
})
plot_of_symbols <- function() {
original_Par <- par()
par(font = 2, mar = c(0.5, 0, 0, 0))
y = rev(c(rep(1, 4), rep(2, 5), rep(3, 5), rep(4, 5))) # y values: 4 times 1, 5 times 2, 5 times 3, 5 times 4
x = c(rep(1:5, 4)) # x values: 4 times 1 2 3 4 5
pch_numbers <- 0:18
plot(x[1:length(pch_numbers)], y[1:length(pch_numbers)], pch = pch_numbers, cex = 1.5, ylim = c(1, 4.5), xlim = c(0.5, 5.5),
axes = FALSE, xlab = "", ylab = "")
text(x[1:length(pch_numbers)], y[1:length(pch_numbers)], labels = pch_numbers, pos = 3)
par(mar = original_Par$mar, font = original_Par$font)
}
# plot showing the symbols
output$pca_symbols_plot <- renderPlot({
plot_of_symbols()
})
# important: called to previously get completely raw data frame (without any feature filtering done)
uploaded_data <- function(){
output$datafile_error <- renderText({ NULL }) # clear
req(input$data)
inFile <- input$data
tryCatch({
ext <- tools::file_ext(inFile$name)
if (ext == "csv") {
df <- read.csv(inFile$datapath, header = TRUE, stringsAsFactors = FALSE)
} else {
df <- read.table(inFile$datapath, header = TRUE, sep = "\t", stringsAsFactors = FALSE)
}
# important: same as in rowwisenorm package, replace all non-letter and non-number with a dot (safety)
colnames(df) <- gsub("[^A-Za-z0-9]", ".", colnames(df)) # - otherwise column names do not match
return(df)
}, error = function(e) {
output$datafile_error <- renderText({
paste("Error reading the file of the data:", e$message)
})
return(data.frame()) # return empty data frame
})
}
# called to previously read in uploaded experimental design
uploaded_design <- function(){
req(input$exp_design)
tryCatch({
design <- read.table(input$exp_design$datapath, header = FALSE, sep = "\t", na.strings = "NaN")
design[is.na(design)] <- ""
design <- design[, !apply(design, 2, function(x) all(grepl("^\\s*$", x)))]
design <- as.data.frame(apply(design, 2, function(x) gsub("[^A-Za-z0-9]", ".", trimws(x))))
return(design)
}, error = function(e) {
output$designfile_error <- renderText({
paste("Error reading the file of the experimental design:", e$message)
})
return(data.frame()) # return empty data frame
})
}
# Reactive value to store available features
available_features <- reactiveVal(NULL)
# new data uploaded: Clear the available features when a new file is uploaded
observeEvent(input$data, {
available_features(NULL)
# clear status message of feature filtering
output$generate_features_status <- renderUI({
HTML('')
})
# clear status message of process button
output$process_status <- renderUI({
HTML('')
})
# clear notification section
output$batch_colors_manually_notification <- renderText({ })
output$condition_symbols_manually_notification <- renderText({ })
m.combat_notification_text(NULL)
output$datafile_error <- renderText({ NULL })
output$reading_error <- renderText({ NULL })
})
# new design uploaded:
observeEvent(input$exp_design, {
# clear status message of process button
output$process_status <- renderUI({
HTML('')
})
# clear notification section
output$batch_colors_manually_notification <- renderText({ })
output$condition_symbols_manually_notification <- renderText({ })
m.combat_notification_text(NULL)
output$designfile_error <- renderText({ NULL })
output$reading_error <- renderText({ NULL })
# clear notes about number of colors/symbols to be set
output$batch_colors_manually_note <- renderText({ NULL })
output$condition_symbols_manually_note <- renderText({ NULL })
design <- uploaded_design()
# modifications as in package function read_files
design[is.na(design)] <- ""
design <- design[, !apply(design, 2, function(x) all(grepl("^\\s*$", x)))]
design <- as.data.frame(apply(design, 2, function(x) gsub("[^A-Za-z0-9]", ".", trimws(x))))
max_choices_batches <<- ncol(design) -1
max_choices_conds <<- nrow(design)
# update information how many colors and symbols need to be set - only when > 0 (no error in design)
if (max_choices_batches > 0){
output$batch_colors_manually_note <- renderText({
paste("There need to be ", max_choices_batches, " colors set.")
})
}
if (max_choices_conds > 0) {
output$condition_symbols_manually_note <- renderText({
paste("There need to be ", max_choices_conds, " symbols set.")
})
}
# possible references for newly uploaded design - same as in package
possible_refs <- c()
if(nrow(design) > 0 && ncol(design) > 0){ # - only when design not empty
for (i in 1:nrow(design)){
counter <- 0 # counts how many columns have a value for this row
for(j in 1:ncol(design)){
if(trimws(design[i,j]) != ""){
counter <- counter + 1
}
}
if(counter == ncol(design)){
possible_refs <- append(possible_refs, trimws(design[i,1]))
}
}
}
possible_refs <- unique(possible_refs) # safety
possible_refs <- trimws(possible_refs) # safety
possible_refs <- paste(possible_refs, collapse = ", ") # convert to a String
# update note stating the possible refs
output$possible_refs_note <- renderText({
paste("Possible references are: ", possible_refs)
})
# when new/another design uploaded:
updateTextInput(session, "refs", value = "") # reset input for manually set references
updateNumericInput(session, "m.combat_center", value = 1) # reset selected value for center as default 1
})
# when button to search for features is clicked
observeEvent(input$generate_features, {
# clear status message
output$generate_features_status <- renderUI({
HTML('')
})
# Get available features for the current data
features <- c("only by site", "reverse", "contaminant")
available_features_data <- character(0)
df <- uploaded_data() # currently uploaded data
for (feat in features) {
regex_pattern <- gsub("\\s+", ".*", feat)
matching_col <- grep(regex_pattern, colnames(df), value = TRUE, ignore.case = TRUE, perl = TRUE)
if (length(matching_col) == 1) { # if exactly one column matches
available_features_data <- append(available_features_data, feat) # add the feature as a choice
}
}
# Update the available features using the reactiveVal
available_features(available_features_data)
# status message
generate_features_status <- renderUI({
HTML('<i class="fa fa-check-circle" style="color: green;"></i> Search completed')
})
output$generate_features_status <- generate_features_status
})
# when at least one feature is present, print title for feature filtering
output$feature_text <- renderText({
if ((! is.null(available_features())) & (! identical(available_features(), character(0)))){
"Features that can be filtered:"
} else {
NULL
}
})
# show each checkbox only when feature is available
output$onlyBySiteCheckbox <- renderUI({
if ("only by site" %in% available_features()) {
checkboxInput("onlyBySite", "Only by Site", value = FALSE)
} else {
# set value first to false, then remove checkbox
tagList(
checkboxInput("onlyBySite", "Only by Site", value = FALSE),
tags$script(HTML("$(document).ready(function() { $('input#onlyBySite').parent().hide(); });"))
)
}
})
output$reverseCheckbox <- renderUI({
if ("reverse" %in% available_features()) {
checkboxInput("reverse", "Reverse", value = FALSE)
} else {
# set value first to false, then remove checkbox
tagList(
checkboxInput("reverse", "Reverse", value = FALSE),
tags$script(HTML("$(document).ready(function() { $('input#reverse').parent().hide(); });"))
)
}
})
output$contaminantCheckbox <- renderUI({
if ("contaminant" %in% available_features()) {
checkboxInput("contaminant", "Contaminant", value = FALSE)
} else {
# set value first to false, then remove checkbox
tagList(
checkboxInput("contaminant", "Contaminant", value = FALSE),
tags$script(HTML("$(document).ready(function() { $('input#contaminant').parent().hide(); });"))
)
}
})
# using uploaded design file to set max number of choices for colors and symbols, and for center of M-ComBat
observe({
req(input$exp_design)
# read the uploaded file
design <- uploaded_design()
# maximum numbers of choices for batches and conditions
max_choices_batches <<- ncol(design) -1
max_choices_conds <<- nrow(design)
# whenever more colors/symbols are set than allowed, directly reduce the selected ones
if (max_choices_batches < 1){ # - e.g. error in design file
updateSelectInput(session, "batch_colors_manually", selected = "")
}
else if (length(input$batch_colors_manually) > max_choices_batches){
updateSelectInput(session, "batch_colors_manually", selected = input$batch_colors_manually[1:max_choices_batches])
}
if (max_choices_conds < 1){ # - e.g. error in design file, make selection empty
updateSelectInput(session, "condition_symbols_manually", selected = "")
}
else if (length(input$condition_symbols_manually) > max_choices_conds){
updateSelectInput(session, "condition_symbols_manually", selected = input$condition_symbols_manually[1:max_choices_conds])
}
if (max_choices_batches < 1){
max_choices_batches <<- 1 # otherwise: empty design leads to max = -1, causes endless loop in next observe block
}
updateNumericInput(session, "m.combat_center", max = max_choices_batches)
})
# M-ComBat center: when manually a number is entered, modify to be at most max and at least 1
observe({
if (!is.null(input$m.combat_center) && !is.na(input$m.combat_center)) {
# convert float to integer
updateNumericInput(session, "m.combat_center", value = as.integer(input$m.combat_center))
if (input$m.combat_center > max_choices_batches) {
updateNumericInput(session, "m.combat_center", value = max_choices_batches)
}
else if (input$m.combat_center < 1){
updateNumericInput(session, "m.combat_center", value = 1)
}
}
else {
updateNumericInput(session, "m.combat_center", value = 1)
}
})