Compare commits

..

5 Commits

Author SHA1 Message Date
marcelcosta 405cecf236 Start new branch 2023-10-05 12:22:18 +02:00
marcelcosta ff1a7e1ff5 Faltaba cargar la librería ggpubr 2023-10-04 17:12:51 +02:00
marcelcosta 17d700e44e Ordenar secciones. 2023-10-04 15:36:12 +02:00
marcelcosta e185aa2935 Soporte para Modulos (Signaturas). 2023-10-04 15:25:28 +02:00
marcelcosta a9377f2494 Visor de genes. 2023-10-03 19:35:08 +02:00
+85 -4
View File
@@ -2,6 +2,8 @@ library(shiny)
library(Seurat) library(Seurat)
library(shinyFiles) library(shinyFiles)
library(ggplot2) library(ggplot2)
library(ggpubr)
# Define UI for application # Define UI for application
ui <- fluidPage( ui <- fluidPage(
@@ -13,20 +15,33 @@ ui <- fluidPage(
sidebarPanel( sidebarPanel(
shinyFilesButton("file", label="Select File", title="Select a Seurat Object", multiple=F), shinyFilesButton("file", label="Select File", title="Select a Seurat Object", multiple=F),
uiOutput('groupby'), uiOutput('groupby'),
uiOutput('facetby') uiOutput('facetby'),
textInput('features', label = "Genes"),
textInput('mods', label = "Signatures"),
actionButton("goButton", "Query"),
sliderInput("height", "Altura", min=1000, max=20000, step=1000, value=6000),
h3("Add Signature"),
textInput('mod_name', label = "Name"),
textInput('mod_feat', label = "Genes"),
actionButton("modButton", "Add Signature")
), ),
mainPanel( mainPanel(
plotOutput("umapPlot") plotOutput("umapPlot"),
uiOutput("featPlotUI")
) )
) )
) )
# Define server logic required to draw a histogram # Define server logic
server <- function(input, output) { server <- function(input, output) {
## Defining reactive values
dades<-reactiveValues() dades<-reactiveValues()
dades$seu<-NULL dades$seu<-NULL
dades$mods<-NULL
## Conecting with file location and entering Seurat object
volumes <- c(Home = fs::path_home(), "R Installation" = R.home(), getVolumes()()) volumes <- c(Home = fs::path_home(), "R Installation" = R.home(), getVolumes()())
shinyFileChoose(input, 'file', roots=volumes) shinyFileChoose(input, 'file', roots=volumes)
@@ -36,6 +51,7 @@ server <- function(input, output) {
} }
}) })
## Rendering UI depending on seu meta.data
output$groupby<-renderUI({ output$groupby<-renderUI({
if (!is.null(dades$seu)){ if (!is.null(dades$seu)){
selectInput("groupby", "GroupBy", c("Default", colnames(dades$seu@meta.data))) selectInput("groupby", "GroupBy", c("Default", colnames(dades$seu@meta.data)))
@@ -48,6 +64,7 @@ server <- function(input, output) {
} }
}) })
## Render DimPlot
output$umapPlot <- renderPlot({ output$umapPlot <- renderPlot({
observeEvent(dades$seu, {}) observeEvent(dades$seu, {})
if (!is.null(dades$seu)){ if (!is.null(dades$seu)){
@@ -57,9 +74,73 @@ server <- function(input, output) {
split.by=if(input$facetby != "None"){input$facetby}else{NULL})+ split.by=if(input$facetby != "None"){input$facetby}else{NULL})+
theme(aspect.ratio=1) theme(aspect.ratio=1)
plot plot
} }
}) })
## Signature - Module Definition
observeEvent(input$modButton, {
if (input$modButton > 0){
mod_list<-strsplit(input$mod_feat, " ")[[1]]
mod_list<-mod_list[mod_list %in% rownames(dades$seu)]
dades$seu<-AddModuleScore(dades$seu,list(mod_list),
name=input$mod_name)
}
})
## FeaturePlot construction
query<-eventReactive(input$goButton,{
dades$fet_query<-strsplit(input$features, " ")[[1]]
})
output$featPlotUI<- renderUI({
observeEvent(dades$fet_query, {})
if (!is.null(dades$seu)){
plotOutput("featPlot",
height = paste0(input$height/10,"px"))
}
})
## ModulePlot/SigPlot construction
query_mod<-eventReactive(input$goButton,{
if (length(strsplit(input$mods, " ")[[1]]) > 0){
dades$mods<-paste(strsplit(input$mods, " ")[[1]], "1", sep="")
}else{
dades$mods<-NULL
}
})
output$modPlotUI<- renderUI({
observeEvent(dades$mod_name, {})
if (!is.null(dades$mod_name)){
plotOutput("modPlot",
height = paste0(input$height/10,"px"))
}
})
## Feature/Mod plot rendering
output$featPlot<-renderPlot({
observeEvent(input$goButton, {})
if (!is.null(dades$seu)){
query()
plot<-list()
print(dades$fet_query)
if (length(dades$fet_query) > 0){
plot[["Genes"]]<-FeaturePlot(dades$seu,
split.by=if(input$facetby != "None"){input$facetby}else{NULL},
features = dades$fet_query)&theme(aspect.ratio = 1)
}
query_mod()
print(dades$mods)
if (length(dades$mods) > 0){
plot[["Mods"]]<-FeaturePlot(dades$seu,
split.by=if(input$facetby != "None"){input$facetby}else{NULL},
features = dades$mods)&theme(aspect.ratio = 1)&scale_color_viridis_c()
}
do.call(ggarrange, c(plot, ncol=1))
}
})
} }
# Run the application # Run the application