Skip to content

Commit 0dcd458

Browse files
authored
Update app.R
1 parent 1a77467 commit 0dcd458

1 file changed

Lines changed: 131 additions & 3 deletions

File tree

fea/app.R

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ library(ggheatmap) #install dev github version
1212
library(ggplot2)
1313
library(ggpubr)
1414
library(ggrepel)
15-
library(ggtree)
15+
library(ggtree) #add
1616
library(gplots)
1717
library(gridExtra)
1818
library(markeR)
@@ -47,6 +47,9 @@ source("tab_SCORES/server.R")
4747
source("tab_GSEA/UI.R")
4848
source("tab_GSEA/server.R")
4949

50+
source("tab_PSEUDO/UI.R")
51+
source("tab_PSEUDO/server.R")
52+
5053
print("Successfully loaded tabs.")
5154

5255
#USER INFERFACE ----------------------------
@@ -80,8 +83,12 @@ tags$head(
8083
navbarPage("scStudio: FEA",
8184
tabPanel("Scores",
8285
tab_SCORES),
86+
#tabPanel("ORA",
87+
# tab_ORA),
8388
tabPanel("GSEA",
84-
tab_GSEA)
89+
tab_GSEA),
90+
tabPanel("Pseudobulk",
91+
tab_PSEUDO)
8592
)#close navbarPage
8693

8794
) #close UI
@@ -195,10 +202,18 @@ output$session_id <- renderText({ paste0("Session token: ", overall_vars$session
195202
else {overall_vars$dea <- list()
196203
save_session(overall_vars$session_token ,overall_vars, "dea")}
197204

198-
199205
overall_vars$md5$dea <- md5sum(
200206
paste0(getwd(),"/tokens/", overall_vars$session_token, "/dea.rds"))
201207

208+
if ("pseudobulk.rds" %in% files){
209+
overall_vars$pseudobulk <- upload_session(overall_vars$session_token, "pseudobulk")
210+
} #close if
211+
else {overall_vars$pseudobulk <- list()
212+
save_session(overall_vars$session_token ,overall_vars, "pseudobulk")}
213+
214+
overall_vars$md5$pseudobulk <- md5sum(
215+
paste0(getwd(),"/tokens/", overall_vars$session_token, "/pseudobulk.rds"))
216+
202217
if ("scores.rds" %in% files){
203218
overall_vars$scores <- upload_session(overall_vars$session_token, "scores")
204219
} #close if
@@ -210,6 +225,12 @@ output$session_id <- renderText({ paste0("Session token: ", overall_vars$session
210225
} #close if
211226
else {overall_vars$gsea <- list()
212227
save_session(overall_vars$session_token ,overall_vars, "gsea")}
228+
229+
updateSelectInput(session, "select_group_pseudo",
230+
choices = names(identify_discrete(overall_vars$metadata)),
231+
selected = "orig.ident")
232+
updateSelectInput(session, "select_condition_pseudo",
233+
choices = names(identify_discrete(overall_vars$metadata)))
213234

214235
} #close if
215236

@@ -282,6 +303,14 @@ output$session_id <- renderText({ paste0("Session token: ", overall_vars$session
282303
overall_vars$md5$dea <- md5sum(
283304
paste0(getwd(),"/tokens/", overall_vars$session_token, "/dea.rds"))
284305

306+
if ("pseudobulk.rds" %in% files){
307+
overall_vars$pseudobulk <- upload_session(overall_vars$session_token, "pseudobulk")
308+
} #close if
309+
else {overall_vars$pseudobulk <- list()
310+
save_session(overall_vars$session_token ,overall_vars, "pseudobulk")}
311+
312+
overall_vars$md5$pseudobulk <- md5sum(
313+
paste0(getwd(),"/tokens/", overall_vars$session_token, "/pseudobulk.rds"))
285314

286315
if ("scores.rds" %in% files){
287316
overall_vars$scores <- upload_session(overall_vars$session_token, "scores")
@@ -294,6 +323,12 @@ output$session_id <- renderText({ paste0("Session token: ", overall_vars$session
294323
} #close if
295324
else {overall_vars$gsea <- list()
296325
save_session(overall_vars$session_token ,overall_vars, "gsea")}
326+
327+
updateSelectInput(session, "select_group_pseudo",
328+
choices = names(identify_discrete(overall_vars$metadata)),
329+
selected = "orig.ident")
330+
updateSelectInput(session, "select_condition_pseudo",
331+
choices = names(identify_discrete(overall_vars$metadata)))
297332

298333
incProgress(1, detail = "Done.")
299334
}) #close progress
@@ -503,13 +538,56 @@ observe({
503538

504539
output$gset_pathway <- NULL}
505540

541+
if (input$select_database_pseudo != "Custom"){
542+
543+
output$gene_set_pseudo <- NULL
544+
545+
get_categories <- readRDS(paste0(getwd(), "/","/msigdbr_collections.rds"))
546+
547+
548+
if (input$select_database_pseudo %in% c("H", "C1", "C6", "C8")){
549+
options <- msigdbr(species = input$gset_scores_organism_pseudo, category = input$select_database_pseudo)
550+
options <- unique(options$gs_name)
551+
}
552+
else{
553+
cat <- get_categories[get_categories$gs_subcollection == input$select_database_pseudo, "gs_collection"]
554+
555+
options <- msigdbr(species = input$gset_scores_organism_pseudo, category = cat$gs_collection,
556+
subcategory = input$select_database_pseudo)
557+
558+
options <- unique(options$gs_name)
559+
}
560+
561+
output$gset_pathway_pseudo <- renderUI(selectInput(inputId = "gset_pathway_pseudo", label = "Gene Sets:",
562+
choices = options, multiple = TRUE))
563+
564+
} #close if
565+
566+
else {output$gene_set_pseudo <- renderUI(
567+
selectizeInput(inputId = "gene_set_pseudo",
568+
label = "Custom Gene Set:",
569+
choices = NULL,
570+
selected = NULL,
571+
multiple = TRUE,
572+
options = NULL))
573+
574+
updateSelectizeInput(session,
575+
"gene_set_pseudo",
576+
choices = overall_vars$genes,
577+
server = TRUE)
578+
579+
output$gset_pathway_pseudo <- NULL}
580+
506581
updateSelectInput(session, "select_matrix_scores",
507582
choices = overall_vars$mat_names[-1])
583+
updateSelectInput(session, "select_matrix_pseudo",
584+
choices = overall_vars$mat_names[-1])
508585

509586
updateSelectInput(session, "gset_var",
510587
choices = names(identify_discrete(overall_vars$metadata)),
511588
selected = "orig.ident")
512589

590+
513591
updateSelectInput(session, "select_gset_scores",
514592
choices = names(overall_vars$scores))
515593

@@ -767,6 +845,56 @@ output$table_gsea <- DT::renderDataTable({
767845
selection = 'single', server = FALSE)
768846
}) #close observeEvent
769847

848+
849+
# RUN PSEUDO --------------------------------------------------------------------
850+
observeEvent(input$calculate_pseudobulk, {
851+
852+
print("Running Pseudobulk")
853+
854+
withProgress(message = 'Running Pseudobulk...', value = 0, {
855+
overall_vars$countMatrices <- upload_session(overall_vars$session_token, "countMatrices")
856+
incProgress(0.4, detail = "")
857+
858+
try({
859+
pseudobulk <- make_pseudobulk(
860+
count_matrix = overall_vars$countMatrices[input$select_matrix_pseudo],
861+
metadata = overall_vars$metadata,
862+
group = overall_vars$metadata[,input$select_group_pseudo]
863+
)
864+
865+
866+
867+
#save_session(overall_vars$session_token, overall_vars, "pseudobulk")
868+
869+
870+
871+
output$marker <- renderPlot({
872+
873+
run_marker(organism = input$gset_scores_organism_pseudo,
874+
database = input$select_database_pseudo,
875+
pathways = input$gset_pathway_pseudo,
876+
count_matrix = pseudobulk[[1]],
877+
metadata = pseudobulk[[2]],
878+
condition = input$select_condition_pseudo,
879+
method = input$method_pseudobulk)
880+
}, height = 700, width = 1000)
881+
882+
output$marker_roc <- renderPlot({
883+
884+
run_marker_roc(organism = input$gset_scores_organism_pseudo,
885+
database = input$select_database_pseudo,
886+
pathways = input$gset_pathway_pseudo,
887+
count_matrix = pseudobulk[[1]],
888+
metadata = pseudobulk[[2]],
889+
condition = input$select_condition_pseudo,
890+
method = input$method_pseudobulk)
891+
}, height = 300, width = 1000)
892+
893+
})
894+
}) # close progress bar
895+
896+
})
897+
770898

771899
}#close server
772900

0 commit comments

Comments
 (0)