/
pcaExplorer.R
2698 lines (2424 loc) · 114 KB
/
pcaExplorer.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
#' Explore a dataset from a PCA perspective
#'
#' Launch a Shiny App for interactive exploration of a dataset from the perspective
#' of Principal Components Analysis
#'
#' @param dds A \code{\link{DESeqDataSet}} object. If not provided, then a \code{countmatrix}
#' and a \code{coldata} need to be provided. If none of the above is provided, it is possible
#' to upload the data during the execution of the Shiny App
#' @param dst A \code{\link{DESeqTransform}} object. Can be computed from the \code{dds} object
#' if left NULL. If none is provided, then a \code{countmatrix}
#' and a \code{coldata} need to be provided. If none of the above is provided, it is possible
#' to upload the data during the execution of the Shiny App
#' @param countmatrix A count matrix, with genes as rows and samples as columns. If not provided, it is possible
#' to upload the data during the execution of the Shiny App
#' @param coldata A data.frame containing the info on the covariates of each sample. If not provided, it is possible
#' to upload the data during the execution of the Shiny App
#' @param pca2go An object generated by the \code{\link{pca2go}} function, which contains
#' the information on enriched functional categories in the genes that show the top or bottom loadings
#' in each principal component of interest. If not provided, it is possible
#' to compute live during the execution of the Shiny App
#' @param annotation A \code{data.frame} object, with row.names as gene identifiers (e.g. ENSEMBL ids)
#' and a column, \code{gene_name}, containing e.g. HGNC-based gene symbols
#' @param runLocal A logical indicating whether the app is to be run locally or remotely on a server, which determines how documentation will be accessed.
#'
#' @return A Shiny App is launched for interactive data exploration
#'
#' @examples
#' library(airway)
#' data(airway)
#' airway
#' dds_airway <- DESeq2::DESeqDataSetFromMatrix(assay(airway),
#' colData = colData(airway),
#' design = ~dex+cell)
#' \dontrun{
#' rld_airway <- DESeq2::rlogTransformation(dds_airway)
#'
#' pcaExplorer(dds_airway, rld_airway)
#'
#' pcaExplorer(countmatrix = counts(dds_airway), coldata = colData(dds_airway))
#'
#' pcaExplorer() # and then upload count matrix, covariate matrix (and eventual annotation)
#' }
#'
#' @export
pcaExplorer <- function(dds = NULL,
dst = NULL,
countmatrix = NULL,
coldata = NULL,
pca2go = NULL,
annotation = NULL,
runLocal = TRUE) {
if (!requireNamespace("shiny", quietly = TRUE)) {
stop("pcaExplorer requires 'shiny'. Please install it using
install.packages('shiny')")
}
# get modes and themes for the ace editor
modes <- shinyAce::getAceModes()
themes <- shinyAce::getAceThemes()
# create environment for storing inputs and values
## i need the assignment like this to export it up one level - i.e. "globally"
pcaexplorer_env <<- new.env(parent = emptyenv())
## upload max 300mb files - can be changed if necessary
options(shiny.maxRequestSize = 300 * 1024^2)
# ui definition -----------------------------------------------------------
pcaexplorer_ui <- shinydashboard::dashboardPage(
# header definition -----------------------------------------------------------
dashboardHeader(
title = paste0("pcaExplorer - Interactive exploration of Principal Components ",
"of Samples and Genes in RNA-seq data - version ",
packageVersion("pcaExplorer")),
titleWidth = 900,
# task menu for saving state to environment or binary data
shinydashboard::dropdownMenu(
type = "tasks", icon = icon("cog"), badgeStatus = NULL,
headerText = "pcaExplorer task menu",
notificationItem(
text = actionButton("exit_and_save", "Exit pcaExplorer & save",
class = "btn_no_border",
onclick = "setTimeout(function(){window.close();}, 100); "),
icon = icon("sign-out"), status = "primary"),
menuItem(
text = downloadButton("state_save_sc", "Save State as .RData"))
)
),
# sidebar definition -----------------------------------------------------------
dashboardSidebar(
width = 280,
menuItem(
"App settings",
icon = icon("cogs"),
startExpanded = TRUE,
selectInput("pc_x", label = "x-axis PC: ", choices = 1:8, selected = 1),
shinyBS::bsTooltip(
"pc_x", paste0("Select the principal component to display on the x axis"),
"right", options = list(container = "body")),
selectInput("pc_y", label = "y-axis PC: ", choices = 1:8, selected = 2),
shinyBS::bsTooltip(
"pc_y", paste0("Select the principal component to display on the y axis"),
"right", options = list(container = "body")),
uiOutput("color_by"),
shinyBS::bsTooltip(
"color_by",
paste0("Select the group of samples to stratify the analysis. Can also assume multiple values"),
"right", options = list(container = "body")),
numericInput("pca_nrgenes", label = "Nr of (most variant) genes:",
value = 300, min = 50, max = 20000),
shinyBS::bsTooltip(
"pca_nrgenes", paste0(
"Number of genes to select for computing the principal components. The top n genes are",
" selected ranked by their variance inter-samples"),
"right", options = list(container = "body")),
numericInput("pca_point_alpha", label = "Alpha: ", value = 1, min = 0, max = 1, step = 0.01),
shinyBS::bsTooltip(
"pca_point_alpha",
paste0("Color transparency for the plots. Can assume values from 0 (transparent) ",
"to 1 (opaque)"),
"right", options = list(container = "body")),
numericInput("pca_label_size", label = "Labels size: ", value = 2, min = 1, max = 8),
shinyBS::bsTooltip(
"pca_label_size", paste0("Size of the labels for the samples in the principal components plots. ",
"This also controls the size of the gene labels in the Genes View panel."),
"right", options = list(container = "body")),
numericInput("pca_point_size", label = "Points size: ", value = 2, min = 1, max = 8),
shinyBS::bsTooltip(
"pca_point_size", paste0("Size of the points to be plotted in the principal components plots"),
"right", options = list(container = "body")),
numericInput("pca_varname_size", label = "Variable name size: ", value = 4, min = 1, max = 8),
shinyBS::bsTooltip(
"pca_varname_size", paste0("Size of the labels for the genes PCA - correspond to the samples names"),
"right", options = list(container = "body")),
numericInput("pca_scale_arrow", label = "Scaling factor : ", value = 1, min = 0.01, max = 10),
shinyBS::bsTooltip(
"pca_scale_arrow", paste0("Scale value for resizing the arrow corresponding to the variables in the ",
"PCA for the genes. It should be used for mere visualization purposes"),
"right", options = list(container = "body")),
selectInput("col_palette", "Color palette", choices = list("hue", "set1", "rainbow")),
selectInput("plot_style", "Plot style for gene counts", choices = list("boxplot", "violin plot")),
shinyBS::bsTooltip(
"col_palette", paste0("Select the color palette to be used in the principal components plots. The number of ",
"colors is selected automatically according to the number of samples and to the levels ",
"of the factors of interest and their interactions"),
"right", options = list(container = "body"))
), # end of menuItem
menuItem(
"Plot export settings",
icon = icon("paint-brush"),
startExpanded = TRUE,
numericInput("export_width",
label = "Width of exported figures (cm)", value = 10, min = 2),
shinyBS::bsTooltip(
"export_width", paste0("Width of the figures to export, expressed in cm"),
"right", options = list(container = "body")),
numericInput("export_height", label = "Height of exported figures (cm)", value = 10, min = 2),
shinyBS::bsTooltip(
"export_height", paste0("Height of the figures to export, expressed in cm"),
"right", options = list(container = "body"))
) # end of menuItem
),
# body definition ---------------------------------------------------------
dashboardBody(
## Define output size and style of error messages
tags$head(
tags$style(HTML("
.shiny-output-error-validation {
font-size: 15px;
color: forestgreen;
text-align: center;
}
")
)
),
# ui main tabBox -------------------------------------------------------
tabBox(
width = 12,
# ui panel data upload -------------------------------------------------------
tabPanel(
"Data Upload", icon = icon("upload"),
fluidRow(
column(
width = 4,
uiOutput("upload_count_matrix"),
shinyBS::bsTooltip(
"upload_count_matrix", paste0("Select the file containing the count matrix"),
"right", options = list(container = "body"))),
column(
width = 4,
uiOutput("upload_metadata"),
shinyBS::bsTooltip(
"upload_metadata", paste0("Select the file containing the samples metadata"),
"right", options = list(container = "body"))),
column(
width = 3,
# help button?
br(), br(), br(),
uiOutput("ui_createDDS"),
actionButton("help_format", label = "", icon = icon("question-circle"),
style = "color: #0092AC; background-color: #FFFFFF; border-color: #FFFFFF"),
shinyBS::bsTooltip(
"help_format",
"How to provide your input data in pcaExplorer",
"bottom", options = list(container = "body"))
##### ,verbatimTextOutput("debugdebug")
)),
fluidRow(
column(
width = 4,
uiOutput("upload_annotation"),
shinyBS::bsTooltip(
"upload_annotation", paste0("Select the file containing the annotation data"),
"right", options = list(container = "body")),
br(),
"... or you can also ",
actionButton("btn_loaddemo", "Load the demo airway data",
icon = icon("play-circle"), style = "color: #0092AC"),
# class = "btn btn-info"),
shinyBS::bsTooltip(
"btn_loaddemo", paste0("Clicking on this button will load the airway data as DESeqDataSet, apply the regularized log transformation, and prepare the annotation for displaying gene symbols"),
"bottom", options = list(container = "body"))
)
)
,
br(),
p(),
uiOutput("ui_computetransform"),
h4("Preview on the available data"),
fluidRow(
column(
width = 10,
splitLayout(
uiOutput("ui_showcm"),
uiOutput("ui_showmetadata"),
uiOutput("ui_showdds"),
uiOutput("ui_showannotation")
)
)
)
),
# ui panel instructions -------------------------------------------------------
tabPanel(
"Instructions", icon = icon("info-circle"),
fluidRow(
column(
width = 12,
p("These buttons will open the fully rendered vignettes, either built locally or directly from the Bioconductor package page."),
actionButton(
"open_vignette_full", label = "Open the User Guide (main vignette)",
icon = icon("book"),
onclick = ifelse(runLocal, "",
# Use web vignette, with varying paths depending on whether we're release or devel.
sprintf("window.open('http://bioconductor.org/packages/%s/bioc/vignettes/pcaExplorer/inst/doc/pcaExplorer.html', '_blank')",
ifelse(unlist(packageVersion("pcaExplorer"))[2] %% 2L == 0L, "release", "devel")
)
)
),
actionButton(
"open_vignette_quickstart", label = "Open the 'Up and running' vignette",
icon = icon("rocket"),
onclick = ifelse(runLocal, "",
# Use web vignette, with varying paths depending on whether we're release or devel.
sprintf("window.open('http://bioconductor.org/packages/%s/bioc/vignettes/pcaExplorer/inst/doc/upandrunning.html', '_blank')",
ifelse(unlist(packageVersion("pcaExplorer"))[2] %% 2L == 0L, "release", "devel")
)
)
),
br(), br(),
p("Otherwise, you can click on the collapsible element below to display a quickstart guide."),
shinyBS::bsCollapse(
id = "help_fulluserguide", open = NULL,
shinyBS::bsCollapsePanel(
"Up and running with pcaExplorer",
includeMarkdown(system.file("extdata", "instructions_unr.md", package = "pcaExplorer"))
)
)
)
)
),
# ui panel counts table -------------------------------------------------------
tabPanel(
"Counts Table",
icon = icon("table"),
conditionalPanel(
condition = "!output.checkdds",
h3("Counts table"),
selectInput("countstable_unit", label = "Data scale in the table",
choices = list("Counts (raw)" = "raw_counts",
"Counts (normalized)" = "normalized_counts",
"Regularized logarithm transformed" = "rlog_counts",
"Log10 (pseudocount of 1 added)" = "log10_counts",
"TPM (Transcripts Per Million)" = "tpm_counts")),
DT::dataTableOutput("showcountmat"),
downloadButton("downloadData", "Download", class = "btn btn-success"),
hr(),
h3("Sample to sample scatter plots"),
selectInput("corr_method", "Correlation method palette",
choices = list("pearson", "spearman", "kendall")),
checkboxInput(inputId = "corr_uselogs", label = "Use log2 values for plot axes and values",
value = TRUE),
checkboxInput(inputId = "corr_usesubset", label = "Use a subset of max 1000 genes (quicker to plot)",
value = TRUE),
p("Compute sample to sample correlations on the normalized counts - warning, it can take a while to plot all points (depending mostly on the number of samples you provided)."),
actionButton("compute_pairwisecorr", "Run", class = "btn btn-primary"),
uiOutput("pairwise_plotUI"),
uiOutput("heatcorr_plotUI")
),
conditionalPanel(
condition = "output.checkdds",
h2("You did not create the dds object yet. Please go the main tab and generate it"))
),
# ui panel data overview -------------------------------------------------------
tabPanel(
"Data Overview", icon = icon("eye"),
conditionalPanel(
condition = "!output.checkrlt",
h1("Sneak peek in the data"),
h3("Design metadata"),
DT::dataTableOutput("showcoldata"),
h3("Sample to sample distance heatmap"),
fluidRow(
column(
width = 8,
selectInput(inputId = "sampledist_distance", label = "Select the distance method to use:",
choices =
c(Euclidean="euclidean", Manhattan = "manhattan", `Correlation-based` = "cor"),
selected = "euclidean"),
plotOutput("heatmapsampledist"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplessamplesheat", "Download Plot"),
textInput("filename_samplessamplesheat", label = "Save as...", value = "pcae_sampletosample.pdf")))
),
hr(),
h3("General information on the provided SummarizedExperiment/DESeqDataSet"),
shiny::verbatimTextOutput("showdata"),
h3("Number of million of reads per sample"),
fluidRow(
column(
width = 8,
plotOutput("reads_barplot"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_readsbarplot", "Download Plot"),
textInput("filename_readsbarplot", label = "Save as...", value = "pcae_readsbarplot.pdf")))),
h3("Basic summary for the counts"),
p("Number of uniquely aligned reads assigned to each sample"),
verbatimTextOutput("reads_summary"),
wellPanel(
fluidRow(
column(
width = 4,
numericInput("threshold_rowsums", "Threshold on the row sums of the counts", value = 0, min = 0)),
column(
width = 4,
numericInput("threshold_rowmeans", "Threshold on the row means of the normalized counts", value = 0, min = 0))
)),
p("According to the selected filtering criteria, this is an overview on the provided count data"),
verbatimTextOutput("detected_genes")),
conditionalPanel(
condition = "output.checkrlt",
h2("You did not create the dst object yet. Please go the main tab and generate it")
)
),
# ui panel samples view -------------------------------------------------------
tabPanel(
"Samples View",
icon = icon("share-alt"),
conditionalPanel(
condition = "!output.checkrlt",
p(h1("Principal Component Analysis on the samples"),
"PCA projections of sample expression profiles onto any pair of components."),
fluidRow(
column(
width = 4,
wellPanel(checkboxInput("sample_labels", "Display sample labels", value = TRUE),
checkboxInput("pca_ellipse", "Draw a confidence ellipse for each group", value = FALSE),
sliderInput("pca_cislider", "Select the confidence interval level", min = 0, max = 1, value = 0.95)))),
fluidRow(
column(
width = 6,
plotOutput("samples_pca", brush = "pca_brush"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplesPca", "Download Plot"),
textInput("filename_samplesPca", label = "Save as...", value = "samplesPca.pdf"))
),
column(
width = 6,
plotOutput("samples_scree"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplesScree", "Download Plot"),
textInput("filename_samplesScree", label = "Save as...", value = "samplesScree.pdf")),
wellPanel(fluidRow(
column(
width = 6,
radioButtons("scree_type", "Scree plot type:",
choices = list("Proportion of explained variance" = "pev",
"Cumulative proportion of explained variance" = "cev"), "pev")
),
column(
width = 6,
numericInput("scree_pcnr", "Number of PCs to display", value = 8, min = 2)
)
))
)
),
hr(),
fluidRow(
column(
width = 6,
plotOutput("samples_pca_zoom"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplesPcazoom", "Download Plot"),
textInput("filename_samplesPcazoom", label = "Save as...", value = "samplesPcazoom.pdf"))
),
column(
width = 6,
numericInput("ntophiload", "Nr of genes to display (top & bottom)", value = 10, min = 1, max = 40),
plotOutput("geneshiload"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplesPca_hiload", "Download Plot"),
textInput("filename_samplesPca_hiload", label = "Save as...", value = "pcae_hiload.pdf"))
)
),
hr(),
fluidRow(
column(
width = 6,
p(h4("Outlier Identification"), "Toggle which samples to remove - suspected to be considered as outliers"),
uiOutput("ui_outliersamples"),
plotOutput("samples_outliersremoved"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_samplesPca_sampleout", "Download Plot"),
textInput("filename_samplesPca_sampleout", label = "Save as...", value = "samplesPca_sampleout.pdf"))
)
),
fluidRow(
column(
width = 8,
selectInput("pc_z", "Select the principal component to display on the z axis", choices = 1:8, selected = 3),
scatterplotThreeOutput("pca3d")
)
)
),
conditionalPanel(
condition = "output.checkrlt",
h2("You did not create the dst object yet. Please go the main tab and generate it"))
),
# ui panel genes view -------------------------------------------------------
tabPanel(
"Genes View",
icon = icon("yelp"),
conditionalPanel(
condition = "!output.checkrlt",
p(h1("Principal Component Analysis on the genes"), "PCA projections of genes abundances onto any pair of components."),
fluidRow(
column(
width = 6,
checkboxInput("variable_labels", "Display variable labels", value = TRUE),
checkboxInput("ylimZero_genes", "Set y axis limit to 0", value = TRUE)
)
),
fluidRow(
column(
width = 6,
h4("Main Plot - interact!"),
plotOutput("genes_biplot", brush = "pcagenes_brush", click = "pcagenes_click"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genesPca", "Download Plot"),
textInput("filename_genesPca", label = "Save as...", value = "genesPca.pdf"))),
column(
width = 6,
h4("Zoomed window"),
plotOutput("genes_biplot_zoom", click = "pcagenes_zoom_click"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genesZoom", "Download Plot"),
textInput("filename_genesZoom", label = "Save as...", value = "genesPca_zoomed.pdf")))
),
fluidRow(
column(
width = 6,
h4("Profile explorer"),
checkboxInput("zprofile", "Display scaled expression values", value = TRUE),
plotOutput("genes_profileexplorer"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genesPca_profile", "Download Plot"),
textInput("filename_genesPca_profile", label = "Save as...", value = "genesPca_profile.pdf")
)
),
column(
width = 6,
h4("Boxplot of selected gene"),
plotOutput("genes_biplot_boxplot"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genesPca_countsplot", "Download Plot"),
textInput("filename_genesPca_countsplot", label = "Save as...", value = "genesPca_countsplot.pdf")))
),
fluidRow(
column(
width = 6,
h4("Zoomed heatmap"),
plotOutput("heatzoom"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genesHeatmap", "Download Plot"),
textInput("filename_genesHeatmap", label = "Save as...", value = "genesHeatmap.pdf"))),
column(
width = 6,
h4("Zoomed interactive heatmap"),
fluidRow(radioButtons("heatmap_colv", "Cluster samples", choices = list("Yes" = TRUE, "No" = FALSE), selected = TRUE)),
fluidRow(plotlyOutput("heatzoomly")))),
hr(),
box(
title = "Table export options", status = "primary", solidHeader = TRUE,
collapsible = TRUE, collapsed = TRUE, width = 12,
fluidRow(
column(
width = 6,
h4("Points selected by brushing - clicking and dragging:"),
DT::dataTableOutput("pca_brush_out"),
downloadButton("downloadData_brush", "Download brushed points"),
textInput("brushedPoints_filename", "File name...")),
column(
width = 6,
h4("Points selected by clicking:"),
DT::dataTableOutput("pca_click_out"),
downloadButton("downloadData_click", "Download clicked (or nearby) points")),
textInput("clickedPoints_filename", "File name...")
)
)
),
conditionalPanel(
condition = "output.checkrlt",
h2("You did not create the dst object yet. Please go the main tab and generate it"))
),
# ui panel gene finder -------------------------------------------------------
tabPanel(
"Gene Finder",
icon = icon("crosshairs"),
conditionalPanel(
condition = "!output.checkdds",
p(h1("GeneFinder")),
fluidRow(
column(
width = 6,
wellPanel(
width = 5,
textInput("genefinder", label = "Type in the name of the gene to search", value = NULL),
shinyBS::bsTooltip(
"genefinder", paste0(
"Type in the name of the gene to search. If no annotation is ",
"provided, you need to use IDs that are the row names of the ",
"objects you are using - count matrix, SummarizedExperiments ",
"or similar. If an annotation is provided, that also contains ",
"gene symbols or similar, the gene finder tries to find the ",
"name and the ID, and it suggests if some characters are in a ",
"different case"),
"bottom", options = list(container = "body")),
checkboxInput("ylimZero", "Set y axis limit to 0", value = TRUE),
checkboxInput("addsamplelabels", "Annotate sample labels to the dots in the plot", value = TRUE)),
verbatimTextOutput("searchresult"),
verbatimTextOutput("debuggene")
)
),
fluidRow(
column(
width = 8,
plotOutput("genefinder_plot"),
div(align = "right", style = "margin-right:15px; margin-bottom:10px",
downloadButton("download_genefinder_countsplot", "Download Plot"),
textInput("filename_genefinder_countsplot", label = "Save as...", value = "pcae_genefinder.pdf"))),
column(
width = 4,
DT::dataTableOutput("genefinder_table"),
downloadButton("download_genefinder_countstable", "Download Table")
)
)
),
conditionalPanel(
condition = "output.checkdds",
h2("You did not create the dds object yet. Please go the main tab and generate it")
)
),
# ui panel pca2go -------------------------------------------------------
tabPanel(
"PCA2GO",
icon = icon("magic"),
conditionalPanel(
condition = "!output.checkrlt",
h1("pca2go - Functional annotation of Principal Components"),
h4("Functions enriched in the genes with high loadings on the selected principal components"),
# verbatimTextOutput("enrichinfo"),
wellPanel(column(
width = 6,
uiOutput("ui_selectspecies")
),
column(
width = 6,
uiOutput("ui_inputtype")
),
shinyBS::bsTooltip(
"ui_selectspecies",
paste0("Select the species for the functional enrichment analysis, ",
"choosing among the ones currently supported by limma::goana. ",
"Alternatively, for other species, it can be possible to use one ",
"of the available annotation packages in Bioconductor, and pre-",
"computing the pca2go object in advance"),
"bottom", options = list(container = "body")),
verbatimTextOutput("speciespkg"),
checkboxInput("compact_pca2go", "Display compact tables (for topGO tables)", value = FALSE),
shinyBS::bsTooltip(
"compact_pca2go",
paste0("Should I display all the columns? If the information content of the ",
"tables is somehow too much for the screen width, as it can be for ",
"objects generated by pca2go with the topGO routines, the app can ",
"display just an essential subset of the columns"),
"bottom", options = list(container = "body")),
uiOutput("ui_computePCA2GO"),
shinyBS::bsTooltip(
"ui_computePCA2GO",
paste0("Compute a pca2go object, using the limma::goana function, ",
"after selecting the species of the experiment under investigation"),
"bottom", options = list(container = "body"))),
fluidRow(
column(width = 3),
column(
width = 6,
DT::dataTableOutput("dt_pcver_pos")),
column(width = 3)
),
fluidRow(
column(4,
DT::dataTableOutput("dt_pchor_neg")),
column(4,
plotOutput("pca2go")),
column(4,
DT::dataTableOutput("dt_pchor_pos"))
),
fluidRow(
column(width = 3),
column(
width = 6,
DT::dataTableOutput("dt_pcver_neg")),
column(width = 3)
)
),
conditionalPanel(
condition = "output.checkrlt",
h2("You did not create the dst object yet. Please go the main tab and generate it"))
),
# ui panel multifactor exploration -----------------------------------------------------
tabPanel(
"Multifactor Exploration",
icon = icon("th-large"),
conditionalPanel(
condition = "!output.checkrlt",
h1("Multifactor exploration of datasets with 2 or more experimental factors"),
verbatimTextOutput("intro_multifac"),
wellPanel(fluidRow(
column(
width = 6,
uiOutput("covar1")
),
column(
width = 6,
uiOutput("covar2")
)
),
fluidRow(
column(
width = 6,
uiOutput("c1levels")
),
column(
width = 6,
uiOutput("c2levels")
)
),
fluidRow(
column(
width = 6,
uiOutput("colnames1"),
uiOutput("colnames2")
)
),
shinyBS::bsTooltip(
"covar1", paste0("Select the first experimental factor"),
"bottom", options = list(container = "body")),
shinyBS::bsTooltip(
"covar2", paste0("Select the second experimental factor"),
"bottom", options = list(container = "body")),
shinyBS::bsTooltip(
"c1levels", paste0("For factor 1, select two levels to contrast"),
"bottom", options = list(container = "body")),
shinyBS::bsTooltip(
"c2levels", paste0("For factor 2, select two or more levels to contrast"),
"bottom", options = list(container = "body")),
shinyBS::bsTooltip(
"colnames1", paste0("Combine samples belonging to Factor1-Level1 samples for each level in Factor 2"),
"bottom", options = list(container = "body")),
shinyBS::bsTooltip(
"colnames2", paste0("Combine samples belonging to Factor1-Level2 samples for each level in Factor 2"),
"bottom", options = list(container = "body"))),
actionButton("composemat", "Compose the matrix", icon = icon("spinner"), class = "btn btn-primary"),
shinyBS::bsTooltip(
"composemat",
paste0("Select first two different experimental factors, for example ",
"condition and tissue. For each factor, select two or more ",
"levels. The corresponding samples which can be used are then displayed ",
"in the select boxes. Select an equal number of samples for each of ",
"the levels in factor 1, and then click the button to compute the ",
"new matrix which will be used for the visualizations below"),
"bottom", options = list(container = "body")),
wellPanel(fluidRow(
column(4,
selectInput("pc_x_multifac", label = "x-axis PC: ", choices = 1:8,
selected = 1)
),
column(4,
selectInput("pc_y_multifac", label = "y-axis PC: ", choices = 1:8,
selected = 2)
))),
# fluidRow(verbatimTextOutput("multifacdebug")),
fluidRow(
column(6,
plotOutput("pcamultifac", brush = "pcamultifac_brush")),
column(6,
plotOutput("multifaczoom"))
),
fluidRow(downloadButton("downloadData_brush_multifac", "Download brushed points"),
textInput("brushedPoints_filename_multifac", "File name..."),
DT::dataTableOutput("pcamultifac_out"))
),
conditionalPanel(
condition = "output.checkrlt",
h2("You did not create the dst object yet. Please go the main tab and generate it")
)
),
# ui panel report editor -------------------------------------------------------
tabPanel(
"Report Editor",
icon = icon("pencil"),
h1("Report Editor"),
fluidRow(
column(
width = 6,
box(
title = "Markdown options", status = "primary", solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, width = 9,
radioButtons("rmd_dl_format", label = "Choose Format:", c("HTML" = "html", "R Markdown" = "rmd"), inline = TRUE),
textInput("report_title", "Title: "),
textInput("report_author", "Author: "),
radioButtons("report_toc", "Table of Contents", choices = list("Yes" = "true", "No" = "false")),
radioButtons("report_ns", "Number sections", choices = list("Yes" = "true", "No" = "false")),
selectInput("report_theme", "Theme",
choices = list("Default" = "default", "Cerulean" = "cerulean",
"Journal" = "journal", "Flatly" = "flatly",
"Readable" = "readable", "Spacelab" = "spacelab",
"United" = "united", "Cosmo" = "cosmo")),
radioButtons("report_echo", "Echo the commands in the output", choices = list("Yes" = "TRUE", "No" = "FALSE")))),
column(
width = 6,
box(
title = "Editor options", status = "primary", solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, width = 9,
checkboxInput("enableAutocomplete", "Enable AutoComplete", TRUE),
conditionalPanel(
"input.enableAutocomplete",
wellPanel(
checkboxInput("enableLiveCompletion", "Live auto completion", TRUE),
checkboxInput("enableRCompletion", "R code completion", TRUE)
)
),
selectInput("mode", "Mode: ", choices = modes, selected = "markdown"),
selectInput("theme", "Theme: ", choices = themes, selected = "solarized_light"))
)
# ,
# column( # kept for debugging purposes!
# width = 6,
# verbatimTextOutput("loadedRmd")
# )
),
fluidRow(
column(3,
actionButton("updatepreview_button", "Update report", class = "btn btn-primary"), p()
),
column(3, downloadButton("saveRmd", "Generate & Save", class = "btn btn-success"))
),
tabBox(
width = NULL,
id = "report_tabbox",
tabPanel("Report preview",
icon = icon("file-text"),
htmlOutput("knitDoc")
),
tabPanel("Edit report",
icon = icon("pencil-square-o"),
aceEditor("acereport_rmd", mode = "markdown", theme = "solarized_light", autoComplete = "live",
value = "_Initialization of the_ `pcaExplorer` _report generation..._",
placeholder = "You can enter some code and text in R Markdown format",
height = "800px"))
)
),
# ui panel about -------------------------------------------------------
tabPanel(
"About", icon = icon("institution"),
includeMarkdown(system.file("extdata", "about.md", package = "pcaExplorer")),
hr(),
h4("Session Info"),
verbatimTextOutput("sessioninfo")
)
# tabPanel(
# "Session manager",
# ## will put here the things to save/restore the sessions
# p("something"),
# )
) # end of tabBox
, footer()
), # end of dashboardBody
skin = "blue"
)
# server definition -------------------------------------------------------
#nocov start
pcaexplorer_server <- shinyServer(function(input, output, session) {
# server setup reactives --------------------------------------------------------
## placeholder for the figures to export
exportPlots <- reactiveValues(
samplessamples_heatmap = NULL,
reads_barplot = NULL,
samplesPca = NULL,
samplesZoom = NULL,
samplesScree = NULL,
samplesHiload = NULL,
samplesOutlier = NULL,
genesPca = NULL,
genesZoom = NULL,
genesProfile = NULL,
genesBoxplot = NULL,
genesHeatmap = NULL,
genefinder_countsplot = NULL
)
if (!is.null(dds)) {
if (is.null(sizeFactors(dds))) {
withProgress({
dds <- estimateSizeFactors(dds)
},
message = "Calculating size factors...",
detail = "Using the DESeq normalization method.")
}
}
## reactive values to use in the app
values <- reactiveValues()
values$mydds <- dds
values$mydst <- dst
values$mycountmatrix <- countmatrix
values$mymetadata <- coldata
values$mypca2go <- pca2go
if (!is.null(annotation)) {
if ("gene_id" %in% colnames(annotation)) {
rownames(annotation) <- annotation$gene_id
}
}
values$myannotation <- annotation
user_settings <- reactiveValues(save_width = 15, save_height = 11)
if (!is.null(dds)) {
# if provided as dds, can fill in the count matrix and metadata
values$mycountmatrix <- counts(dds)
values$mymetadata <- colData(dds)
}
output$checkdds <- reactive({
is.null(values$mydds)
})
output$checkrlt <- reactive({
is.null(values$mydst)
})
outputOptions(output, "checkdds", suspendWhenHidden = FALSE)
outputOptions(output, "checkrlt", suspendWhenHidden = FALSE)
if (runLocal) {
observeEvent(input$open_vignette_full, {
path <- system.file("doc", "pcaExplorer.html", package = "pcaExplorer")
if (path == "") {
showNotification("This vignette (User Guide) has not been built on this system, please run pcaExplorer with runLocal=FALSE or install the package with the option to build the vignettes", type = "error")
} else {
browseURL(path)
}
})
observeEvent(input$open_vignette_quickstart, {
path <- system.file("doc", "upandrunning.html", package = "pcaExplorer")
if (path == "") {
showNotification("This vignette (Up and running) has not been built on this system, please run pcaExplorer with runLocal=FALSE or install the package with the option to build the vignettes", type = "error")
} else {
browseURL(path)
}
})
}
# server setup dataset --------------------------------------------------------
if (!is.null(dds)) {
if (!is(dds, "DESeqDataSet"))
stop("dds must be a DESeqDataSet object. If it is a simple counts matrix, provide it to the countmatrix parameter!")
if (is.null(sizeFactors(dds))) {
withProgress({
dds <- estimateSizeFactors(dds)
},
message = "Calculating size factors...",
detail = "Using the DESeq normalization method.")
}
}
if (!is.null(dst)) {
if (!is(dst, "DESeqTransform"))
stop("dds must be a DESeqTransform object")
}
output$ui_computetransform <- renderUI({
if (is.null(values$mydds))
return(NULL)
tagList(
h4("Select one of the following transformations for your count data:"),
actionButton("btn_computevst",
HTML("Compute variance stabilized </br>transformed data from the <code>dds</code> object"),
class = "btn btn-primary", icon = icon("spinner")),
actionButton("btn_computerlog",
HTML("Compute regularized logarithm </br>transformed data from the <code>dds</code> object"),
class = "btn btn-primary", icon = icon("spinner")),
actionButton("btn_computeshiftedlog",
HTML("Compute log2 data (with pseudocount 1)</br> from the <code>dds</code> object"),
class = "btn btn-primary", icon = icon("spinner"))
)
})
observeEvent(input$btn_computevst, {
withProgress(message = "Computing the variance stabilized transformed data...",
detail = "This step can take a little while",
value = 0, {
values$mydst <- vst(values$mydds)
values$transformation_type <- "vst"
})
})
observeEvent(input$btn_computerlog, {
withProgress(message = "Computing the rlog transformed data...",
detail = "This step can take a little while",
value = 0, {
values$mydst <- rlog(values$mydds)
values$transformation_type <- "rlog"
})
})
observeEvent(input$btn_computeshiftedlog,
{