-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOmicsVolcano_v1_1_Server.r
2939 lines (2451 loc) · 144 KB
/
OmicsVolcano_v1_1_Server.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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# OmicsVolcano V1.1
#
# UPDATED !!!!!!!!!!!!!!!!!!!!
#
# The initial version of OmicsVolcano used shinydashboardPlus() v.0.7.5 function,
# which has been depreciated.
# The software has updated version of shinydashboardPlus() v.2.0.0 now.
#
# rightSidebar() is replaced with dashboardControlbar()
#
# fontawesome package has been added | packageVersion("fontawesome") - '0.2.2'
#
# The software has been tested on R version 4.1.1 (2021-08-10) "Kick Things"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ====================================================================
# ====================================================================
# ====================================================================
# Title: OmicsVolcano
# Copyright: (C) 2020
# License: GNU General Public
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# NON-ACADEMICS:
# CONTACT authors/software developers for any COMMERCIAL USE
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# ====================================================================
# ====================================================================
# ====================================================================
# ====================================================================
# ====================================================================
# ====================================================================
# Script Developers
# ====================================================================
# ====================================================================
# ====================================================================
# Author: Irina Kuznetsova
# email: [email protected]
# Co-developer: Artur Lugmayr
# email: [email protected]
# Edith Cowan University, WA, AUSTRALIA
# Umea University, Umea, Sweden
# UXMachines Pty Ltd. WA, AUSTRALIA
# ====================================================================
# ====================================================================
# ====================================================================
# License
# ====================================================================
# ====================================================================
# ====================================================================
# OmicsVolcano is visualization software that enables to explore interactively
# volcano plot for presence of mitochondrial localized genes or proteins.
#
# Copyright (C) 2020 Irina Kuznetsova
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Debugging mode only - set TRUE if debugging information should be displayed
DEBUGGING_MODE = TRUE
# ====================================================================
# ====================================================================
# ====================================================================
# I VARIABLES
# ====================================================================
# ====================================================================
# ====================================================================
ui_mmp_names = list( "Amino Acid Metabolism", "Apoptosis","Bile Acid Synthesis", "Calcium Signaling & Transport",
"Cardiolipin Biosynthesis", "Fatty Acid Biosynthesis & Elongation", "Fatty Acid Degradation & Beta-oxidation",
"Fatty Acid Metabolism", "Fe-S Cluster Biosynthesis", "Folate & Pterin Metabolism", "Fructose Metabolism",
"Glycolysis", "Heme Biosynthesis","Import & Sorting", "Lipoic Acid Metabolism", "Metabolism of Lipids & Lipoproteins",
"Metabolism of Vitamins & Co-Factors", "Mitochondrial Carrier", "Mitochondrial Dynamics", "Mitochondrial Gene Expression",
"Mitochondrial Signaling", "Mitophagy", "Nitrogen Metabolism", "Nucleotide Metabolism", "Oxidative Phosphorylation",
"Pentose Phosphate Pathway","Protein Stability & Degradation", "Pyruvate Metabolism", "Replication & Transcription",
"Ribosomal", "ROS Defense", "Transcription (nuclear)", "Translation", "Transmembrane Transport", "Tricarboxylic Acid Cycle",
"Ubiquinone Biosynthesis", "Unknown MT process", "UPRmt", "Translation (MT)", "Oxidative Phosphorylation (MT)")
# ====================================================================
# ====================================================================
# ====================================================================
# II Reference Files MOUSE
# ====================================================================
# ====================================================================
# ====================================================================
mm_ribos_file = read.table("./ReferenceFiles/Mouse/mm_Ribosomal_processes19March20.txt",
header = T,
sep = "\t",
fill = T,
quote = "") # dim = 82 x 3 | yourlist Entry Entry.name Protein.names Gene.names Organism
mm_processes_file = read.table("./ReferenceFiles/Mouse/mm_MitoCarta_MitoXplorer_AF_2April2020.txt",
header = T,
sep = "\t",
fill = T,
quote = "") # dim = 1495 x 3 | GeneID Symbol Description Synonyms Maestro.score FDR Evidence Tissues
# ====================================================================
# ====================================================================
# ====================================================================
# II Reference Files HUMAN
# ====================================================================
# ====================================================================
# ====================================================================
hs_ribos_file = read.table("./ReferenceFiles/Human/hs_ribosomal_30March2020.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[, c(2,3,4)] # dim = 82 x 4
hs_processes_file = read.table("./ReferenceFiles/Human/hs_MitoCarta_MitoXplorer_AF_2April2020.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3)] # dim(1516 5)
# # Cellular compartmen localization (NOTE: HUMAN ONLY)
# 1) ACTIN
hs_actin_file = read.table("./ReferenceFiles/Human/actin_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 237 5 head(hs_actin_file);dim(hs_actin_file)
# 2) centrosome
hs_centrosome_file = read.table("./ReferenceFiles/Human/centrosome_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 359 4 head(hs_centrosome_file);dim(hs_centrosome_file)
# 3) cytosol_hs.txt
hs_cytosol_file = read.table("./ReferenceFiles/Human/cytosol_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 4395 5 head(hs_cytosol_file); dim(hs_cytosol_file)
# 4) ER_hs.txt
hs_ER_file = read.table("./ReferenceFiles/Human/ER_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 466 5 head(hs_ER_file);dim(hs_ER_file)
# 5) golgi_hs.txt
hs_golgi_file = read.table("./ReferenceFiles/Human/golgi_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 1030 5 head(hs_golgi_file);dim(hs_golgi_file)
# 6) intermediate_hs.txt"
hs_intermediate_file = read.table("./ReferenceFiles/Human/intermediate_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 191 5 head(hs_intermediate_file);dim(hs_intermediate_file)
# 7) microtubules_hs.txt
hs_microtubules_file = read.table("./ReferenceFiles/Human/microtubules_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 253 5 head(hs_microtubules_file);dim(hs_microtubules_file)
# 8) mito_hs.txt
hs_mito_file = read.table("./ReferenceFiles/Human/mito_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 1098 5 head(hs_mito_file);dim(hs_mito_file)
# 9) nucleoli_hs.txt
hs_nucleoli_file = read.table("./ReferenceFiles/Human/nucleoli_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 1027 5 head(hs_nucleoli_file);dim(hs_nucleoli_file)
# 10) nucmembrane_hs.txt
hs_nucmembrane_file = read.table("./ReferenceFiles/Human/nucmembrane_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 270 5 head(hs_nucmembrane_file); dim(hs_nucmembrane_file)
# 11) plasma_hs.txt
hs_plasma_file = read.table("./ReferenceFiles/Human/plasma_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] #1707 5 head(hs_plasma_file); dim(hs_plasma_file)
# 12) hs_vesicles_file
hs_vesicles_file = read.table("./ReferenceFiles/Human/vesicles_hs.txt",
header = T,
sep = "\t",
fill = T,
quote = "")[,c(1,2,3,4)] # 1930 5 head(hs_vesicles_file);dim(hs_vesicles_file)
# Create a list that contains
# Cell.name and related genes
list_of_cellular_values =list("Actin" = hs_actin_file$Gene,
"Centrosome" = hs_centrosome_file$Gene,
"Cytosol" = hs_cytosol_file$Gene,
"ER" = hs_ER_file$Gene,
"Golgi" = hs_golgi_file$Gene,
"Intermediate" = hs_intermediate_file$Gene,
"Microtubules" = hs_microtubules_file$Gene,
"Mito" = hs_mito_file$Gene,
"Nucleoli" = hs_nucleoli_file$Gene,
"Nucmembrane" = hs_nucmembrane_file$Gene,
"Plasma" = hs_plasma_file$Gene,
"Vesicles" = hs_vesicles_file$Gene)
name_list_of_cellular_values = list("Actin Filaments", "Centrosome", "Cytosol", "Endoplasmic Reticulum", "Golgi Apparatus", "Intermediate Filaments",
"Microtubules", "Mitochondria", "Nucleoli", "Nuclear Membrane", "Plasma Membrane", "Vesicles")
# ====================================================================
# ====================================================================
# ====================================================================
# Error handling
# ====================================================================
# ====================================================================
# ====================================================================
displayErrorMessage = function (messagesubject, message, errortrace) {
showModal(modalDialog(
title = messagesubject,
fade = TRUE,
easyClose = TRUE,
message,
footer = tagList(modalButton("Close")) )) }
# ====================================================================
# ====================================================================
# ====================================================================
# SERVER BODY
# ====================================================================
# ====================================================================
# ====================================================================
server = function(input, output, session) {
if(DEBUGGING_MODE) {
Sys.time()
print("server")
}
# ===================================================================================================================================
# ===================================================================================================================================
# 0. UI Front-End Handling
# ===================================================================================================================================
# ===================================================================================================================================
# Initialize UI default values
DEFAULT_STATUS_MESSAGE = "Ok."
UI_STATUS_LIST = c("General", "Plot")
UI_STATUS = "General"
UI_RIGHTDASBOARD_HELP_TEXT = "No info available."
UI_NOTIFICATIONS = c( c("Application Started!", "thumbs-up") )
# Initialize the status bar
output$UI_INFO_PROCESS = renderInfoBox({
infoBox ("Process",
paste0 ("Mouse"),
paste0 ("Show All Mitochondrial Genes"),
icon = icon("fas fa-filter"),
color = "yellow") })
output$UI_INFO_GENERAL = renderInfoBox ({
infoBox ("Threshold/Signficance",
paste0 (input$VerticalThreshold),
paste0 (input$Signif),
icon = icon ("tachometer-alt"),
color = "yellow") })
output$UI_INFO_FILENAME = renderInfoBox ({
infoBox ("Filename",
paste0 (input$UI_INPUT_FILE_NAME),
icon = icon ("database"),
color = "yellow") })
output$UI_INFO_EXPLORE = renderInfoBox ({
infoBox ("Explore",
"Manual List",
icon = (icon("list-ol")),
color = "yellow") })
output$ui_status_box_message = renderText(
{ paste0(DEFAULT_STATUS_MESSAGE) } )
displayUIStatusMessage = function(message, error) {
output$ui_status_box_message = renderText({paste0(message)})}
displayUIRightDashboardMenue = function (info_text) {
output$UI_RIGHT_DASBOARD_HELP_TEXT = renderText({paste0(info_text)})
output$UI_RIGHT_DASBOARD_CONTENT = renderUI({
input$ui_threshold_configuration # sliderInput("n", "N", 1, 1000, 500)
} )}
output$UI_NOTIFICATIONS = renderMenu ( {
dropdownMenu (
type = "notifications",
notificationItem(
text = "Applications successfuly started",
icon("thumbs-up") )) })
# CONTEXTUALIZED RIGHT MENUE DEPENENDENT WHAT IS SELECTED ON THE LEFT MENUE
UI_INFO_TEXTS = list(
menue_tab_file_open = ("Open data file"),
menue_tab_file_close = ("close data file"),
menue_tab_exp_plot = ("Plot and explore data"),
menue_tab_exp_genelist = ("Explore gene list"),
menue_tab_exp_mitproc = ("Mitochondrial process explorer"),
menue_tab_exp_multiple_mitoprocesses = ("Mitochondrial multi processes explorer"),
menue_tab_exp_cellular_compartment = ("Cellular compartment localization explorer"),
menue_tab_download_plot = ("Download data plot"),
menue_tab_download_table = ("Download data tables"),
menue_tab_help = ("Help page"),
menue_tab_about = ("About page") )
# UPDATE THE RIGHT CONTEXT MENUE dependent on which left menue in the dashboard has been selected
observeEvent(input$ui_dashboard_sidebar, {
print(input$ui_dashboard_sidebar)
x = UI_INFO_TEXTS["input$ui_dashboard_sidebar"]
if (is.null(x)) { x=""}
output$UI_RIGHT_DASHBOARD_HELP_TEXT = renderText({paste0( x )})
x="UI_RIGHT_SIDEBAR_NONE"
if ( (input$ui_dashboard_sidebar == "menue_tab_exp_plot") | (input$ui_dashboard_sidebar == "menue_tab_exp_genelist") | (input$ui_dashboard_sidebar == "menue_tab_exp_mitproc") | (input$ui_dashboard_sidebar == "menue_tab_exp_multiple_mitoprocesses") | (input$ui_dashboard_sidebar == "menue_tab_exp_cellular_compartment") )
{ x = input$ui_dashboard_sidebar}
updateTabsetPanel(session, "UI_RIGHT_SIDEBAR_SELECTMODE", selected = x) })
# Status box upldates: Mitochondria process
observeEvent(input$OrganismSource, {
output$UI_INFO_PROCESS = renderInfoBox ({
infoBox ( "Process",
paste (input$OrganismSource),
paste (input$MtProcess),
icon = icon("fas fa-filter"),
color = "yellow")
}) })
observeEvent(input$MtProcess, {
output$UI_INFO_PROCESS = renderInfoBox ({
infoBox ("Process",
paste (input$OrganismSource),
paste (input$MtProcess),
icon = icon("fas fa-filter"),
color = "yellow")
}) })
observeEvent(input$VerticalThreshold, {
output$UI_INFO_GENERAL = renderInfoBox ({
infoBox ( title = "Log2FC and Significance",
value = paste0 ("+/-", input$VerticalThreshold, ""),
subtitle = paste0 (input$Signif),
icon = icon("tachometer-alt"),
color = "yellow")
}) })
observeEvent(input$UI_INPUT_FILENAME, {
output$UI_INFO_FILENAME = renderInfoBox ( {
infoBox ("Filename",
paste0 (input$UI_INPUT_FILENAME),
icon = icon("database"),
color = "yellow")
}) })
observeEvent(input$CustomInputOptions, {
if (input$CustomInputOptions == "Insert a list of genes") {
output$UI_INFO_EXPLORE = renderInfoBox ({
infoBox ( "Explore",
"Manual List",
paste0 (input$CustomList),
icon = (icon("list-ol")),
color = "yellow") })
}
else
{output$UI_INFO_EXPLORE = renderInfoBox ({
infoBox ("Explore",
"File",
icon = (icon("list-ol")),
color = "yellow") })
} })
# exit button pressed
observeEvent(input$ExitApplication, {
quit(0) })
observeEvent( input$CustomList, ({
print( paste("Custom List Selected", input$CustomList))
}) )
observeEvent( input$UserGeneNamesFile, ({
print( paste("Custom List Selected", input$UserGeneNamesFile)) }) )
# Raise error if file is not uploaded
observeEvent(input$ui_dashboard_sidebar, {
if ( is.null(input$UI_INPUT_FILE_NAME$datapath) & input$ui_dashboard_sidebar=="menue_tab_exp_plot"){
displayErrorMessage("Input file is not uploded!", "Please use File tab to upload your file.", "")
return(NULL)}
else if (is.null(input$UI_INPUT_FILE_NAME$datapath) & input$ui_dashboard_sidebar=="menue_tab_exp_genelist"){
displayErrorMessage("Input file is not uploded!", "Please use File tab to upload your file.", "")
return(NULL)}
else if (is.null(input$UI_INPUT_FILE_NAME$datapath) & input$ui_dashboard_sidebar=="menue_tab_exp_mitproc"){
displayErrorMessage("Input file is not uploded!", "Please use File tab to upload your file.", "")
return(NULL)}
else if (is.null(input$UI_INPUT_FILE_NAME$datapath) & input$ui_dashboard_sidebar=="menue_tab_exp_multiple_mitoprocesses"){
displayErrorMessage("Input file is not uploded!", "Please use File tab to upload your file.", "")
return(NULL)}
else if (is.null(input$UI_INPUT_FILE_NAME$datapath) & input$ui_dashboard_sidebar=="menue_tab_exp_cellular_compartment"){
displayErrorMessage("Input file is not uploded!", "Please use File tab to upload your file.", "")
return(NULL)}
})
# ===================================================================================================================================
# 2. The function takes the complete list of input values and creates
# a data frame for further processing.
# vl: global value, reactiveValuesToList(input)
# RETURNS: a data frame with the input$ values as value-key pairs
# ===================================================================================================================================
convertValueListToDF = function(vl) {
if (DEBUGGING_MODE) {
Sys.time()
print("convertValueListToDF")
}
if (!is.null(vl)) {
df = data.frame(matrix(ncol = 2,
nrow = length(vl))) # create a data frame
colnames(df) = c("IDs","Value")
df$IDs = names(vl)
df$Value = lapply(1:length(vl), function (x) { values = vl[[x]]})
return(df)
}
return (null)
}
# ===================================================================================================================================
# 3. The function takes a data frame which consists of value-key pairs
# and compares it to the second string
# INPUT: df - data frame with key-value pairs
# INPUT: st - string value to compare to
# RETURNS: the value of the key st that is contained in the df., NULL if not present
# ===================================================================================================================================
getValueOfDF = function(df, st){
if (DEBUGGING_MODE) {
Sys.time()
print("getValueOfDF")
}
for (x in (1:dim(df)[1])){
# ARL STRING COMPARISON HERE
if (st == df[x,1]) {
# print("st")
# print(st)
# print("df")
# print(df[x,1])
# print(df[x,2])
return (unlist(df[x, 2]))
}
}
return (NULL)
}
# ===================================================================================================================================
# 4. BUILD DATA FRAME OF SELECTED MULTIPLE PROCESSES WITH SELECTED COLOR | reactiveValues
# ===================================================================================================================================
getMMPValuesSelected = function () {
if (DEBUGGING_MODE) {
Sys.time()
print("getMMPValuesSelected")
}
df_valueKeysList = convertValueListToDF(reactiveValuesToList(input)) # IDs Value
df_result = data.frame(MMPRow=numeric(0),
CheckBoxID=character(0),
CheckBoxVal=logical(0),
ColID=character(0),
ColValue=character(0),
ProcessName=character(0)) # create a data frame
for (val in (1:length(ui_mmp_names))){
cb_id = paste0("UI_MMP_LIST_CHECKBOX_", val)
col_id = paste0("UI_MMP_LIST_COLORPICKER_", val)
cb_val = getValueOfDF(df_valueKeysList, cb_id)
if (is.logical(cb_val) & cb_val!="FALSE") { # ARTUR as.logical(cb_val)
#if (is.logical(cb_val)) { # is.logical returns TRUE or FALSE depending on whether its argument is of logical type or not.
col_val = getValueOfDF(df_valueKeysList, col_id)
proc_name = unlist(ui_mmp_names)[val]
df_result = rbind (df_result, data.frame(MMPRow = val,
CheckBoxID = cb_id,
CheckBoxVal= as.logical(cb_val),
ColID = col_id,
ColValue = col_val,
ProcessName= proc_name))
}
}
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print(df_result)
return(df_result)
}
# ====================================================================
# ====================================================================
# ====================================================================
# EXPLORE CELLULAR COMPARTMENT LOCALIZATION
# ====================================================================
# ====================================================================
# ====================================================================
# #================================================================================================================
# # 1. CELLULAR COMPARTMENT LOCALIZATION WIDGET (right-hand widget appearance)
# #================================================================================================================
# ====================================================================
# ====================================================================
# ====================================================================
# 1. SUBSET DATA to SIGNIFICANT, PROCESSES
# ====================================================================
# ====================================================================
# ====================================================================
#================================================================================================================
# 1.0 PARSE INPUT FILE provided by the user
#================================================================================================================
DataInputFile = reactive ({
if (DEBUGGING_MODE) {
Sys.time()
print("DataInputFile()")
}
# Ensure that required values are available
req(input$UI_INPUT_FILE_NAME$datapath)
# specify your location in the script
print("DataInputFile() Reactive:")
print(input$UI_INPUT_FILE_NAME$datapath)
print(input$UI_INPUT_FILE_SEPARATOR)
print(input$UI_INPUT_FILE_REMOVE_DUPLICATES)
print("END ---- DataInputFile() Reactive: -------")
print("-------------------------------------------")
# handling errors and warnings
tryCatch({
# IF CHECK FOR THE FILE
# parse file
df = read.csv(file = input$UI_INPUT_FILE_NAME$datapath,
sep = input$UI_INPUT_FILE_SEPARATOR,
header = T,
quote = "")
# browser()
# I.Number of columns
if (!ncol(df) ==5){
displayErrorMessage("File Loading Error in Data Input File!", "Please check number of columns or select correct field separator character. Alternatively, review the Help Page for the file input format", "")
return(NULL)
}
# II.Column names
else if ( !names(df)[1]=="ID"){
displayErrorMessage( "File Formatting Error", paste("Please check the name of the 1st column. It is ID, not", names(df)[1], sep=" "), "")
return(NULL)
}
else if (!names(df)[2]=="GeneSymbol"){
displayErrorMessage("File Formatting Error", paste("Please check the name of the 2nd column. It is GeneSymbol, not", names(df)[2], sep=" "), "")
return(NULL)
}
else if (!names(df)[3]=="Description"){
displayErrorMessage("File Formatting Error", paste("Please check the name of the 3rd column. It is Description, not", names(df)[3], sep=" "), "")
return(NULL)
}
else if (!names(df)[4]=="Log2FC"){
displayErrorMessage("File Formatting Error", paste("Please check the name of the 4th column. It is Log2FC, not", names(df)[4], sep=" "), "")
return(NULL)
}
else if (!names(df)[5]=="AdjPValue"){
displayErrorMessage("File Formatting Error", paste("Please check the name of the 5th column. It is AdjPValue, not", names(df)[5], sep=" "), "")
return(NULL)
}
# III. IF CHECK FOR DUPLICATES BOX IS TICKED
else if (input$UI_INPUT_FILE_REMOVE_DUPLICATES==TRUE) {
df_dup = df %>%
mutate( GeneSymbol = make.unique( sapply(strsplit( as.character(df$GeneSymbol),";"), `[`, 1) , sep=".") ) %>% # Add numeric extention to duplicated gene name
mutate( GeneSymbol = gsub(".*NA.*", "NA" , GeneSymbol))
# browser()
# Represent Gene Symbols that are not available as NA
displayUIStatusMessage("File Loading Successful!", FALSE)
output$UI_INPUT_FILE_RESULTS = renderDT(DataInputFile())
return(df_dup)}
else {
displayUIStatusMessage("File Loading Successful!", FALSE)
output$UI_INPUT_FILE_RESULTS = renderDT(DataInputFile())
return(df)}
},
error = function(e) {
displayErrorMessage("File Loading Error in Data Input File!", "Please choose the correct file separator! Alternatively, review the Help Page for the file input format", "")})
})
#================================================================================================================
# 1.1 SUBSET input data to SIGNIF. threshold
#================================================================================================================
FilteredToSignif = reactive({
if (DEBUGGING_MODE) {
Sys.time()
print("FilteredToSignif()")
}
# Ensure that required values are available
req(DataInputFile())
req(input$Signif)
# specify your location in the script
print("FilteredToSignif Reactive:")
print("----")
tryCatch({
# Filter to significant
signif = DataInputFile() %>%
filter( AdjPValue < input$Signif,
!is.na(AdjPValue))
return(signif[,c(1,2,4,5,3)])
},
error = function(e) {
displayErrorMessage("File Loading Error in Data Input File!",
"Check the Help Page for the file input format, column names", "")}
) })
#================================================================================================================
# 1.1.0 OUTPUT SIGNIF. to TABs: "Explore Plot Values" AND to "Explore Mitochondrial Processes"
#================================================================================================================
output$SignifData1 = output$SignifData3 = renderDT({ FilteredToSignif() })
df_subset_input_to_reffiles = function(inputdata, mitorefprocesses, ribosomref){
# 0. FUNCTION TASK:
# This function takes INPUT file and subsets to Mito ref. and Ribosomal/OXPHOs ref.files
# 1. FUNCTION ARGUMENTS:
# A) inputdata = DataInputFile()
# Mouse or Human data
# B) mitorefprocesses = mm_processes_file | hs_processes_file
# C) ribosomref = mm_ribos_file | hs_ribos_file
# 2. FUNCTION BODY:
# MitoCarta ref.file
upperCase = mutate( inputdata, upcase = toupper(GeneSymbol) )
mtfunct_in = upperCase %>% filter(upcase %in% toupper(mitorefprocesses$GeneName))
processdata_in = merge.data.frame(mtfunct_in, mitorefprocesses[,c(1,3)], by.x = "upcase", by.y = "GeneName") #processdata_in[ , c(3,2,7,5,6,4)]
# Ribosom and OXPHOs ref.files
mm_ribos_file_upper= mutate( mm_ribos_file, GeneName = toupper(GeneName) )
mtfunct_rib = upperCase %>% filter(upcase %in% toupper(mm_ribos_file_upper$GeneName)) # dim(mtfunct_rib) # 58 6
processdata_rib = merge.data.frame(mtfunct_rib, mm_ribos_file_upper[,c(1,3)], by.x = "upcase", by.y = "GeneName") #processdata_rib[1:5 , c(3,2,7,5,6,4)] # 58 7
# Assemble result
final_processes = rbind(processdata_in, processdata_rib)
# browser()
# 3. RETURN VALUE:
return(final_processes[,c(2,3,5,6,4,7)])
}
#================================================================================================================
# 1.2 COMBINE MT PROCESSES, such as MitoCarta + MitoXplorer AND Ribosomal
#================================================================================================================
MitoProcesses = reactive ({
# MitoProcesses = observe ({
if (DEBUGGING_MODE) {
Sys.time()
print("MitoProcesses()")
}
# Ensure that required values are available
req(DataInputFile())
req(input$OrganismSource)
# specify your location in the script
print("MitoProcesses Reactive:")
print(input$OrganismSource)
print("END ---- MitoProcesses Reactive: -----")
print("-------------------------------------------")
tryCatch({
# Mouse
if (input$OrganismSource == "Mouse" & !is.null(DataInputFile()) ){
df_subset_input_to_reffiles(DataInputFile(), mm_processes_file, mm_ribos_file)
# browser()
}
# Human
else if (input$OrganismSource == "Human" & !is.null(DataInputFile()) ){
df_subset_input_to_reffiles(DataInputFile(), hs_processes_file, hs_ribos_file)
}
# Mouse & NO INPUT
else if (input$OrganismSource == "Mouse" & is.null(DataInputFile()) ){
return(NULL)}
# Human & NO INPUT
else if (input$OrganismSource == "Human" & is.null(DataInputFile()) ){
return(NULL)}
},
error = function(e) {
displayErrorMessage("File Loading Error in Data Input File!",
"Check the Help Page for the file input format, column names. /// MitoProcesses function |dependencies: df_subset_input_to_reffiles()", "")}
)
})
#================================================================================================================
# 1.2.0 OUTPUT PROCESSES
#================================================================================================================
output$ProcessesData3 = renderDT({
MitoProcesses() })
#================================================================================================================
# Subset input data to selected ONE process
#================================================================================================================
MitoProcessesTableRes = reactive ({
#MitoProcessesTableRes = observe ({
# Ensure that required values are available
req(MitoProcesses())
req(input$MtProcess)
# specify your location in the script
print("MitoProcessesTableRes Reactive:")
print(input$MtProcess)
print("END ---- MitoProcessesTableRes Reactive: -----")
print("-------------------------------------------")
SelectedProcess=MitoProcesses()[as.character(MitoProcesses()$Process) %in% input$MtProcess, ]
#browser()
return(SelectedProcess)
})
output$ProcessesDataSubset3 = renderDT({
MitoProcessesTableRes() })
#================================================================================================================
#================================================================================================================
#================================================================================================================
# 2.0 Create data frame with identifier for visualization
# TASK: Take input data and assign color according its significance values: blue, red, grey
#================================================================================================================
#================================================================================================================
DataFrameWithColors = reactive({
# DataFrameWithColors = observe({
# Ensure that required values are available
req(DataInputFile())
req(input$Signif)
req(input$VerticalThreshold)
# specify your location in the script
print("DataFrameWithColors Reactive:")
print(input$Signif)
print("END DataFrameWithColors----")
print("-------------------------------------------")
# 2.0.0 Initialize input variables
tryCatch ({
if (is.null(DataInputFile())){
return(NULL) }
else {
# 2.0.4 Add column that contains information about signif-negative, signif-positiv, not signif + signif
inputdata = DataInputFile()
logFC_threshold_pos = as.numeric(input$VerticalThreshold) # logFC_threshold_pos = 1
logFC_threshold_neg = -logFC_threshold_pos # logFC_threshold_neg = -(logFC_threshold_pos)
signif_threshold = input$Signif # signif_threshold = 0.05
# 2.0.5 1-SIGNIF. positive | prot_in$Log2FC > neg_val & prot_in$AdjPValue < input$Signif))] = sign_pos_color
positiv_signif = inputdata %>%
filter( Log2FC > logFC_threshold_pos & AdjPValue < signif_threshold) %>%
mutate(CharValue = "red")
# 2.0.6 2-SIGNIF. negative | prot_in$Log2FC < -neg_val & prot_in$AdjPValue < input$Signif))] = sign_neg_color
neg_signif = inputdata %>%
filter( Log2FC < logFC_threshold_neg & AdjPValue < signif_threshold) %>%
mutate(CharValue = "blue")
# 2.0.7 3-NOT SIGNIF between [-1;+1]
notsignif1 = inputdata %>%
filter( AdjPValue < signif_threshold & Log2FC >= logFC_threshold_neg,
AdjPValue < signif_threshold & Log2FC <= logFC_threshold_pos) %>%
mutate(CharValue = "grey")
# 2.0.8 4-NOT SIGNIF NA are excluded
notsignif2 = inputdata %>%
filter( AdjPValue > signif_threshold) %>%
mutate(CharValue = "grey")
# 2.0.9 5-SUBSET to NA
na_data = inputdata %>%
filter(is.na(AdjPValue) | is.na(Log2FC)) %>%
mutate(CharValue = "grey2")
# 2.1.0 6-COMBINE ALL filtered data
df_color = rbind(positiv_signif, neg_signif, notsignif1, notsignif2, na_data)
# browser()
return(df_color) # ID - GeneSymbol - Log2FC - AdjPValue - Description - CharValue
}
}, error = function(e) {
displayErrorMessage("File Loading Error in Data Input File!",
"Check the Help Page for the file input format, column names. /// DataFrameWithColors function", "")}
)
})
#================================================================================================================
# 2.1 CROSSTALK :) # https://rstudio.github.io/crosstalk/shiny.html
#================================================================================================================
DataSharedWithColors = SharedData$new(DataFrameWithColors)
#================================================================================================================
# 2.2 REACTIVE VALUE, so plot can be saved
#================================================================================================================
StorePlotForExplore = reactiveValues()
plot_colour_distrib = function(inputdatawithcolors){
# 0. FUNCTION TASK:
# This function creates a vector of colors for the plot and takes into consideration variouse scenarios of data and colors:
# 1) data has blue - grey - white - red values
# 2) NO BLUE (neg signif), grey - white - red
# 3) NO RED (pos signif), blue - grey - white
# 4) blue - grey - red
# 5) grey white
# 6) blue - red
# 1. FUNCTION ARGUMENTS:
# A) inputdatawithcolors = DataFrameWithColors()
# 2. FUNCTION BODY: color distribution
colorvec = unique(inputdatawithcolors$CharValue) # color order: red blue grey grey2
plot_color_values = c() # initialize empty vector
# all values: left sig NA right
if ( length(colorvec)==4){
plot_color_values = c(plot_color_values, c("#9fd8fb", "#cccccc", "white", "#ffcccc")) # => reverse coloring: blue - grey - white - red
}
# left nsig na ---
else if (length(colorvec)==3 & (colorvec[1]=="red") & (!colorvec[2]=="blue")){
plot_color_values = c(plot_color_values, c("#cccccc", "white", "#ffcccc")) # => reverse coloring: grey - white - red
}
# --- nsig na right
else if (length(colorvec)==3 & (colorvec[1]=="blue") & (colorvec[2]=="grey")){
plot_color_values = c(plot_color_values, c("#9fd8fb", "#cccccc", "white")) # => reverse coloring: blue - grey - white
}
# left nsig --- right
else if (length(colorvec)==3 & (!"grey2" %in% colorvec) & (colorvec[1]=="red") & (colorvec[2]=="blue") & (colorvec[3]=="grey")){
plot_color_values = c(plot_color_values, c("#9fd8fb", "#cccccc", "#ffcccc")) # => reverse coloring: blue - grey - red
}
# --- nsig NA ---
else if (length(colorvec)==2 & (colorvec[1]=="grey") & (colorvec[2]=="grey2") ){ # => reverse coloring: grey white
plot_color_values = c(plot_color_values, c( "#cccccc", "white"))
}
# left --- --- right
else if (length(colorvec)==2 & (colorvec[1]=="red") & (colorvec[2]=="blue") ){ # => reverse coloring: blue - red
plot_color_values = c(plot_color_values, c( "#9fd8fb", "#ffcccc"))
}
# 3. RETURN VALUE:
return(plot_color_values)
}
#================================================================================================================
# 2.3 VISUALIZATION ("Explore Plot Values")
#================================================================================================================
ExplorePlotVolPplot = reactive({
# ExplorePlotVolPplot = observe({
# Ensure that required values are available
req(DataInputFile())
req(input$Signif)
req(input$VerticalThreshold)
req(DataFrameWithColors())
# specify your location in the script
print("ExplorePlotVolPplot Reactive:")
print("END ---- ExplorePlotVolPplot Reactive: ------")
print("-------------------------------------------")
# 0 Initialised parameters
sigval = input$Signif
logFC_threshold_pos = as.numeric(input$VerticalThreshold)
logFC_threshold_neg = -logFC_threshold_pos
numrows = nrow(DataInputFile())
yaxis = list(tickmode = "array", automargin = TRUE )
tex = list(family = "sans serif", size = 14, color = toRGB("#262626"))