-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
1151 lines (966 loc) · 37.4 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
# Load libraries and source code
library(shiny)
library(shinyFiles)
library(fs)
library(pdftools)
library(purrr)
library(DT)
library(bslib)
library(shinyhelper)
library(shinyvalidate)
source("generate_input_path.R")
source("iterate_graphs.R")
source("statistical_analysis.R")
source("helpers.R")
noyes <- c("no","yes")
# Build the User Interface
ui <- fluidPage(
theme = bslib::bs_theme(bootswatch = "darkly"),
#turn-off shown errors in final tool
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"),
tags$head(
tags$style(HTML("
.shiny-output-error-validation {
color: red;
}
"))
),
tags$h1("IgIDivA", align = "center"),
navlistPanel(id = 'main',
tabPanel("Import Data",
textInput("output_folder", "Please provide a path where to save the final results", placeholder = "Enter desired path here",width = "100%"),
actionButton("create", "Create Results Path", class = "btn-primary"),
br(),
br(),
br(),
br(),
textInput("dir", "Choose input directory", placeholder = "Enter desired path here",width = "100%"),
br(),
actionButton("upload", "Upload", class = "btn-primary"),
br(),
br(),
selectInput("samples", "Select samples to analyze", choices = character(0), selected = character(0), multiple = TRUE, width = "100%"),
textOutput("error"),
br(),
tags$b("Press Verify when finished with inputting samples"),
br(),
br(),
actionButton("verify", "Verify", class = "btn-primary"),
br(),
br(),
tags$b("Create a .txt file determining the grouping of the chosen samples for comparisons."),
br(),
tags$b("The file must contain two columns and the first row must contain the names of the columns."),
br(),
tags$b("First column contains the IDs of the samples to be analyzed. It must be named 'sample_id'."),
br(),
tags$b("Second column includes the name of the group each sample belongs to. Default name is 'group_name' but can be changed below."),
br(),
tags$b("The columns and their corresponding values must be separated by tabs."),
br(),
br(),
textInput("groups_name", "Enter the name chosen for the second column:", value = "group_name", placeholder = "Enter column name"),
br(),
fileInput("samples_groups", "Upload .txt file with grouped samples:", multiple = FALSE, accept = ".txt", width = "100%", buttonLabel = "Browse...", placeholder = "No file has been uploaded"),
),
tabPanel("Set Parameters",
numericInput("col_start", "Enter starting column [suggested: 5 (beginning of FR1 region), 23-59 (when using FR1 primers)]:", value = 5, step = 1),
br(),
numericInput("col_end", "Enter ending column [suggested: 313 (end of FR3 region)]:", value = 313, step = 1),
br(),
numericInput("min_reads", "Enter threshold minimum reads for the nodes [suggested: 10]:", value = 10, step = 1),
br(),
numericInput("p_thres", "Enter p-value threshold [suggested: 0.01 or 0.05]:", value = 0.05),
br(),
selectInput("adjust", "Do you want the p-values to be adjusted?", noyes),
br(),
textInput("highly_sim_clonos", "Clonotypes to be taken into account for the analysis: Choose the row from the highly_sim_clonos_file and enter its index [default = 1]", value = "1"),
br(),
helper(
shiny::checkboxGroupInput("include", "Which should be included from the following?", choices = c("Summary tables", "Jumps between non-adjacent nodes", "Separate graphs","Amino-acid mutations", "Size scaling of nodes proportional to reads", "Graph metrics", "Graph networks", "Metrics comparisons"), selected = c("Jumps between non-adjacent nodes","Amino-acid mutations", "Size scaling of nodes proportional to reads", "Graph metrics", "Summary tables", "Graph networks", "Metrics comparisons")),
colour = "red",
type = "inline",
content = "Choose which options to include in the analysis. Summary tables produces tables throughout the process. The jumps between non-adjacent nodes allows that nt vars with common SHMs differing by two or more SHMs to be included in the analysis. If the option separate graphs is selected, the graph network of each sample will be separated into two different graphs: on the left, the main nt var and the nt vars with fewer SHMs than the main nt var [the less mutations pathway] and on the right the main nt var and the nt vars with additional mutations. If the option of amino acids mutations is selected, replacement mutations will be shown in the analysis and summary tables about the replacement mutations will be produced. Other option includes the possibility of having the size of the nodes of the graph networks proportional to the number of reads of the respective nucleotide variant. Other options consist on including graph metrics, graph networks and metric comparison in the analysis. For more information, please consult the IgIDivA UserGuide."
),
br(),
uiOutput("graph_metrics_to_choose"),
br(),
uiOutput("comparison_metrics_to_choose"),
br(),
actionButton("start", "Start", class = "btn-lg btn-success"),
br(),
br(),
br(),
tags$strong("Resets input parameters to suggested values"),
br(),
br(),
actionButton("reset", "Reset", class = "btn-lg btn-danger"),
br(),
br()
),
tabPanel("Visualize Results",
tabsetPanel(
tabPanel("Summary Calculations",
navlistPanel(
id = "samples1"
)
),
tabPanel("Extra Mutations Calculations",
navlistPanel(
id = "samples2"
)
),
tabPanel("Less Mutations Calculations",
navlistPanel(
id = "samples3"
)
),
tabPanel("Mutations",
navlistPanel(
id = "samples4"
)
),
tabPanel("Amino-acid Mutations Main Variant",
navlistPanel(
id = "samples5"
)
),
tabPanel("Global Amino-acid Mutations Main Variant",
dataTableOutput("aa_mutations_main_var_global")
),
tabPanel("Amino-acid Mutations",
navlistPanel(
id = "samples6"
)
),
tabPanel("Global Amino-acid Mutations",
dataTableOutput("aa_mutations_global")
),
tabPanel("Graph Metrics",
navlistPanel(
id = "samples7"
)
),
tabPanel("Global Graph Metrics",
dataTableOutput("graph_metrics_global")
),
tabPanel("Graph Networks",
navlistPanel(
id = "samples8"
)
),
tabPanel("Metrics Comparisons",
navlistPanel(
id = "metrics"
)
),
tabPanel("Discarded Samples",
dataTableOutput("discard_samples"
)
)
)
)
)
)
# Construct the Server
server <- function(input, output, session) {
observe_helpers()
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$upload
},
handlerExpr = {
p = input$dir
if( .Platform$OS.type == "windows" ){p <- str_replace_all(p,'\\\\','/')}
samples <- generate_input_file(p)
updateSelectInput(inputId = "samples", choices = samples[[3]])
}
)
files <- reactiveValues(
ga_files = NULL,
hsim_files = NULL,
id_hsim = NULL,
)
files_old <- reactiveValues(
id_hsim = NULL,
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$verify
},
handlerExpr = {
req(input$samples)
showNotification("Nice!", type = "message")
chosen_samples <- data.table::fread(paste0(getwd(), "/input_files.txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
chosen_samples <- chosen_samples[which(chosen_samples$sample_id %in% input$samples), ]
write.table(chosen_samples, paste0(input$output_folder, "/chosen_samples.txt"), sep = "\t", dec = ".",
row.names = FALSE, col.names = TRUE,quote = FALSE)
files$hsim_files <- chosen_samples$highly_sim_clonos_file
files$ga_files <- chosen_samples$grouped_alignment_file
files$id_hsim <- chosen_samples$sample_id
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$create
},
handlerExpr = {
req(input$output_folder)
generate_output_path(input$output_folder)
showNotification("Folder Created!", type = "message")
}
)
output$graph_metrics_to_choose <- renderUI({
if ("Graph metrics" %in% input$include) {
helper(
shiny::checkboxGroupInput("include_metrics", "Which graph metrics to show?", choices = c("Main variant identity", "Relative convergence (reads)", "Most relevant pathway score", "Most relevant pathway (nodes)", "End nodes density", "Max path length", "Max mutations path length", "Total reads", "Average degree", "Average distance"), selected = c("Sample ID", "Main variant identity", "Relative convergence (reads)", "Most relevant pathway score", "Most relevant pathway (nodes)", "End nodes density", "Max path length", "Max mutations path length", "Total reads", "Average degree", "Average distance")),
colour = "red",
type = "inline",
content = "The main variant identity shows the percentage of identity of the main nt var with its respective germline. The relative convergence reads calculates the ratio of the number of sequences of the most relevant pathways to the number of sequences of the main nt var. The most relevant pathway score is the ratio o the total number of sequences of the nodes forming one block of pathways to the total number of sequences of all the nodes of the network with more SHMs than the main nt var. The most relevant pathway score nodes shows the number of nodes of the most relevant pathway. The end nodes density is the ratio of the number of end nodes to the number of nt vars with additional SHMs. The max path length is the number of levels of additional SHMs. The max mutations path length shows the maximum level of additional SHMs, allowing non-consecutive SHMs. The total reads shows the total number of reads of the sample. The average degree is the average total number of connections of each nt var. The average distance isthe average number of steps along the shortest pathways between each pair of nt vars."
)
}
})
output$comparison_metrics_to_choose <- renderUI({
if ("Metrics comparisons" %in% input$include) {
helper(
shiny::checkboxGroupInput("compare_metrics", "Which metrics to compare?", choices = c("Convergence score", "End nodes density", "Max path length", "Max mutations length", "Average degree", "Average distance"), selected = c("Convergence score", "End nodes density", "Max path length", "Max mutations length", "Average degree", "Average distance")),
colour = "red",
type = "inline",
content = "Select, among the graph metrics, which one(s) to use to perform comparisons between groups of samples."
)
}
})
clonotypes <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$highly_sim_clonos
},
valueExpr = {
as.integer(unlist(strsplit(input$highly_sim_clonos, ",")))
}
)
metrics_to_compare <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$compare_metrics
},
valueExpr = {
req("Metrics comparisons" %in% input$include)
metrics <- paste(input$compare_metrics, collapse = ",")
metrics_to_compare <- choose_comparison_metrics(metrics)
metrics_to_compare
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
if (!is.null(files_old$id_hsim)){
for(i in 1:8) {
imap(files_old$id_hsim, ~{
removeTab(
paste0("samples", i),
target = paste(files_old$id_hsim[.y])
)
})
}
tabs <- c("Convergence Score", "End Nodes Density", "Max Path Length", "Max Mutations Length", "Average Degree", "Average Distance")
for (i in tabs) {
removeTab(
"metrics",
target = i
)
}
output$aa_mutations_main_var_global <- renderDataTable({})
output$aa_mutations_global <- renderDataTable({})
output$graph_metrics_global <- renderDataTable({})
output$discard_samples <- renderDataTable({})
}
updateNavlistPanel(session, 'main', selected = "Visualize Results")
files_old$id_hsim = files$id_hsim
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
withProgress(
message = "Analysis in progress",
detail = "This may take a while...",
{
for (i in 1:length(files$id_hsim)) {
doGraph(save_path = input$output_folder, files$hsim_files[i], files$ga_files[i], files$id_hsim[i], include_jump = ("Jumps between non-adjacent nodes" %in% input$include), col_start = input$col_start, col_end = input$col_end, min_reads = input$min_reads, highly_sim_clonos = clonotypes(), nodes_size_scaling = ("Size scaling of nodes proportional to reads" %in% input$include), include_aa_muts = ("Amino-acid mutations" %in% input$include), separate_graphs = ("Separate graphs" %in% input$include))
incProgress(1 / length(files$id_hsim))
}
iterate_do_graph(argument_file=paste0(input$output_folder, "/chosen_samples.txt"), save_path = input$output_folder, include_jump = ("Jumps between non-adjacent nodes" %in% input$include), col_start = input$col_start, col_end = input$col_end, min_reads = input$min_reads, highly_sim_clonos = clonotypes(), nodes_size_scaling = ("Size scaling of nodes proportional to reads" %in% input$include), include_aa_muts = ("Amino-acid mutations" %in% input$include), separate_graphs = ("Separate graphs" %in% input$include))
#####################
if(input_provided(input$samples_groups)){
perform_statistical_analysis(groups_file = input$samples_groups$datapath,
save_folder = input$output_folder,
final_metric_table = paste0(input$output_folder,
"/Output/metric_table_all.txt"),
comparison_metrics = metrics_to_compare(),
compare_by = input$groups_name,
p_threshold = input$p_thres,
adjust = input$adjust)
}
}
)
}
)
# summary calculations TAB
summary_calculations_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include)
summary_calculations_tables <- map2(files$id_hsim, input$output_folder, create_summary_calculations_table)
summary_calculations_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(summary_calculations_tables())
iwalk(summary_calculations_tables(), ~{
output_name <- paste0("summary_calculations_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Summary Calculations", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(summary_calculations_tables())
summary_calculations_tables_list <- imap(summary_calculations_tables(), ~{
tagList(
insertTab(
"samples1",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("summary_calculations_table_", .y)
)
)
)
)
})
tagList(summary_calculations_tables_list)
}
)
# extra mutations TAB
extra_mutations_calculations_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include)
extra_mutations_calculations_tables <- map2(files$id_hsim, input$output_folder, create_extra_mutations_calculations_table)
extra_mutations_calculations_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(extra_mutations_calculations_tables())
iwalk(extra_mutations_calculations_tables(), ~{
output_name <- paste0("extra_mutations_calculations_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Extra Mutations Calculations", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(extra_mutations_calculations_tables())
extra_mutations_calculations_tables_list <- imap(extra_mutations_calculations_tables(), ~{
tagList(
insertTab(
"samples2",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("extra_mutations_calculations_table_", .y)
)
)
)
)
})
tagList(extra_mutations_calculations_tables_list)
}
)
# less mutations TAB
less_mutations_calculations_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include)
less_mutations_calculations_tables <- map2(files$id_hsim, input$output_folder, create_less_mutations_calculations_table)
less_mutations_calculations_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(less_mutations_calculations_tables())
iwalk(less_mutations_calculations_tables(), ~{
output_name <- paste0("less_mutations_calculations_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Less Mutations Calculations", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(less_mutations_calculations_tables())
less_mutations_calculations_tables_list <- imap(less_mutations_calculations_tables(), ~{
tagList(
insertTab(
"samples3",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("less_mutations_calculations_table_", .y)
)
)
)
)
})
tagList(less_mutations_calculations_tables_list)
}
)
############################################################################
# mutations TAB
mutations_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include)
mutations_tables <- pmap(list(files$id_hsim, input$min_reads, input$output_folder), create_mutations_table)
mutations_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(mutations_tables())
iwalk(mutations_tables(), ~{
output_name <- paste0("mutations_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Mutations", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(mutations_tables())
mutations_tables_list <- imap(mutations_tables(), ~{
tagList(
insertTab(
"samples4",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("mutations_table_", .y)
)
)
)
)
})
tagList(mutations_tables_list)
}
)
# Amino-acide mutations main variant TAB
aa_mutations_main_var_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include, "Amino-acid mutations" %in% input$include)
aa_mutations_main_var_tables <- map2(files$id_hsim, input$output_folder, create_aa_mutations_main_var_table)
aa_mutations_main_var_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(aa_mutations_main_var_tables())
iwalk(aa_mutations_main_var_tables(), ~{
output_name <- paste0("aa_mutations_main_var_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Amino - acid Mutations (main)", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(aa_mutations_main_var_tables())
aa_mutations_main_var_tables_list <- imap(aa_mutations_main_var_tables(), ~{
tagList(
insertTab(
"samples5",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("aa_mutations_main_var_table_", .y)
)
)
)
)
})
tagList(aa_mutations_main_var_tables_list)
}
)
# Global Amino-acid Mutations Main Variant TAB
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req("Summary tables" %in% input$include, "Amino-acid mutations" %in% input$include)
output$aa_mutations_main_var_global <- renderDataTable(
{
aa_mutations_main_var_global <- data.table::fread(paste0(input$output_folder, "/Output/aa_muts_weight_main_variant.txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
aa_mutations_main_var_global
},
caption = paste("Global Amino - acid Mutations (main)"),
options = list(paging=FALSE,searching=TRUE)
)
}
)
# Amino-acid mutations TAB
aa_mutations_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include, "Amino-acid mutations" %in% input$include)
aa_mutations_tables <- map2(files$id_hsim, input$output_folder, create_aa_mutations_table)
aa_mutations_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(aa_mutations_tables())
iwalk(aa_mutations_tables(), ~{
output_name <- paste0("aa_mutations_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Amino - acid Mutations (rest)", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(aa_mutations_tables())
aa_mutations_tables_list <- imap(aa_mutations_tables(), ~{
tagList(
insertTab(
"samples6",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("aa_mutations_table_", .y)
)
)
)
)
})
tagList(aa_mutations_tables_list)
}
)
#Global Amino-acid Mutations TAB
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req("Summary tables" %in% input$include, "Amino-acid mutations" %in% input$include)
output$aa_mutations_global <- renderDataTable(
{
aa_mutations_global <- data.table::fread(paste0(input$output_folder,"/Output/aa_muts_weight.txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
aa_mutations_global
},
caption = paste("Global Amino - acid Mutations (rest)"),
options = list(paging=FALSE,searching=TRUE)
)
}
)
#Discarded Samples TAB
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req("Summary tables" %in% input$include, "Amino-acid mutations" %in% input$include)
output$discard_samples <- renderDataTable(
{
discard_samples <- data.table::fread(paste0(input$output_folder, "/Output/discarded_samples_table.txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
discard_samples
},
caption = paste("Discarded Samples"),
options = list(paging=FALSE,searching=TRUE)
)
}
)
# Graph Metrics TAB
graph_metrics_tables <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
req("Summary tables" %in% input$include, "Graph metrics" %in% input$include)
metrics <- paste(input$include_metrics, collapse = ",")
graph_metrics_tables <- pmap(list(files$id_hsim, metrics, input$output_folder), create_graph_metrics_table)
graph_metrics_tables
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(graph_metrics_tables())
iwalk(graph_metrics_tables(), ~{
output_name <- paste0("graph_metrics_table_", .y)
output[[output_name]] <- renderDataTable(
{.x},
caption = paste("Graph Metrics", files$id_hsim[.y]),
options = list(paging=FALSE,searching=TRUE)
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(graph_metrics_tables())
graph_metrics_tables_list <- imap(graph_metrics_tables(), ~{
tagList(
insertTab(
"samples7",
tabPanel(paste(files$id_hsim[.y]),
dataTableOutput(
outputId = paste0("graph_metrics_table_", .y)
)
)
)
)
})
tagList(graph_metrics_tables_list)
}
)
#Global Graph Metrics TAB
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req("Summary tables" %in% input$include, "Graph metrics" %in% input$include)
output$graph_metrics_global <- renderDataTable(
{
graph_metrics_global <- data.table::fread(paste0(input$output_folder,"/Output/metric_table_all.txt"), header = TRUE, sep = "\t", stringsAsFactors = FALSE)
graph_metrics_global
},
caption = paste("Global Graph Metrics"),
options = list(paging=FALSE,searching=TRUE)
)
}
)
#Graph Networks TAB
graph_networks <- eventReactive(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
valueExpr = {
showNotification(id="conversion","File conversion in progress...", type = "message", duration = NULL)
req("Graph networks" %in% input$include)
graph_networks <- map2(files$id_hsim, input$output_folder, create_graph_network)
graph_networks
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(graph_networks())
removeNotification(id="conversion")
iwalk(graph_networks(), ~{
output_name <- paste0("graph_network_", .y)
output[[output_name]] <- renderImage(
{.x},
deleteFile = FALSE
)
})
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req(graph_networks())
graph_networks_list <- imap(graph_networks(), ~{
tagList(
insertTab(
"samples8",
tabPanel(paste(files$id_hsim[.y]),
imageOutput(
outputId = paste0("graph_network_", .y)
)
)
)
)
})
tagList(graph_networks_list)
}
)
#Metrics Comparisons TAB
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},
handlerExpr = {
req("Metrics comparisons" %in% input$include, "Convergence score" %in% input$compare_metrics)
insertTab(
"metrics",
tabPanel("Convergence Score",
imageOutput(
outputId = "convergence_score_comparison"
)
)
)
output$convergence_score_comparison <- renderImage(
{
pdf_convert(paste0(input$output_folder, "/Comparisons/convergence_score_vs_", input$groups_name, ".pdf"), format = "png", filenames = paste0(input$output_folder, "/Comparisons/convergence_score_vs_", input$groups_name, ".png"), dpi = 300)
list(src = paste0(input$output_folder,"/Comparisons/convergence_score_vs_", input$groups_name, ".png"), width = 800, height = 800)
},
deleteFile = FALSE
)
}
)
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$start
},