From b14fddf8fe39899b525cc84506054f8bc2e7a91f Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Tue, 22 Mar 2022 16:29:04 +0100 Subject: [PATCH 1/4] Visor scRNAseq. --- BDAccess/app.R | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/BDAccess/app.R b/BDAccess/app.R index e360628..b4b4c0c 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -1,5 +1,9 @@ library(shiny) library(rhandsontable) +library(tidyverse) +library(reshape2) +library(Matrix) +library(CitFuns) print(getwd()) source("../sqlFunctions.R", encoding = "UTF-8") @@ -59,6 +63,19 @@ ui <- fluidPage( h3("Nitrogen"), tableOutput("nitrogen") ) + ), + tabPanel("scRNAseq", + sidebarPanel( + textInput("sqlquery", label = "sqlquery", value = ""), + uiOutput("PATID"), + checkboxInput("cd45_chk", "Purificación CD45") + ), + mainPanel( + tabsetPanel( + tabPanel("Table", tableOutput("sc_table")), + tabPanel("Plots", plotOutput("sc_plot")) + ) + ) ) ) ) @@ -677,6 +694,56 @@ server <- function(input, output) { ## scRNAseq + output$PATID = renderUI({ + observeEvent(input$goButton, {}) + sc_cod<-sqlFetch(dta, "CNAG") %>% pull(CODIGO) + selectizeInput("sc_cod", "CÓDIGO", sc_cod, multiple = T) + }) + + 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) + }else{ + sqlFetch(dta, "CNAG") + } + } + }) + + output$sc_plot <-renderPlot({ + meta<-readRDS(paste0(scRNAseqRoute,"metadata_full_object.rds")) + + if (input$sqlquery != ""){ + sc_codigos<-sqlQuery(dta, input$sqlquery) %>% pull(CNAG_NAME) + }else{ + if (!is.null(input$sc_cod)){ + sc_codigos<-sqlFetch(dta, "CNAG") %>% filter(CODIGO %in% input$sc_cod) %>% pull(CNAG_NAME) + }else{ + sc_codigos<-sqlFetch(dta, "CNAG") %>% pull(CNAG_NAME) + } + } + sc_codigos<-gsub(" _","_", sc_codigos ) + sc_codigos<-gsub("_ ","_", sc_codigos ) + sc_codigos<-gsub(" ","_", sc_codigos ) + + meta<-meta %>% mutate(sample2=gsub("_CD45", "", sample)) %>% filter(sample2 %in% sc_codigos) + if (isFALSE(input$cd45_chk)){ meta<-meta %>% filter(!grepl("_CD45", sample))} + + g1<-ggplot(meta, aes(coord_x, coord_y, color=predicted.id))+ + geom_point(size=0.2)+ + guides(colour = guide_legend(override.aes = list(size=2)))+ + theme_bw()+ + theme(aspect.ratio = 1) + + meta_perc<-meta %>% group_by(sample, predicted.id) %>% summarise(N=n()) %>% mutate(N=perc(N)) %>% + 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) + } # Run the application 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 2/4] =?UTF-8?q?A=C3=B1adido=20plot=20para=20expresi=C3=B3n?= =?UTF-8?q?=20de=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 From ea45d8c845f167fc770bacd5fb601be1f5626665 Mon Sep 17 00:00:00 2001 From: Costa <47926492N@ICO.SCS.local> Date: Thu, 31 Mar 2022 13:40:47 +0200 Subject: [PATCH 3/4] merge with nitro --- BDAccess/app.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/BDAccess/app.R b/BDAccess/app.R index 99ff87f..f1143cd 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -1,13 +1,10 @@ library(shiny) library(rhandsontable) -<<<<<<< HEAD library(tidyverse) library(reshape2) library(Matrix) library(CitFuns) -======= library(BDCIT) ->>>>>>> main print(getwd()) source("../sqlFunctions.R", encoding = "UTF-8") From 44901be4907eae16ba5172bc0c2eca3744bea3c2 Mon Sep 17 00:00:00 2001 From: marcelcosta Date: Fri, 1 Apr 2022 12:26:04 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Corregir=20a=C3=B1o=20en=20la=20fecha=20de?= =?UTF-8?q?=20tabla=20clinics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BDAccess/app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BDAccess/app.R b/BDAccess/app.R index 5ea68ad..bbbc7e6 100644 --- a/BDAccess/app.R +++ b/BDAccess/app.R @@ -206,7 +206,7 @@ server <- function(input, output) { if (!is.null(CLINICS)){ rhandsontable(values[["CLINICS"]], stretchH = "all", readOnly = F, useTypes = T) %>% hot_col(values[["CLINICS"]] %>% select(lubridate::is.Date) %>% colnames, - dateFormat = "DD/MM/YY", type = "date") + dateFormat = "DD/MM/YYYY", type = "date") } })