Skip to content

Commit 54ab025

Browse files
committed
Add markeR similarity heatmap
1 parent 5f6ec30 commit 54ab025

3 files changed

Lines changed: 104 additions & 11 deletions

File tree

‎fea/app.R‎

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ library(dplyr)
88
library(ff)
99
library(fgsea)
1010
library(ggheatmap) #install dev github version
11+
#devtools::install_github("XiaoLuo-boy/ggheatmap")
1112
library(ggplot2)
1213
library(ggpubr)
1314
library(ggrepel)
15+
library(ggtree) #add
1416
library(gplots)
1517
library(gridExtra)
1618
library(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 --------------------------------------------------------------------
625676
observeEvent(input$run_gsea, {

‎fea/tab_SCORES/UI.R‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ tab_SCORES <- tabItem(
5151
"CGP",
5252
"CP",
5353
"CP:BIOCARTA",
54-
"CP:KEGG",
54+
"CP:KEGG_LEGACY",
55+
"CP:KEGG_MEDICUS",
5556
"CP:PID",
5657
"CP:REACTOME",
5758
"CP:WIKIPATHWAYS",
5859
"MIR:MIRDB",
5960
"MIR:MIR_Legacy",
6061
"TFT:GTRD",
6162
"TFT:TFT_Legacy",
63+
"3CA",
6264
"CGN",
6365
"CM",
6466
"GO:BP",
@@ -78,7 +80,8 @@ tab_SCORES <- tabItem(
7880
actionButton(inputId = "calculate_gset_score",
7981
label = "Calculate"),
8082

81-
h4("Plotting"),
83+
h3("Plotting"),
84+
h4("Cell Scores Heatmap"),
8285

8386
selectInput(inputId = "select_gset_scores",
8487
label = "Gene set scores:",
@@ -104,6 +107,22 @@ tab_SCORES <- tabItem(
104107
inline = TRUE),
105108

106109
actionButton(inputId = "plot_gset_scores", label = "Plot heatmap"),
110+
111+
h4("Gene Set Similarity Heatmap"),
112+
selectInput(inputId = "select_gsets",
113+
label = "Gene sets:",
114+
choices = c("-"),
115+
multiple = TRUE),
116+
117+
p("Choose at least 2 gene sets to view heatmap."),
118+
119+
radioButtons( inputId = "similarity_option",
120+
label = "Metric:",
121+
choices = c("Jaccard index", "Odds ratio"),
122+
selected = "Jaccard index",
123+
inline = TRUE),
124+
125+
actionButton(inputId = "plot_gset_similarity", label = "Plot heatmap")
107126
), #close sidebarPanel
108127

109128
mainPanel(
@@ -114,7 +133,15 @@ tab_SCORES <- tabItem(
114133
type = 5),
115134
width = NULL) #, height = 150
116135
) #close column
117-
) #close fluidrow
136+
), #close fluidrow
137+
fluidRow(
138+
column(width = 10,
139+
box(withSpinner(
140+
plotOutput(outputId = "gsets_similarity_heatmap"),
141+
type = 5),
142+
width = NULL) #, height = 150
143+
) #close column
144+
) #close fluidrow
118145
) #close mainPanel
119146
) #close sidebarlayout
120147
) #close FEA

‎fea/tab_SCORES/server.R‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ get_score_pathways <- function(mat_name, mat, organism, database, pathways, name
5151

5252

5353
plot_gset_heatmap <- function(scores, ids, cluster, scale, selected_cols, groups){
54-
55-
print(sessionInfo())
56-
54+
5755
df <- data.frame(cells = names(scores[[1]]))
5856
for (score in ids){
5957
#print(score)
@@ -110,7 +108,7 @@ plot_gset_heatmap <- function(scores, ids, cluster, scale, selected_cols, groups
110108
if (scale == "none") {legend_name <- "log2(counts + 1)"
111109
} else {legend_name <- "Z-score"}
112110

113-
ggheatmap::ggheatmap(data = mat,
111+
p <- ggheatmap::ggheatmap(data = mat,
114112
color = colorRampPalette(c( "#0000ff","#fad541","#b60404"))(100),
115113
cluster_rows = clust_rows,
116114
cluster_cols = clust_cols,
@@ -120,6 +118,23 @@ plot_gset_heatmap <- function(scores, ids, cluster, scale, selected_cols, groups
120118
annotation_cols = col_metaData,
121119
annotation_color = col
122120
)
121+
122+
g <- ggheatmap_theme(ggheatmap = p,
123+
plotlist = c(1,2),
124+
theme =list(
125+
126+
theme(axis.title.x=element_blank(),
127+
text = element_text(size=20),
128+
axis.text.x=element_blank(),
129+
axis.ticks.x=element_blank()),
130+
131+
theme(
132+
legend.title = element_text(size = 18),
133+
legend.text = element_text(size= 18))
134+
)
135+
)
136+
g
137+
123138
}
124139

125140
plot_pathway <- function(selected_pathway, nrank, species){
@@ -135,4 +150,4 @@ plot_pathway <- function(selected_pathway, nrank, species){
135150

136151

137152

138-
153+

0 commit comments

Comments
 (0)