-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
2385 lines (2106 loc) · 84 KB
/
app.R
File metadata and controls
2385 lines (2106 loc) · 84 KB
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)
library(shinythemes)
library(fontawesome)
library(DT)
library(plotly)
library(ggplot2)
library(limma)
library(ggrepel)
library(shinycssloaders)
library(fgsea)
library(msigdbr)
library(dplyr)
library(tidyr)
library(qs)
library(ggpubr)
library(png)
library(grid)
source("helper_functions.R")
# Load CHARM object once when app starts
#Charm.object <- readRDS("data/Charm.object.RDS")
Charm.object <- qs::qread("data/QS_Files/Charm.object.qs")
#sh_effect_vector <- readRDS("data/shRNA_Efficiency.Rds")
sh_effect_vector <- qs::qread("data/QS_Files/shRNA_Efficiency.qs")
#Charm.object_K562 <- readRDS("data/Charm.object_K562.RDS")
Charm.object_K562 <- qs::qread("data/QS_Files/Charm.object_K562.qs")
#sh_effect_vector_K562 <- readRDS("data/shRNA_Efficiency_K562.Rds")
sh_effect_vector_K562 <- qs::qread("data/QS_Files/shRNA_Efficiency_K562.qs")
#Charm.object_HEPG2 <- readRDS("data/Charm.object_HEPG2.RDS")
Charm.object_HEPG2 <- qs::qread("data/QS_Files/Charm.object_HEPG2.qs")
#sh_effect_vector_HEPG2 <- readRDS("data/shRNA_Efficiency_HEPG2.Rds")
sh_effect_vector_HEPG2 <- qs::qread("data/QS_Files/shRNA_Efficiency_HEPG2.qs")
# Binding Data
#Charm.object.binding.ES <- readRDS("data/Binding_both.RDS")
Charm.object.binding.ES <- qs::qread("data/QS_Files/Binding_both.qs")
#Charm.object.binding.ES_K562 <- readRDS("data/Binding_K562.RDS")
Charm.object.binding.ES_K562 <- qs::qread("data/QS_Files/Binding_K562.qs")
#Charm.object.binding.ES_HEPG2 <- readRDS("data/Binding_HEPG2.RDS")
Charm.object.binding.ES_HEPG2 <- qs::qread("data/QS_Files/Binding_HEPG2.qs")
#Charm.object.binding.IR <- readRDS("data/Binding_IR_both.RDS")
Charm.object.binding.IR <- qs::qread("data/QS_Files/Binding_IR_both.qs")
#Charm.object.binding.IR_K562 <- readRDS("data/Binding_IR_K562.RDS")
Charm.object.binding.IR_K562 <- qs::qread("data/QS_Files/Binding_IR_K562.qs")
#Charm.object.binding.IR_HEPG2 <- readRDS("data/Binding_IR_HEPG2.RDS")
Charm.object.binding.IR_HEPG2 <- qs::qread("data/QS_Files/Binding_IR_HEPG2.qs")
#Similarity stuff
#similar_expression_all <- readRDS("data/RBPs.t_All.RDS")
similar_expression_all <- qs::qread("data/QS_Files/RBPs.t_All.qs")
#similar_expression_K562 <- readRDS("data/RBPs.t_K562.RDS")
similar_expression_K562 <- qs::qread("data/QS_Files/RBPs.t_K562.qs")
#similar_expression_HEPG2 <- readRDS("data/RBPs.t_HEPG2.RDS")
similar_expression_HEPG2 <- qs::qread("data/QS_Files/RBPs.t_HEPG2.qs")
#similar_gsea_all <- readRDS("data/RBPs.gsea_All.RDS")
similar_gsea_all <- qs::qread("data/QS_Files/RBPs.gsea_All.qs")
#similar_gsea_K562 <- readRDS("data/RBPs.gsea_K562.RDS")
similar_gsea_K562 <- qs::qread("data/QS_Files/RBPs.gsea_K562.qs")
#similar_gsea_HEPG2 <- readRDS("data/RBPs.gsea_HEPG2.RDS")
similar_gsea_HEPG2 <- qs::qread("data/QS_Files/RBPs.gsea_HEPG2.qs")
#SearchBarPopulation
#GenesBoth <- readRDS("data/AvailableGenes_both.RDS")
GenesBoth <- qs::qread("data/QS_Files/AvailableGenes_both.qs")
#GenesK562 <- readRDS("data/AvailableGenes_K562.RDS")
GenesK562 <- qs::qread("data/QS_Files/AvailableGenes_K562.qs")
#GenesHEPG2 <- readRDS("data/AvailableGenes_HEPG2.RDS")
GenesHEPG2 <- qs::qread("data/QS_Files/AvailableGenes_HEPG2.qs")
#EventsBoth <- readRDS("data/AvailableEvents_Both.RDS")
EventsBoth <- qs::qread("data/QS_Files/AvailableEvents_Both.qs")
#EventsK562 <- readRDS("data/AvailableEvents_K562.RDS")
EventsK562 <- qs::qread("data/QS_Files/AvailableEvents_K562.qs")
#EventsHEPG2 <- readRDS("data/AvailableEvents_HEPG2.RDS")
EventsHEPG2 <- qs::qread("data/QS_Files/AvailableEvents_HEPG2.qs")
ui <- fluidPage(
theme = shinytheme("flatly"),
# Custom CSS for bold tabs
tags$head(
tags$style(HTML("
.search-box {
border-radius: 20px;
padding: 6px 12px;
border: 1px solid #ccc;
box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
font-size: 14px;
}
.search-box:focus {
border-color: #2c3e50;
outline: none;
box-shadow: 0 0 5px rgba(44,62,80,0.4);
}
")),
tags$script(HTML("
Shiny.addCustomMessageHandler('toggleCursor', function(state) {
document.body.style.cursor = state ? 'wait' : 'default';
});
"))
),
# Tabset with 5 tabs
tabsetPanel(
type = "tabs",
id = "main_tabs",
# Home tab
tabPanel(
tagList(fa("home", fill = "black", height = "1em"), " Home"),
fluidPage(
fluidRow(
column(
4,
div(
style = "display: flex; align-items: center; justify-content: center; margin: 30px 0;",
div(style = "margin-right: 15px;", fa("gem", fill = "black", height = "4em")),
div(
style = "text-align: left;",
tags$h2("CHARM", style = "margin: 0; font-weight: bold;"),
tags$h4("Comprehensive Hub of Alternative Regulatory Mapping", style = "margin: 0; font-weight: bold;")
)
)
)
),
fluidRow(
column(
6,
div(
style = "background-color: #EAEBEB; color: black; border: 2px solid #2c3e50; border-radius: 20px; padding: 40px; text-align: center; margin: 15px;",
div(style = "margin-bottom: 10px;", fa("globe", fill = "black", height = "3em")),
tags$h3("Explore", style = "font-weight: bold;"),
tags$p("Investigate how a known RBP affects expression, splicing, and binding, based on ENCODE's gene silencing series and eCLIP data. Find out which genes/gene sets are more influenced by RBPs")
)
),
column(
6,
div(
style = "background-color: #EAEBEB; color: black; border: 2px solid #2c3e50; border-radius: 20px; padding: 40px; text-align: center; margin: 15px;",
div(style = "margin-bottom: 10px;", fa("map", fill = "black", height = "3em")),
tags$h3("Discover", style = "font-weight: bold;"),
tags$p("Users can input their own expression, splicing, or binding data to discover which RBPs are more likely to be altered on your biological system.")
)
)
)
)
),
# Expression tab
tabPanel(
tagList(fa("dna", fill = "black", height = "1em"), " Expression"),
fluidPage(
fluidRow(
# Left sidebar
# Left sidebar (width = 3)
column(
width = 3,
wellPanel(
# --- Mode selection ---
radioButtons(
inputId = "expr_mode",
label = "Select mode:",
choices = c("Explore Mode", "Discovery Mode"),
selected = "Explore Mode"
),
# --- Explore Mode ---
conditionalPanel(
condition = "input.expr_mode == 'Explore Mode'",
# Dataset selection
selectInput(
inputId = "expr_dataset",
label = "Select option:",
choices = c("Both Cells", "K562", "HEPG2", "Similar RBPs")
),
# ---- Search by RBP ----
div(
style = "margin-top: 15px;",
tags$h5("Search by RBP"),
tags$p("Find out how RBPs influence expression and gene set enrichment",
style = "font-size: 12px; color: #666; margin-top: -5px;"),
div(
style = "display: flex; align-items: center;",
selectizeInput(
inputId = "expr_search_rbp",
label = NULL,
choices = NULL, # dynamically populated in server
multiple = FALSE,
options = list(placeholder = "RBP"),
width = "400px"
),
conditionalPanel(
condition = "input.expr_dataset != 'Similar RBPs'",
div(
style = "display: flex; align-items: center; margin-left: 10px;",
actionButton("search_btn_rbp", tagList(fa("search"), " Search"),
class = "btn btn-primary", style = "margin-right: 10px; border-radius: 20px;"),
actionButton("reset_btn_rbp", tagList(fa("redo"), " Reset"),
class = "btn btn-secondary", style = "border-radius: 20px;")
)
)
)
),
# ---- Search by Gene (hidden for Similar RBPs) ----
conditionalPanel(
condition = "input.expr_dataset != 'Similar RBPs'",
div(
style = "margin-top: 25px;",
tags$h5("Search by Gene"),
selectizeInput(
inputId = "expr_search_gene",
label = NULL,
choices = NULL, # dynamically populated in server
multiple = FALSE,
options = list(placeholder = "Gene"),
width = "400px"
),
div(
style = "margin-top: 5px;",
actionButton("search_btn_gene", tagList(fa("search"), " Search"),
class = "btn btn-primary", style = "margin-right: 10px; border-radius: 20px;"),
actionButton("reset_btn_gene", tagList(fa("redo"), " Reset"),
class = "btn btn-secondary", style = "border-radius: 20px;")
)
)
),
# ---- Search by Hallmark Gene Set (hidden for Similar RBPs) ----
conditionalPanel(
condition = "input.expr_dataset != 'Similar RBPs'",
div(
style = "margin-top: 25px;",
tags$h5("Search by Hallmark Gene Set"),
selectizeInput(
inputId = "expr_search_hallmark",
label = NULL,
choices = NULL, # dynamically populated in server
multiple = FALSE,
options = list(placeholder = "Hallmark Gene Set"),
width = "400px"
),
div(
style = "margin-top: 5px;",
actionButton("search_btn_hallmark", tagList(fa("search"), " Search"),
class = "btn btn-primary", style = "margin-right: 10px; border-radius: 20px;"),
actionButton("reset_btn_hallmark", tagList(fa("redo"), " Reset"),
class = "btn btn-secondary", style = "border-radius: 20px;")
)
)
),
# ---- Similar RBPs options (single, no duplication) ----
conditionalPanel(
condition = "input.expr_dataset == 'Similar RBPs'",
# Correlation type
radioButtons(
inputId = "similar_mode",
label = "Select correlation type:",
choices = c("By Gene Expression" = "expr", "By Gene Set Enrichment" = "gsea"),
selected = "expr",
inline = TRUE
),
# Expression correlation inputs - ONLY show when expr mode is selected
conditionalPanel(
condition = "input.similar_mode == 'expr'",
selectizeInput(
inputId = "similar_rbps_select_expr",
label = "Compare with specific RBPs (optional)",
choices = NULL,
multiple = TRUE,
options = list(placeholder = "Select one or more RBPs")
),
numericInput("correl_num_expr", "Show top N correlated RBPs (optional):", value = NA, min = 1),
numericInput("n_pos_expr", "Show top N positive correlations (optional):", value = NA, min = 1),
numericInput("n_neg_expr", "Show top N negative correlations (optional):", value = NA, min = 1)
),
# GSEA correlation inputs - ONLY show when gsea mode is selected
conditionalPanel(
condition = "input.similar_mode == 'gsea'",
selectizeInput(
inputId = "similar_rbps_select_gsea",
label = "Compare with specific RBPs (optional)",
choices = NULL,
multiple = TRUE,
options = list(placeholder = "Select one or more RBPs")
),
numericInput("correl_num_gsea", "Show top N correlated RBPs (optional):", value = NA, min = 1),
numericInput("n_pos_gsea", "Show top N positive correlations (optional):", value = NA, min = 1),
numericInput("n_neg_gsea", "Show top N negative correlations (optional):", value = NA, min = 1)
),
# Plot / Reset buttons
div(
style = "display: flex; align-items: center; margin-top: 15px;",
actionButton("similar_plot_btn", tagList(fa("chart-line"), " Plot"),
class = "btn btn-primary", style = "margin-right: 10px; border-radius: 20px;"),
actionButton("similar_reset_btn", tagList(fa("redo"), " Reset"),
class = "btn btn-secondary", style = "border-radius: 20px;")
)
)
),
# --- Discovery Mode: User File Upload ---
conditionalPanel(
condition = "input.expr_mode == 'Discovery Mode'",
hr(),
tags$p("Alternatively, upload your own table with differential expression values. Data must have no header, and the first column must be the HGNC gene symbol, and the second column the t-stats."),
fileInput("user_file_expr", "Upload your file:", accept = c(".txt")),
uiOutput("file_warning_expr"),
uiOutput("user_file_options")
)
)
)
,
# Right content area
column(
width = 9,
tags$h3("Expression Data <- "),
# --- Explore Mode (default mode) ---
conditionalPanel(
condition = "input.expr_mode == 'Explore Mode' && input.expr_dataset != 'Similar RBPs'",
# --- Warning message ---
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;"
),
# --- Gene search plot (appear at top when searched) ---
conditionalPanel(
condition = "input.search_btn_gene > 0",
fluidRow(
column(
width = 12,
plotOutput("expr_gene_plot", height = "600px")
)
)
),
# --- Hallmark gene set search plot (appear at top when searched) ---
conditionalPanel(
condition = "input.search_btn_hallmark > 0",
fluidRow(
column(
width = 12,
plotOutput("expr_hallmark_plot", height = "600px")
)
)
),
# --- Default RBP plots ---
fluidRow(
column(width = 6, plotOutput("expr_violin", height = "400px")),
column(
width = 6,
plotOutput("shrna_plot"),
uiOutput("shrna_warning")
)
),
fluidRow(
column(width = 6, plotlyOutput("volcano_plot", height = "450px")),
column(width = 6, DTOutput("volcano_table"))
),
fluidRow(
column(width = 6, plotOutput("gsea_plot", height = "600px")),
column(width = 6, DTOutput("geneset_table"))
)
),
# --- Similar RBPs (Explore Mode, special layout) ---
conditionalPanel(
condition = "input.expr_mode == 'Explore Mode' && input.expr_dataset == 'Similar RBPs'",
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
uiOutput("similar_expr_plots")
),
# --- Discovery Mode ---
conditionalPanel(
condition = "input.expr_mode == 'Discovery Mode'",
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
uiOutput("userfilesimilar_expr"),
uiOutput("userfilesimilar_gsea")
)
)
)
)
),
# Splicing tab
tabPanel(
tagList(fa("scissors", fill = "black", height = "1em"), " Splicing"),
fluidPage(
fluidRow(
column(
width = 3,
wellPanel(
radioButtons("splice_mode", "Select mode:", choices = c("Explore Mode", "Discovery Mode"), selected = "Explore Mode"),
conditionalPanel(
condition = "input.splice_mode == 'Explore Mode'",
selectInput(
"splice_dataset", "Select option:",
choices = c("Both Cells", "K562", "HEPG2", "Similar RBPs")
),
# ---- Search by RBP (always visible) ----
div(
style = "margin-top: 15px;",
tags$h5("Search by RBP"),
tags$p(
"Visualize how splicing of an RBP impacts alternative splicing across datasets.",
style = "font-size: 12px; color: #666; margin-top: -5px;"
),
div(
style = "display: flex; align-items: center;",
selectizeInput(
inputId = "splice_search",
label = NULL,
choices = NULL,
multiple = FALSE,
options = list(placeholder = "RBP"),
width = "400px"
),
conditionalPanel(
condition = "input.splice_dataset != 'Similar RBPs'",
div(
style = "display: flex; align-items: center; margin-left: 10px;",
actionButton(
"splice_search_btn",
tagList(fa("search"), " Search"),
class = "btn btn-primary",
style = "margin-right: 10px; border-radius: 20px;"
),
actionButton(
"splice_reset_btn",
tagList(fa("redo"), " Reset"),
class = "btn btn-secondary",
style = "border-radius: 20px;"
)
)
)
)
),
# ---- Search by Event ID (hidden when Similar RBPs is selected) ----
conditionalPanel(
condition = "input.splice_dataset != 'Similar RBPs'",
div(
style = "margin-top: 25px;",
tags$h5("Search by Event ID"),
tags$p(
list(
"Find out which RBPs most strongly regulate a specific splicing event. Event IDs are obtained from ",
tags$a(
href = "https://vastdb.crg.eu/",
"VastDB",
target = "_blank",
style = "color: #007bff; text-decoration: none;"
),
"."
),
style = "font-size: 12px; color: #666; margin-top: -5px;"
),
div(
style = "display: flex; align-items: center;",
selectizeInput(
inputId = "splice_search_event", # <-- consistent ID
label = NULL,
choices = NULL,
multiple = FALSE,
options = list(placeholder = "Event ID"),
width = "400px"
),
div(
style = "display: flex; align-items: center; margin-left: 10px;",
actionButton(
"search_btn_event",
tagList(fa("search"), " Search"),
class = "btn btn-primary",
style = "margin-right: 10px; border-radius: 20px;"
)
)
)
)
),
conditionalPanel(
condition = "input.splice_dataset == 'Similar RBPs'",
selectizeInput("similar_rbps_select_splice", "Compare with specific RBPs (optional)", choices = NULL, multiple = TRUE, options = list(placeholder = "Select one or more RBPs")),
numericInput("correl_num_splice", "Show top N correlated RBPs (optional):", value = NA, min = 1),
numericInput("n_pos_splice", "Show top N positive correlations (optional):", value = NA, min = 1),
numericInput("n_neg_splice", "Show top N negative correlations (optional):", value = NA, min = 1),
div(
style = "display: flex; align-items: center; margin-top: 15px;",
actionButton("similar_plot_btn_splice", tagList(fa("chart-line"), " Plot"), class = "btn btn-primary", style = "margin-right: 10px; border-radius: 20px;"),
actionButton("similar_reset_btn_splice", tagList(fa("redo"), " Reset"), class = "btn btn-secondary", style = "border-radius: 20px;")
)
)
),
conditionalPanel(
condition = "input.splice_mode == 'Discovery Mode'",
hr(),
tags$p(
list(
"Alternatively, upload your own table with differential splicing values. Table must be directly obtained from ",
tags$a(
href = "https://compbio.imm.medicina.ulisboa.pt/app/betAS",
"betAS",
target = "_blank", # opens in a new tab
style = "color: #007bff; text-decoration: none;" # optional styling
),
"."
)
),
fileInput("user_file_splice", "Upload your file:", accept = c(".txt")),
uiOutput("file_warning_splice"),
uiOutput("user_file_options_splice")
)
)
),
#Right Side, where plots will appear
# Right Side, where plots will appear
column(
width = 9,
tags$h3("Splicing Data Results"),
# --- Explore Mode (default mode, NOT Similar RBPs) ---
conditionalPanel(
condition = "input.splice_mode == 'Explore Mode' && input.splice_dataset != 'Similar RBPs'",
# --- Warning message ---
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
# --- Default Explore-Mode Plots ---
fluidRow(
column(width = 6, plotOutput("violin_splice_plot", height = "400px")),
column(width = 6, plotOutput("plot_shrna_effect", height = "400px"))
),
fluidRow(
column(width = 6, plotlyOutput("plot_splice_volcano", height = "450px")),
column(width = 6, DTOutput("splice_volcano_table"))
),
fluidRow(
column(width = 12, plotOutput("heatmap_splicing_dpsi", height = "600px"))
)
),
# --- Explore Mode: Similar RBPs ---
conditionalPanel(
condition = "input.splice_mode == 'Explore Mode' && input.splice_dataset == 'Similar RBPs'",
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
uiOutput("similar_splice_plots")
),
# --- Discovery Mode ---
conditionalPanel(
condition = "input.splice_mode == 'Discovery Mode'",
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
shinycssloaders::withSpinner(
plotOutput("user_file_initial_plot_splice", height = "420px"),
type = 6
),
br(),
uiOutput("similar_splice_plots_file")
)
)
)
)
),
# Binding tab
tabPanel(
tagList(fa("link", fill = "black", height = "1em"), " Binding"),
fluidPage(
fluidRow(
column(
width = 3,
wellPanel(
radioButtons("binding_eventtype", "Event Type:",
choices = c("Exon Skipping", "Intron Retention"),
selected = "Exon Skipping"),
radioButtons("binding_mode", "Select mode:",
choices = c("Explore Mode", "Discovery Mode"),
selected = "Explore Mode"),
# -------------------------
# EXPLORE MODE
# -------------------------
conditionalPanel(
condition = "input.binding_mode == 'Explore Mode'",
selectInput("binding_dataset", "Select option:",
choices = c("Both Cells", "K562", "HEPG2", "Similar RBPs")),
div(
style = "display: flex; align-items: center; margin-top: 15px;",
selectizeInput("binding_search", NULL,
choices = NULL, multiple = FALSE,
options = list(placeholder = "RBP"),
width = "400px"),
actionButton("search_btn",
tagList(fa("search"), " Search"),
class = "btn btn-primary",
style = "margin-left: 10px; border-radius: 20px;"),
actionButton("reset_btn",
tagList(fa("redo"), " Reset"),
class = "btn btn-secondary",
style = "margin-left: 10px; border-radius: 20px;")
),
# Show only when not "Similar RBPs"
conditionalPanel(
condition = "input.binding_dataset != 'Similar RBPs'",
uiOutput("binding_target_ui"),
uiOutput("binding_dpsi_ui"),
selectInput("binding_metric", "Metric:",
choices = c("FDR", "EffectSize"),
selected = "FDR")
)
),
# -------------------------
# DISCOVERY MODE
# -------------------------
conditionalPanel(
condition = "input.binding_mode == 'Discovery Mode'",
hr(),
tags$p("Alternatively, upload your own table with differential splicing values."),
fileInput("user_file_binding", "Upload your file:", accept = c(".txt")),
uiOutput("file_warning_binding")
)
)
),
# =========================================================
# RIGHT SIDE: RESULTS + PLOT AREA
# =========================================================
column(
width = 9,
tags$h3("Binding Data Results"),
div(
"⚠ Please press reset after every plot!",
style = "border: 2px solid #f0ad4e;
background-color: #fff3cd;
padding: 8px;
border-radius: 6px;
font-weight: bold;
color: #856404;
margin-bottom: 10px;"
),
uiOutput("binding_plot_ui")
)
)
)
),
# Network tab
tabPanel(
tagList(fa("project-diagram", fill = "black", height = "1em"), " Network"),
fluidPage(
fluidRow(
column(
width = 3,
wellPanel(
radioButtons("network_mode", "Select mode:", choices = c("Explore Mode", "Discovery Mode"), selected = "Explore Mode"),
conditionalPanel(
condition = "input.network_mode == 'Explore Mode'",
selectInput("network_dataset", "Select option:", choices = c("Both Cells", "K562", "HEPG2", "Similar RBPs")),
div(
style = "display: flex; align-items: center; margin-top: 15px;",
selectizeInput("network_search", NULL, choices = NULL, multiple = FALSE, options = list(placeholder = "RBP"), width = "400px"),
actionButton("search_btn", tagList(fa("search"), " Search"), class = "btn btn-primary", style = "margin-left: 10px; border-radius: 20px;"),
actionButton("reset_btn", tagList(fa("redo"), " Reset"), class = "btn btn-secondary", style = "margin-left: 10px; border-radius: 20px;")
)
)
)
),
column(width = 9, tags$h3("Network Results"), tags$p("Network-related results will appear here."))
)
)
)
),
# GitHub link floating across ALL tabs
tags$div(
style = "
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
background-color: #EAEBEB;
padding: 8px 12px;
border-radius: 10px;
border: 1px solid #2c3e50;
text-align: center;
",
tags$a(
href = "https://github.com/DiseaseTranscriptomicsLab/CHARM",
target = "_blank",
style = "color: black; text-decoration: none;",
fa("github", fill = "black", height = "1.5em"),
" GitHub"
)
)
)
# ---- Server ----
server <- function(input, output, session) {
image_to_ggplot <- function(path) {
img <- png::readPNG(path)
g <- grid::rasterGrob(img, interpolate = TRUE)
ggplot() + annotation_custom(g, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
theme_void()
}
result_splice <- reactiveVal(NULL)
# ---- Helper functions to pick correct dataset ----
# Expression tab
current_charm_expr <- reactive({
req(input$expr_dataset)
switch(input$expr_dataset,
"K562" = Charm.object_K562,
"HEPG2" = Charm.object_HEPG2,
Charm.object)
})
# Splicing tab
current_charm_splice <- reactive({
req(input$splice_dataset)
switch(input$splice_dataset,
"K562" = Charm.object_K562,
"HEPG2" = Charm.object_HEPG2,
Charm.object)
})
current_shrna_expr <- reactive({
req(input$splice_dataset)
switch(input$splice_dataset,
"K562" = sh_effect_vector_K562,
"HEPG2" = sh_effect_vector_HEPG2,
sh_effect_vector)
})
current_shrna_splice <- reactive({
req(input$splice_dataset)
switch(input$splice_dataset,
"K562" = sh_effect_vector_K562,
"HEPG2" = sh_effect_vector_HEPG2,
sh_effect_vector)
})
# Reactive storage
display_table <- reactiveVal(NULL)
rbp_current <- reactiveVal(NULL)
# ---- Search bar population (Expression tab) ----
observe({
req(current_charm_expr(), input$expr_dataset)
# 1️⃣ RBP search bar (depends on selected dataset)
rbp_choices <- names(current_charm_expr())
updateSelectizeInput(
session,
"expr_search_rbp",
choices = rbp_choices,
server = TRUE
)
# 2️⃣ Gene search bar (depends on selected dataset)
gene_choices <- switch(
input$expr_dataset,
"K562" = GenesK562,
"HEPG2" = GenesHEPG2,
GenesBoth # default for "Both Cells" or anything else
)
updateSelectizeInput(
session,
"expr_search_gene",
choices = sort(unique(gene_choices)),
server = TRUE
)
# 3️⃣ Hallmark Gene Set search bar (always from RBFOX2)
hallmark_choices <- Charm.object[["RBFOX2"]]$GSEA$pathway
updateSelectizeInput(
session,
"expr_search_hallmark",
choices = sort(unique(hallmark_choices)),
server = TRUE
)
})
# ---- Search bar population (Splicing tab) ----
observe({
req(current_charm_splice())
rbp_choices_splice <- names(current_charm_splice())
updateSelectizeInput(
session,
"splice_search",
choices = rbp_choices_splice,
server = TRUE
)
rbp_choices_similar <- names(current_charm_splice())
updateSelectizeInput(session, "similar_rbps_select_splice", choices = rbp_choices_similar)
})
# ---- Populate Event ID choices based on dataset ----
observe({
req(current_charm_splice())
req(input$splice_dataset)
event_choices <- switch(
input$splice_dataset,
"Both Cells" = EventsBoth,
"K562" = EventsK562,
"HEPG2" = EventsHEPG2,
NULL
)
updateSelectizeInput(
session,
"splice_search_event", # must match UI
choices = event_choices,
server = TRUE
)
})
# ---- Event ID Search button ----
observeEvent(input$search_btn_event, {
req(input$splice_search_event)
event_id <- input$splice_search_event
charm_obj <- current_charm_splice()
output$heatmap_splicing_dpsi <- renderPlot({
plot_event_dpsi_barplot(charm_obj, event_id)
})
})
###EXPRESSION (user File)
upload_ok <- reactiveVal(FALSE)
user_expr_df <- reactiveVal(NULL)
observeEvent(input$user_file_expr, {
req(input$user_file_expr)
file_path <- input$user_file_expr$datapath
df <- tryCatch(
read.table(file_path, header = FALSE, sep = "\t", stringsAsFactors = FALSE),
error = function(e) NULL
)
if (is.null(df)) {
upload_ok(FALSE)
user_expr_df(NULL)
error_msg <- "Could not read the file. Make sure it is tab-delimited."
} else if (ncol(df) != 2) {
upload_ok(FALSE)
user_expr_df(NULL)
error_msg <- "File must have exactly 2 columns."
} else if (!is.character(df[[1]])) {
upload_ok(FALSE)
user_expr_df(NULL)
error_msg <- "First column must be character (gene names)."
} else if (!is.numeric(df[[2]])) {
upload_ok(FALSE)
user_expr_df(NULL)
error_msg <- "Second column must be numeric (t-statistics)."
} else {
colnames(df) <- c("Gene", "t")
upload_ok(TRUE)
user_expr_df(df) # save dataframe globally
error_msg <- NULL
}
output$file_warning_expr <- renderUI({
if (upload_ok()) {
div(style="color:green;font-weight:bold;margin-top:10px;", "Upload complete!")
} else {
div(style="color:red;font-weight:bold;margin-top:10px;", paste("Upload failed:", error_msg))
}
})
})
# Only show extra options if upload is successful
output$user_file_options <- renderUI({
if (!upload_ok()) return(NULL)
tagList(
radioButtons(
inputId = "user_file_mode_expr",
label = "Select correlation type:",
choices = c("By Gene Expression" = "expr",
"By Gene Set Enrichment" = "gsea"),
selected = "expr",
inline = TRUE
),
# Gene Expression options
conditionalPanel(
condition = "input.user_file_mode_expr == 'expr'",
selectizeInput(
inputId = "user_file_compare_expr",
label = "Compare with specific RBPs (optional)",
choices = names(Charm.object),
multiple = TRUE,
options = list(placeholder = "Select one or more RBPs")
),
numericInput(
"user_file_topN_expr",
"Show top N correlated RBPs (optional):",
value = NA, min = 1
),
helpText("Tip: By selecting a number here, this will take precedence over the two inputs below."),
numericInput(
"user_file_n_pos_expr",
"Show top N positive correlations (optional):",
value = NA, min = 1
),
numericInput(
"user_file_n_neg_expr",
"Show top N negative correlations (optional):",
value = NA, min = 1
),
helpText("Tip: You may use one or both of the numeric inputs above."),