From 2909f49eecc0c7dc780230c5c63ac85b5ed2c936 Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Mon, 28 Mar 2022 12:49:29 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20plot=20para=20expresi=C3=B3n=20d?= =?UTF-8?q?e=20genes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BDAccess/app.R | 65 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/BDAccess/app.R b/BDAccess/app.R index b4b4c0c..31a7971 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -68,12 +68,16 @@ ui <- fluidPage( sidebarPanel( textInput("sqlquery", label = "sqlquery", value = ""), uiOutput("PATID"), - checkboxInput("cd45_chk", "Purificación CD45") + checkboxInput("sct_sel", "Mostrar filtrados"), + checkboxInput("cd45_chk", "Purificación CD45"), + textInput("genes", label="genes", value = "") ), mainPanel( tabsetPanel( tabPanel("Table", tableOutput("sc_table")), - tabPanel("Plots", plotOutput("sc_plot")) + tabPanel("Plots", + plotOutput("sc_plot", height = "1000px"), + plotOutput("sc_expr"), height = "600px") ) ) ) @@ -701,20 +705,25 @@ server <- function(input, output) { }) output$sc_table<-renderTable({ - if (input$sqlquery != ""){ - print(input$sqlquery) - sqlQuery(dta, input$sqlquery) - }else{ - if (!is.null(input$sc_cod)){ - sqlFetch(dta, "CNAG") %>% filter(CODIGO %in% input$sc_cod) + if (input$sct_sel){ + if (input$sqlquery != ""){ + print(input$sqlquery) + sqlQuery(dta, input$sqlquery) }else{ - sqlFetch(dta, "CNAG") + if (!is.null(input$sc_cod)){ + sqlFetch(dta, "CNAG") %>% filter(CODIGO %in% input$sc_cod) + }else{ + sqlFetch(dta, "CNAG") + } } + }else{ + sqlFetch(dta, "CNAG") } + }) output$sc_plot <-renderPlot({ - meta<-readRDS(paste0(scRNAseqRoute,"metadata_full_object.rds")) + meta<<-readRDS(paste0(scRNAseqRoute,"metadata_full_object.rds")) if (input$sqlquery != ""){ sc_codigos<-sqlQuery(dta, input$sqlquery) %>% pull(CNAG_NAME) @@ -742,8 +751,42 @@ server <- function(input, output) { spread(predicted.id, N) %>% gather("predicted.id","N",-sample) %>% mutate(N=case_when(is.na(N)~0,TRUE~N)) g2<-ggheatmap(meta_perc, "sample","predicted.id", "N", color = "grey50") ggpubr::ggarrange(g1,g2, ncol=1, heights = c(0.3, 0.7)) - }, height = 1000) + }) + + output$sc_expr <-renderPlot({ + if (input$genes != ""){ + expr<-readRDS(paste0(scRNAseqRoute,"expression_full_object.rds")) + genes<-strsplit(input$genes, ",")[[1]] + if (length(genes) > 1){ + df.expr<-as.data.frame(as.matrix(expr[genes,])) + df.expr["Gene"]<-rownames(df.expr) + mdf.expr<-melt(df.expr) + }else{ + df.expr<-as.data.frame(t(as.matrix(expr[genes[1],]))) + df.expr["Gene"]<-genes[1] + mdf.expr<-melt(df.expr) + } + + alldata<-merge(meta, mdf.expr, by.x="barcode", by.y = "variable") + + } + + # order <- clustsort(alldata %>% spread(Gene, value) %>% select(predicted.id, all_of(genes)) %>% + # group_by(predicted.id) %>% summarise(across(all_of(genes), mean)) %>% as.data.frame) + # + # g1<-ggplot(alldata, aes(predicted.id, value, fill=predicted.id))+ + # geom_violin(scale = "width")+ + # geom_jitter(width=0.2, size=0.1, alpha=0.3)+ + # scale_x_discrete(limits=order$x)+ + # guides(fill=F)+ + # facet_wrap(.~Gene)+ + # theme_bw()+ + # theme(axis.text.x = element_text(angle=90, hjust=1, vjust = 0.5)) + g2<-ggheatmap(alldata, x="predicted.id",y="Gene",value="value", color="grey")+coord_equal() + # ggpubr::ggarrange(g1,g2, ncol=1) + g2 + }) } # Run the application