-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.R
1916 lines (1767 loc) · 104 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
# loading all the required libraries
library(shiny)
library(ggplot2)
library(tidyverse)
library(pheatmap)
library(RColorBrewer)
library(DT)
library(corrplot)
library(shinyWidgets)
library(shinydashboard)
library(shinyBS)
library(tippy)
library(htmltools)
library(shinycustomloader)
library(shinyjs)
library(scatterD3)
library(viridis)
# setting the working directory and loading all the required datasets
#setwd("/srv/shiny-server/RShiny/")
#setwd("/Users/ajitknarendra/Desktop/PEM/RShiny/")
load("input_files_2.RDa")
load("average_expression_matrices_2.RDa")
load("percent_exprs_matrices_2.RDa")
load("avg_cellty_all_age_matrices_2.RDa")
# arranging the cell types in a specific order so that they appear in this order in the drop-down
# menus for cell type, as well as the dot plot
cellt_order <- c("alveolar.type.1.cells",
"alveolar.type.2.cells",
"AT1/AT2.like.cells",
"AT2/club.like.cells",
"basal.cells",
"club.cells",
"ciliated.cells",
"goblet.cells",
"PNECs",
"matrix.fibroblast.1",
"matrix.fibroblast.2",
"myofibroblasts",
"pericytes",
"airway.smooth.muscle",
"vascular.smooth.muscle",
"chondrocytes",
"arteries",
"veins",
"Cap1",
"Cap2",
"lymphatics",
"bronchial.vessel",
"Alveolar.macrophages",
"Interstitial.macrophages",
"monocytes",
"mast.cells",
"dendritic.cells",
"T.cells",
"B.cells",
"NK.cells",
"enucleated.erythrocytes")
cellt_order_df <- data.frame("CellTypes" = cellt_order)
all_cell_types <- left_join(cellt_order_df, all_cell_types)
epithelial_cells <- inner_join(cellt_order_df, epithelial_cells)
mesenchymal_cells <- inner_join(cellt_order_df, mesenchymal_cells)
endothelial_cells <- inner_join(cellt_order_df, endothelial_cells)
hematopoeitic_cells <- inner_join(cellt_order_df, hematopoeitic_cells)
# creating a dashboardSidebar, adding menu items and subitems to it
sidebar <- dashboardSidebar(
width = 250,
tags$head(tags$style(HTML('.shiny-server-account { display: none; }'))),
sidebarMenu(id = "tabs",
menuItem("RNA-seq", icon = icon("dna"), startExpanded = TRUE,
menuSubItem("Dot Plot", tabName = "dot_plot", icon = icon("braille"),
selected = TRUE),
menuSubItem("Heatmap", tabName = "heatmap", icon = icon("fire")),
menuSubItem("Gene Expression Data", tabName = "exprs_data", icon = icon("table"))
),
menuItem("About", icon = icon("info-circle"), tabName = "main_page")
)
)
# creating the dot plot page along with all the contents
# there are 3 tab items in this page - dot plot by cell type, by age and by sample
# dot plot by cell type
dotplot_pg_celltype <- tabPanel("By Cell Type", style = "background-color: #fff; border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(3,
selectizeInput('color_cellt_dotp',
label = "Select Color : ",
choices = list(
"Red",
"Blue",
"Green",
"Orange",
"Purple",
"Grey",
"Purple - Orange",
"Orange - Red",
"Purple - Red",
"Red - Yellow - Blue",
"Yellow - Orange - Red",
"Viridis",
"Spectral",
"Inferno",
"Plasma",
"Warm",
"Rainbow"),
multiple = FALSE,
selected = "Viridis"
)
),
column(2),
column(6,
setSliderColor(color = c("#D1B2D1", "#D1B2D1", "#D1B2D1", "#D1B2D1",
"#D1B2D1", "#D1B2D1"),
sliderId = c(1,2,3,4,5,6)),
sliderInput('leftmarg_dotp_cellt',
label = "Adjust the Left Margin : ",
min = 1, max = 250,
value = 125)
),
column(12,
box(title = "Dot Plot for Cell Type", solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
collapsed = FALSE, br(), width = "100%",
scatterD3Output('dotplot_plot_cellt', width = "100%"),
tags$style(HTML('#dotplot_plot_cellt .scatterD3 .x.axis text {
fill: #000;
font-style: italic;
}'))
)
)
)
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "Corresponding Data for Cell Type",
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = TRUE, br(), width = "100%",
DT::dataTableOutput('dotplot_data_cellt', width = "100%")
),
br(),
conditionalPanel("output.dotplot_data_cellt",
downloadButton("downloadDotPDCt", "Download Corresponding Data",
class = "d_dotbutt")),
tags$head(tags$style(".d_dotbutt{background-color: #D1B2D1;}
.d_dotbutt{border-color: #D3D3D3;}")),
br()
)
)
# dot plot by age
dotplot_pg_age <- tabPanel("By Age", style = "background-color: #fff; border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(3,
selectizeInput('age_dotp_list',
label = "Select Age : ",
choices = list(
"All Ages",
"Age" = age_list
),
multiple = TRUE,
selected = "All Ages")
),
column(3,
selectizeInput('symbol_age_dotp',
label = "Select Symbol : ",
choices = list(
"Gene",
"Age",
"None"
),
multiple = FALSE,
selected = "None")
),
column(3,
selectizeInput('color_age_dotp',
label = "Select Color : ",
choices = list(
"Red",
"Blue",
"Green",
"Orange",
"Purple",
"Grey",
"Purple - Orange",
"Orange - Red",
"Purple - Red",
"Red - Yellow - Blue",
"Yellow - Orange - Red",
"Viridis",
"Spectral",
"Inferno",
"Plasma",
"Warm",
"Rainbow"),
multiple = FALSE,
selected = "Viridis"
)
),
column(3,
sliderInput('leftmarg_dotp_age',
label = "Adjust the Left Margin : ",
min = 1, max = 250,
value = 125)
),
column(12,
box(title = "Dot Plot for Age", solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
collapsed = FALSE, br(), width = "100%",
scatterD3Output('dotplot_plot_age', width = "100%"),
tags$style(HTML('#dotplot_plot_age .scatterD3 .x.axis text {
fill: #000;
font-style: italic;
}'))
)
)
)
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "Corresponding Data for Age",
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = TRUE, br(), width = "100%",
DT::dataTableOutput('dotplot_data_age', width = "100%")
),
br(),
conditionalPanel("output.dotplot_data_age",
downloadButton("downloadDotPDAge", "Download Corresponding Data",
class = "d_dotbutt")),
br()
)
)
# dot plot by sample
dotplot_pg_sample <- tabPanel("By Sample",
style = "background-color: #fff; border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(3,
uiOutput("gene_samp"),
uiOutput("cellty_samp")
),
column(3,
selectizeInput('sample_exprs_type',
label = "Select Expression : ",
choices = list(
"Average",
"Percent"
),
multiple = FALSE,
selected = "Average"
),
selectizeInput('color_samp_dotp',
label = "Select Color : ",
choices = list(
"Red",
"Blue",
"Green",
"Orange",
"Yellow",
"Maroon",
"Purple",
"Violet",
"Grey",
"Black",
"Color by Age"),
multiple = FALSE,
selected = "Blue"
)
),
column(3,
HTML(paste("<b>","Static Scatter Plot : ", "</b>")),
switchInput(
inputId = "sc_plot_samp",
label = "<i class=\"fas fa-chart-bar\"></i>",
onLabel = "Yes",
offLabel = "No",
width = "100%"
),
sliderInput('point_size_sample',
label = "Adjust the Point Size: ",
min = 1, max = 500,
value = 100)
),
column(3,
sliderInput('leftmarg_dotp_sample',
label = "Adjust the Left Margin: ",
min = 1, max = 100,
value = 30)
)
),
fluidRow(
column(12,
box(title = "Graph for Sample grouped by Age",
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = FALSE, br(), width = "100%",
uiOutput('dotplot_plot_sample'),
tags$head(tags$style(".d_dotbutt{background-color: #D1B2D1;}
.d_dotbutt{border-color: #D3D3D3;}"))
)
)
)
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "Corresponding Data for Sample grouped by Age",
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = TRUE, br(), width = "100%",
DT::dataTableOutput('dotplot_data_sample', width = "100%")
),
br(),
conditionalPanel("output.dotplot_data_sample",
downloadButton("downloadDotPDSamp", "Download Corresponding Data",
class = "d_dotbutt")),
br()
)
)
# combining all the three tabs in the dot plot page
dotplot_page <- tabItem(
tabName = "dot_plot",
fluidRow(
column(3,
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
selectizeInput('dp_gene',
label = HTML("Select Gene <br/> (One or More) : "),
choices = NULL,
options = list(create = TRUE),
multiple = TRUE,
selected = NULL
),
selectizeInput('dp_cellty',
label = HTML("Select Cell Type <br/> (One or More) : "),
choices = NULL,
options = list(create = TRUE),
multiple = TRUE,
selected = NULL
),
actionButton("reset_def_dp", "Reset to Default", class = "d_dotbutt",
width = "100%", style='padding:4px; font-size:80%')
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
h4(tags$b("Gene Links")),
selectizeInput('gene_link_n',
label = "Select Gene : ",
choices = NULL,
multiple = FALSE,
selected = NULL
),
h5(tags$b("Click here to see the Input Gene in : ")),
actionButton("umap_link", "Single Cell UMAP",
class = "d_dotbutt",
width = "100%", style='padding:4px; font-size:80%'),
br(),
br(),
actionButton("lungep_link", "Region Overlap",
class = "d_dotbutt", width = "100%",
style='padding:4px; font-size:80%'),
br(),
br(),
actionButton("genecard_link", "GeneCards",
class = "d_dotbutt",
width = "100%",
style='padding:4px; font-size:80%')
)
)
),
column(9,
tabsetPanel(
id = "dot_plot_types",
dotplot_pg_celltype,
dotplot_pg_age,
dotplot_pg_sample
)
)
)
)
# creating the heatmap page along with all the contents
# there are 2 tab items in this page - average expression and percent expression
# function for average/percent expression tab for heatmap
heatmap_tab_func <- function(tabpan_title, cellt_in1, gene_in1, reset_in, top_most_label,
cellt_in2, gene_in2, color_in, scale_in, clust_col_in,
clust_row_in, plot_out, down_plot_out, plot_data, down_plot_data,
heatmap_down_cond, heatmap_data_down_cond) {
heatmap_tab <- tabPanel(title = tabpan_title,
style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(3,
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
selectizeInput(cellt_in1,
label = "Select Cell Type(s) : ",
choices = NULL,
options = list(create = TRUE),
multiple = TRUE,
selected = NULL
),
selectizeInput(gene_in1,
label = "Select Gene(s) : ",
choices = NULL,
options = list(create = TRUE),
multiple = TRUE,
selected = NULL
)
),
h5(tags$i("Click here to use the Heatmap option given below :")),
actionButton(reset_in, "Reset",
class = "d_dotbutt"),
br(),
br(),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
h5(tags$b(top_most_label
)),
selectizeInput(cellt_in2,
label = "Select Cell Type : ",
choices = NULL,
options = list(create = TRUE),
selected = NULL,
multiple = FALSE
),
sliderInput(gene_in2,
label = "Select Top No. of Genes to Display : ",
min = 1, max = 500,
value = 25)
)
)
),
column(9,
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(3,
selectizeInput(color_in,
label = "Select Color : ",
choices = list(
"Red",
"Blue",
"Green",
"Grey",
"Orange",
"Purple",
"Spectral",
"Viridis",
"Magma" ,
"Heat colors"),
multiple = FALSE,
selected = NULL
)
),
column(1),
column(3,
selectizeInput(scale_in,
label = "Scale : ",
choices = list("column", "row", "none"),
options = list(create = TRUE),
multiple = FALSE,
selected = "none"
)
),
column(1),
column(4,
h5(tags$b("Cluster the Heatmap by :")),
tags$style(".pretty.p-default input:checked~.state
label:after {background-color: #D1B2D1 !important;
font-family: Arial !important;}"),
fluidRow(
column(4,
prettyCheckbox(
inputId = clust_col_in,
label = "column",
value = FALSE,
shape = "curve",
status = "default"
)
),
column(3,
prettyCheckbox(
inputId = clust_row_in,
label = "row",
value = FALSE,
shape = "curve",
status = "default"
)
)
)
)
),
box(title = "Heatmap", solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = FALSE, br(), width = "100%",
plotOutput(plot_out, width = "100%")
),
br(),
conditionalPanel(heatmap_down_cond,
downloadButton(down_plot_out, "Download Heatmap",
class = "d_dotbutt")),
br()
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "Heatmap Corresponding Data",
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = TRUE, br(), width = "100%",
DT::dataTableOutput(plot_data, width = "100%")
),
br(),
conditionalPanel(heatmap_data_down_cond,
downloadButton(down_plot_data, "Download Corresponding Data",
class = "d_dotbutt")),
br()
)
)
)
)
return(heatmap_tab)
}
# average expression tab for heatmap
heatmap_avg_exprs_tab <- heatmap_tab_func("Average Expression", 'cell_type_hp_avg1',
'genes_hp_avg1', "reset_heatmap_avg",
"See Top Most Avg Gene Expression for a Particular Cell Type
and corresponding Avg Expression of those Genes in the remaining
Cell Types", 'cell_type_hp_avg2', 'genes_hp_avg2',
'color_hp_avg', 'scale_hp_avg', 'clust_col_hp_avg',
'clust_row_hp_avg', 'heatmap_plot_avg', "downloadPlotavg",
'heatmap_data_avg', "downloadHmDavg", "output.heatmap_plot_avg",
"output.heatmap_data_avg")
# percent expression tab for heatmap
heatmap_perc_exprs_tab <- heatmap_tab_func("Percent Expression", 'cell_type_hp2',
'genes_hp2', "reset_heatmap",
"See Top Most % Gene Expression for a Particular Cell Type
and corresponding % Expression of those Genes in the remaining
Cell Types", 'cell_type_hp1', 'genes_hp1',
'color_hp', 'scale_hp', 'clust_col_hp',
'clust_row_hp', 'heatmap_plot', "downloadPlot",
'heatmap_data', "downloadHmD", "output.heatmap_plot",
"output.heatmap_data")
# combining the two heatmap tabs in the heatmap page
heatmap_page <- tabItem(style = "font-family: Arial !important;",
tabName = "heatmap",
tabsetPanel(id = "heatmap_types",
heatmap_avg_exprs_tab,
heatmap_perc_exprs_tab
)
)
# creating the gene expression data page along with all the contents
# there are multiple tab items in this page, depending on the sample number
# each sample then has 2 tabs - one for average gene expression, and the other for percent gene expression
# creating a function for the average/percent gene expression tab for each sample
gene_exprs_tab_func <- function(tabpantitle, boxtitle, dtout_name, downbut_name_dt) {
gene_exprs_tp <- tabPanel(title = tabpantitle,
style = "background-color: #fff;
border-color: #D3D3D3;",
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = boxtitle,
solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = FALSE, br(), width = "100%",
DT::dataTableOutput(dtout_name, width = "100%"),
br(),
downloadButton(downbut_name_dt,"Download the (selected) data",
class = "d_dotbutt")
)
)
)
return(gene_exprs_tp)
}
# adding this function inside another function created for each sample tab
sample_tabpan_func <- function(samptab_title, tabpan_id,
tabpantitle_a, boxtitle_a, dtout_name_a, downbut_name_dt_a,
tabpantitle_p, boxtitle_p, dtout_name_p, downbut_name_dt_p) {
sample_tabpan <- tabPanel(title = samptab_title,
style = "background-color: #fff; border-color: #D3D3D3;",
fluidRow(
column(12,
tabsetPanel(id = tabpan_id,
gene_exprs_tab_func(tabpantitle_a, boxtitle_a, dtout_name_a, downbut_name_dt_a),
gene_exprs_tab_func(tabpantitle_p, boxtitle_p, dtout_name_p, downbut_name_dt_p)
)
)
)
)
return(sample_tabpan)
}
# combining everything in the gene expression data page
gene_exprs_data_page <- tabItem(
tabName = "exprs_data",
tabsetPanel(id = "expressiondata_types",
sample_tabpan_func("Sample : D032", "d032_exp",
"Average Expression", "Average Expression : Sample D032",
'd032_average', 'd032a_down',
"Percent Expression", "Percent Expression : Sample D032",
'd032_percent', 'd032p_down'),
sample_tabpan_func("Sample : D046", "d046_exp",
"Average Expression", "Average Expression : Sample D046",
'd046_average', 'd046a_down',
"Percent Expression", "Percent Expression : Sample D046",
'd046_percent', 'd046p_down'),
sample_tabpan_func("Sample : D062", "d062_exp",
"Average Expression", "Average Expression : Sample D062",
'd062_average', 'd062a_down',
"Percent Expression", "Percent Expression : Sample D062",
'd062_percent', 'd062p_down'),
sample_tabpan_func("Sample : D088", "d088_exp",
"Average Expression", "Average Expression : Sample D088",
'd088_average', 'd088a_down',
"Percent Expression", "Percent Expression : Sample D088",
'd088_percent', 'd088p_down'),
sample_tabpan_func("Sample : D122", "d122_exp",
"Average Expression", "Average Expression : Sample D122",
'd122_average', 'd122a_down',
"Percent Expression", "Percent Expression : Sample D122",
'd122_percent', 'd122p_down'),
sample_tabpan_func("Sample : D139", "d139_exp",
"Average Expression", "Average Expression : Sample D139",
'd139_average', 'd139a_down',
"Percent Expression", "Percent Expression : Sample D139",
'd139_percent', 'd139p_down'),
sample_tabpan_func("Sample : D150", "d150_exp",
"Average Expression", "Average Expression : Sample D150",
'd150_average', 'd150a_down',
"Percent Expression", "Percent Expression : Sample D150",
'd150_percent', 'd150p_down'),
sample_tabpan_func("Sample : D175", "d175_exp",
"Average Expression", "Average Expression : Sample D175",
'd175_average', 'd175a_down',
"Percent Expression", "Percent Expression : Sample D175",
'd175_percent', 'd175p_down'),
sample_tabpan_func("Sample : D231", "d231_exp",
"Average Expression", "Average Expression : Sample D231",
'd231_average', 'd231a_down',
"Percent Expression", "Percent Expression : Sample D231",
'd231_percent', 'd231p_down')
)
)
# the 'About' section page
about_section_page <- tabItem(tabName = "main_page",
fluidRow(style = "font-family: Arial !important;",
column(12,
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "About the Experiment", solidHeader = TRUE, collapsible = TRUE,
status = "primary",
collapsed = FALSE,
br(), width = "100%",
c("Respiratory failure associated with COVID-19 has placed focus on
the lung. Here, we present single-nucleus accessible chromatin
profiles of 90,980 nuclei and matched single-nucleus
transcriptomes of 46,500 nuclei in healthy lung donors of
~30 weeks gestation, ~3 years and ~30 years. We mapped
398,395 candidate cis-regulatory elements (cCREs) in lung cell
types and linked distal cCREs to putative target genes and
leveraged this dataset to investigate loci associated with COVID-19.
At the SARS-CoV-2 host entry gene TMPRSS2, we identified distal
cCREs with age-increased activity in alveolar type 2 cells
which had immune regulatory signatures and harbored variants
associated with respiratory traits. At the novel 3p21.31 COVID-19
risk locus, a candidate variant overlapped a distal cCRE linked to
SLC6A20, a gene expressed in alveolar cells which has known
functional association with ACE2. Our findings provide insight into
the gene regulatory logic of lung cell types including likely
drivers of the increased expression of SARS-CoV-2 host genes in
adults, and establish a resource (lungepigenome.org) for
interpreting lung disease risk."),
br(),
br(),
"Link to the paper : ", tags$a(href="https://elifesciences.org/articles/62522",
"https://elifesciences.org/articles/62522"),
br(),
"Link to all the datasets : ",
tags$a(href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE161383",
"GEO: GSE161383")
)
),
wellPanel(style = "background-color: #fff; border-color: #D3D3D3;",
box(title = "Related Links", solidHeader = TRUE, collapsible = TRUE, status = "primary",
collapsed = TRUE,
br(), width = "100%",
"Xin Sun lab homepage : ", tags$a(href="http://xinsunlab.org", "http://xinsunlab.org"),
br(),
"Kyle Gaulton lab : ", tags$a(href="http://www.gaultonlab.org",
"http://www.gaultonlab.org"),
br(),
"UCSD Center for Epigenomics : ",
tags$a(href="https://medschool.ucsd.edu/som/cmm/research/epigenomics/pages/default.aspx",
"https://medschool.ucsd.edu/som/cmm/research/epigenomics/pages/default.aspx"),
br(),
"LungMAP : ", tags$a(href="https://lungmap.net", "https://lungmap.net"),
br(),
"Lungepigenome Website : ", tags$a(href="https://www.lungepigenome.org/",
"https://www.lungepigenome.org/"),
br(), br(),
img(src="lungepigenome.png", width = "50%")
)
)
)
)
)
# combining all the pages in the 'body' of the app
body <- dashboardBody(style = "font-family: Arial !important;",
useShinyjs(),
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "custom.css"),
tags$style(HTML('.logo {
background-color: #D1B2D1 !important;
font-family: Arial !important;
}
.navbar {
background-color: #D1B2D1 !important;
}
body {
font-family: Arial !important;
}
.box.box-solid.box-primary>.box-header {
color:#000000;
background:#D1B2D1;
}
.box.box-solid.box-primary{
border-bottom-color:#D3D3D3;
border-left-color:#D3D3D3;
border-right-color:#D3D3D3;
border-top-color:#D3D3D3;
}
.box-header .box-title, .box-header>.fa,
.box-header>.glyphicon, .box-header>.ion {
font-family: "Arial", sans-serif !important;
}
.panel.panel-primary{
border-color:#D3D3D3;
}
.panel.panel-success{
border-color:#D3D3D3;
}
.panel-group>.panel.panel-success>.panel-heading {
color:#000000;
background:#D1B2D1;
}
.panel-group>.panel.panel-primary>.panel-heading {
color:#000000;
background:white;
}
.scatterD3 .gear-menu path {
fill:rgb(177 1 193) !important;
opacity: 1;
}
.scatterD3 .caption-icon path {
fill:rgb(177 1 193) !important;
opacity: 1;
}
.scatterD3 .axis text {
font-family: Arial;
}
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-primary,
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-primary {
color: #fff;
background: #D1B2D1;
}
'))
),
tabItems(
dotplot_page,
heatmap_page,
gene_exprs_data_page,
about_section_page
)
)
# creating the ui side
ui <- function(request) {
dashboardPage(
skin = "black",
dashboardHeader(title = "Gene Expression Profiling", titleWidth = 355),
sidebar,
body
)
}
# creating the server side
server <- function(input, output, session) {
#################################### ALL INPUT DATA ##########################################
# creating functions for updating SelectizeInput, with and without the 'selected' option
# without 'selected' option
updateinp_func <- function(inputid, choices) {
update_sel_in <- updateSelectizeInput(session = session,
inputId = inputid,
choices = choices,
server = TRUE)
return(update_sel_in)
}
# with 'selected' option
updateinp_func_w_select <- function(inputid, choices, selected_choice) {
update_sel_in <- updateSelectizeInput(session = session,
inputId = inputid,
choices = choices,
selected = selected_choice,
server = TRUE)
return(update_sel_in)
}
# updating the cell type and gene inputs in dot plot
updateinp_func_w_select('dp_gene', gene_names_old, "TMPRSS2")
updateinp_func_w_select('dp_cellty', list("All Cell Types",
"Epithelial Cells" = c(epithelial_cells$CellTypes,
"All Epithelial Cells" =
"Epithelial"),
"Mesenchymal Cells" = c(mesenchymal_cells$CellTypes,
"All Mesenchymal Cells" = "Mesenchymal"),
"Endothelial Cells" = c(endothelial_cells$CellTypes,
"All Endothelial Cells" = "Endothelial"),
"Hematopoeitic Cells" = c(hematopoeitic_cells$CellTypes,
"All Hematopoeitic Cells" = "Hematopoeitic")),
"All Cell Types")
updateinp_func_w_select('gene_link_n', gene_names_old, "TMPRSS2")
# rendering the UI Output for the gene selection for dot plot by sample tab
output$gene_samp <- renderUI({
req(input$dp_gene)
selectizeInput(inputId = 'gene_samp_inp',
label = "Select One Gene : ",
choices = input$dp_gene,
multiple = FALSE,
selected = NULL
)
})
# rendering the UI Output for the cell type selection for dot plot by sample tab
output$cellty_samp <- renderUI({
req(input$dp_cellty)
selectizeInput(inputId = 'cellty_samp_inp',
label = "Select One Cell Type : ",
choices =
if (input$dp_cellty == "All Cell Types") {
cellt_order
} else {
cellt_list1 <- data.frame()
cellt_list <- data.frame()
for (dpcellty in input$dp_cellty) {
if (dpcellty %in% c("Epithelial", "Mesenchymal", "Endothelial", "Hematopoeitic")) {
cellt_list <- all_cell_types %>% filter(Cells %in% dpcellty)
cellt_list1 <- rbind.data.frame(cellt_list1, cellt_list)
}
if (dpcellty %in% celltypes_old) {
cellt_list <- all_cell_types %>% filter(CellTypes %in% dpcellty)
cellt_list1 <- rbind.data.frame(cellt_list1, cellt_list)
}
}
cellt_list1$CellTypes
},
multiple = FALSE,
selected = NULL
)
})
# updating the cell type and gene inputs in heatmap (average expression)
updateinp_func('cell_type_hp_avg2', list("Cell Type" = cellt_order))
updateinp_func_w_select('cell_type_hp_avg1', list("All Cell Types", "Cell Type" = cellt_order),
"All Cell Types")
updateinp_func_w_select('genes_hp_avg1', gene_names_old, c("TMPRSS2", "ACE2"))
# updating the cell type and gene inputs in heatmap (percent expression)
updateinp_func('cell_type_hp1', list("Cell Type" = cellt_order))
updateinp_func_w_select('cell_type_hp2', list("All Cell Types", "Cell Type" = cellt_order),
"All Cell Types")
updateinp_func_w_select('genes_hp2', gene_names_old, c("TMPRSS2", "ACE2"))
############################### DOT PLOT PAGE ##############################################
# creating dot plot by cell type, by age and by sample
# first creating a function to encapsulate the 'color' option in the dot plot by cell type and
# by age, in a reactive environment
color_dotplot_func <- function(input_col) {
color_dp_reactive <- reactive({
switch(input_col,
"Red" = "interpolateReds",
"Blue" = "interpolateBlues",
"Green" = "interpolateGreens",
"Orange" = "interpolateOranges",
"Purple" = "interpolatePurples",
"Grey" = "interpolateGreys",
"Purple - Orange" = "interpolatePuOr",
"Orange - Red" = "interpolateOrRd",
"Purple - Red" = "interpolatePuRd",
"Red - Yellow - Blue" = "interpolateRdYlBu",
"Yellow - Orange - Red" = "interpolateYlOrRd",
"Viridis" = "interpolateViridis",
"Spectral" = "interpolateSpectral",
"Inferno" = "interpolateInferno",
"Plasma" = "interpolatePlasma",
"Warm" = "interpolateWarm",
"Rainbow" = "interpolateRainbow"
)
})
return(color_dp_reactive)
}
# dot plot by cell type and by age 'color' options in reactive environments using the above function
color_dotplot_cell <- color_dotplot_func(input$color_cellt_dotp)
color_dotplot_age <- color_dotplot_func(input$color_age_dotp)
# arranging the celltypes in an order to be used in the same order in the dot plot (scatterD3)
cellt_order1 <- data.frame("CellTypes" = c("alveolar.type.1.cells",
"alveolar.type.2.cells",
"AT1/AT2.like.cells",
"AT2/club.like.cells",
"basal.cells",
"club.cells",
"ciliated.cells",
"goblet.cells",
"PNECs",
"matrix.fibroblast.1",
"matrix.fibroblast.2",
"myofibroblasts",
"pericytes",
"airway.smooth.muscle",
"vascular.smooth.muscle",
"chondrocytes",
"arteries",
"veins",
"Cap1",
"Cap2",
"lymphatics",
"bronchial.vessel",
"Alveolar.macrophages",
"Interstitial.macrophages",
"monocytes",
"mast.cells",
"dendritic.cells",
"T.cells",
"B.cells",
"NK.cells",
"enucleated.erythrocytes"),
"CellTy_Num" = c(1:31))
# function for dot plot by cell type (the starting part of which is common for the dot plot and
# the corresponding data for the same)
dotplot_cellt_func <- function(gene_input, celltype_input) {
perc_cellt <- as.data.frame(t(exprs_mat[gene_input,]))
perc_cellt$CellTypes <- rownames(perc_cellt)
avg_cellt <- as.data.frame(t(exprs_mat_avg[gene_input,]))
avg_cellt$CellTypes <- rownames(avg_cellt)
avg_cellt <- tidyr::gather(avg_cellt[,c("CellTypes", gene_input)],
key = "Gene", value = "Avg_Expression",
-"CellTypes")
avg_cellt$comb_sample <- paste0(avg_cellt$CellTypes, "_", avg_cellt$Gene)
perc_cellt <- tidyr::gather(perc_cellt[,c("CellTypes", gene_input)],
key = "Gene", value = "Percent_Expression",
-"CellTypes")
perc_cellt$comb_sample <- paste0(perc_cellt$CellTypes, "_", perc_cellt$Gene)
perc_cellt <- perc_cellt %>% select(-c(CellTypes, Gene))
cellt_exprs_comb <- left_join(avg_cellt, perc_cellt, by = "comb_sample")
cellt_exprs_comb <- left_join(cellt_exprs_comb, all_cell_types, by = "CellTypes")
cellt_exprs_comb <- left_join(cellt_order1, cellt_exprs_comb)
cellt_exprs_comb <- cellt_exprs_comb %>% arrange(desc(CellTy_Num))
if (celltype_input == "All Cell Types") {
cellt_exprs_comb <- cellt_exprs_comb
cellt_exprs_comb$CellTypes <- factor(cellt_exprs_comb$CellTypes,
levels = unique(cellt_exprs_comb$CellTypes))
} else {
cellt_exp_df1 <- data.frame()
cellt_exp_df <- data.frame()
for (dpcellty in celltype_input) {
if (dpcellty %in% c("Epithelial", "Mesenchymal", "Endothelial", "Hematopoeitic")) {
cellt_exp_df <- cellt_exprs_comb %>% filter(Cells %in% dpcellty)
cellt_exp_df1 <- rbind.data.frame(cellt_exp_df1, cellt_exp_df)
cellt_exp_df1$CellTypes <- factor(cellt_exp_df1$CellTypes,
levels = unique(cellt_exp_df1$CellTypes))
}
if (dpcellty %in% celltypes_old) {
cellt_exp_df <- cellt_exprs_comb %>% filter(CellTypes %in% dpcellty)
cellt_exp_df1 <- rbind.data.frame(cellt_exp_df1, cellt_exp_df)
}
}
cellt_exprs_comb <- cellt_exp_df1
}
return(cellt_exprs_comb)