@@ -8,9 +8,11 @@ library(dplyr)
88library(ff )
99library(fgsea )
1010library(ggheatmap ) # install dev github version
11+ # devtools::install_github("XiaoLuo-boy/ggheatmap")
1112library(ggplot2 )
1213library(ggpubr )
1314library(ggrepel )
15+ library(ggtree ) # add
1416library(gplots )
1517library(gridExtra )
1618library(Matrix )
@@ -466,14 +468,17 @@ observe({
466468 output $ gene_set <- NULL
467469
468470 get_categories <- readRDS(paste0(getwd(), " /" ," /msigdbr_collections.rds" ))
471+
469472
470473 if (input $ select_database %in% c(" H" , " C1" , " C6" , " C8" )){
471474 options <- msigdbr(species = input $ gset_scores_organism , category = input $ select_database )
472475 options <- unique(options $ gs_name )
473476 }
474477 else {
475- cat <- get_categories [get_categories $ gs_subcat == input $ select_database , " gs_cat" ]
476- options <- msigdbr(species = input $ gset_scores_organism , category = cat , subcategory = input $ select_database )
478+ cat <- get_categories [get_categories $ gs_subcollection == input $ select_database , " gs_collection" ]
479+
480+ options <- msigdbr(species = input $ gset_scores_organism , category = cat $ gs_collection , subcategory = input $ select_database )
481+
477482 options <- unique(options $ gs_name )
478483 }
479484
@@ -507,6 +512,9 @@ observe({
507512 updateSelectInput(session , " select_gset_scores" ,
508513 choices = names(overall_vars $ scores ))
509514
515+ updateSelectInput(session , " select_gsets" ,
516+ choices = names(overall_vars $ scores ))
517+
510518 updateSelectizeInput(session ,
511519 " featplot_gsets" ,
512520 choices = names(overall_vars $ scores ),
@@ -592,6 +600,9 @@ observeEvent(input$calculate_gset_score,{
592600 choices = names(overall_vars $ scores ),
593601 selected = NULL )
594602
603+ updateSelectInput(session , " select_gsets" ,
604+ choices = names(overall_vars $ scores ))
605+
595606 updateSelectizeInput(session ,
596607 " gene_set" ,
597608 choices = overall_vars $ genes ,
@@ -617,9 +628,49 @@ observeEvent(input$plot_gset_scores ,{
617628 selected_cols = overall_vars $ colours [[input $ gset_var ]],
618629 groups = overall_vars $ metadata [[input $ gset_var ]])
619630 p
620- }, height = 800 , width = 1500 ), input $ plot_gset_scores )
631+ }, height = 400 , width = 1000 ), input $ plot_gset_scores )
621632 }
622633 })
634+
635+ observeEvent(input $ plot_gset_similarity ,{
636+
637+ if (length(input $ select_gsets ) > 1 ){
638+
639+
640+ output $ gsets_similarity_heatmap <- bindEvent(renderPlot({
641+
642+ signature_list <- list ()
643+ print(input $ select_gsets )
644+ for (gset in input $ select_gsets ){
645+ print(gset )
646+ signature_list [[gset ]] <- overall_vars $ report $ scores [[gset ]]$ genes
647+ }
648+
649+ if (input $ similarity_option == " Jaccard index" ){
650+ p <- markeR :: geneset_similarity(
651+ signatures = signature_list ,
652+ other_user_signatures = signature_list ,
653+ jaccard_threshold = 0.05 ,
654+ msig_subset = NULL ,
655+ metric = " jaccard"
656+ )$ plot
657+
658+ }
659+ else {
660+ p <- markeR :: geneset_similarity(
661+ signatures = signature_list ,
662+ other_user_signatures = signature_list ,
663+ msig_subset = NULL ,
664+ metric = " odds_ratio" ,
665+ universe = overall_vars $ genes # ,
666+ # or_threshold = 100,
667+ # pval_threshold = 0.05
668+ )$ plot
669+ }
670+ p
671+ }, height = 400 , width = 750 ), input $ plot_gset_similarity )
672+ }
673+ })
623674
624675# RUN GSEA --------------------------------------------------------------------
625676observeEvent(input $ run_gsea , {
0 commit comments