Commit 3ccf7055 authored by Bagueneau Mathias's avatar Bagueneau Mathias
Browse files

- Ajout d'un second filtre de Factors possible pour la page Compare (rendant...

- Ajout d'un second filtre de Factors possible pour la page Compare (rendant pour l'instant le calcul de marqueurs impossible...)
parent 0985ef52
......@@ -4,7 +4,9 @@
*Jean-Baptiste Alberge, Jonathan Cruard, Mathias Bagueneau*
</br>
**Direct Link of the Tool :** https://shiny-bird.univ-nantes.fr/jbalberge/schnurr/
......@@ -29,9 +31,9 @@ The *rds files used must have been made with the pipeline available at this adre
Here the list of the required packages for Shiny SChnurR :
* [shiny][shiny]
* shinythemes
* [Seurat][Seurat] : **The version 3 is required !**
* [sctransform][sctransform]
* shinythemes
* dplyr
* ggplot2
* viridis
......
......@@ -195,8 +195,8 @@ body <- dashboardBody(
br(),
conditionalPanel(condition="output.fileUploaded",
fluidRow(column(align="center", width = 2, plotOutput(outputId="miniplot_compare", width="250px", height="250px"), br(), plotOutput(outputId="miniplot_compare2", width="250px", height="250px")),
column(align="center", width = 5, plotlyOutput("plot1_compare", width="450px", height="450px"), br(), uiOutput("plot1_library"), downloadButton("dl_compare1", label="")),
column(align="center", width = 5, plotlyOutput("plot2_compare", width="450px", height="450px"), br(), uiOutput("plot2_library"), downloadButton("dl_compare2", label=""))
column(align="center", width = 5, plotlyOutput("plot1_compare", width="450px", height="450px"), br(), uiOutput("plot1_library"), div(actionLink("add1", "", icon = icon("far fa-plus-square")), align="center"),uiOutput("addf1"), uiOutput("addg1"), br(), downloadButton("dl_compare1", label="")),
column(align="center", width = 5, plotlyOutput("plot2_compare", width="450px", height="450px"), br(), uiOutput("plot2_library"), div(actionLink("add2", "", icon = icon("far fa-plus-square")), align="center"),uiOutput("addf2"), uiOutput("addg2"), br(), downloadButton("dl_compare2", label=""))
),
br(),
uiOutput(align="left","markbutton"), uiOutput(align="left","dlmarkbutton_compare"), br(),
......@@ -307,14 +307,21 @@ server <- function(input, output, session) {
plot1_compareData <- reactive ({
scalex <- scale_x_continuous(limits = c(min(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1])))
scaley <- scale_y_continuous(limits = c(min(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1])))
cells_to_plot <- rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library1_compare)]
if (input$add1 %% 2 != 0) {
subset1 <- SubsetData(object = filedata$data, cells=rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library1_compare)] )
cells_to_plot1 <- SubsetData(object = subset1, cells=rownames(subset1@meta.data)[which(eval(parse(text=paste0("subset1@meta.data$",input$add_factor1))) %in% input$add_group1)])
} else {
cells_to_plot1 <- SubsetData(object = filedata$data, cells=rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library1_compare)] )
}
if (input$choice_compare == "f_compare") {
withProgress(DimPlot(object = filedata$data, cells=cells_to_plot, label=FALSE, pt.size = input$ptsize_compare, reduction=input$graph_compare, group.by = input$fsel2), message = "Plot Generation", value=1) + NoLegend() + theme_bw() + NoAxes() + ggtitle(paste(filedata$name,"-", input$fsel2)) + scalex + scaley
withProgress(DimPlot(object = filedata$data, cells=rownames(cells_to_plot1@meta.data), label=FALSE, pt.size = input$ptsize_compare, reduction=input$graph_compare, group.by = input$fsel2), message = "Plot Generation", value=1) + NoLegend() + theme_bw() + NoAxes() + ggtitle(paste(filedata$name,"-",input$fsel2)) + scalex + scaley
} else {
if (input$featuresel2 =="d2") {
withProgress(FeaturePlot(object = filedata$data, cells=cells_to_plot, cols=c("lightgrey",plasma(ceiling(max(eval(parse(text=paste0("filedata$data@meta.data$",input$nsel2))))))), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Feature Plot -", input$nsel2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
withProgress(FeaturePlot(object = filedata$data, cells=rownames(cells_to_plot1@meta.data), cols=c("lightgrey",plasma(ceiling(max(eval(parse(text=paste0("filedata$data@meta.data$",input$nsel2))))))), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Feature Plot -", input$nsel2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
} else if (input$featuresel2 =="g2") {
withProgress(FeaturePlot(object = filedata$data, cells=cells_to_plot, cols=c("lightgrey",plasma(ceiling(max(filedata$data@assays$SCT@data[input$genes2,])))), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Gene Plot -", input$genes2)) +scalex + scaley #+ aes(text=Cells(filedata$data))
withProgress(FeaturePlot(object = filedata$data, cells=rownames(cells_to_plot1@meta.data), cols=c("lightgrey",plasma(ceiling(max(filedata$data@assays$SCT@data[input$genes2,])))), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Gene Plot -", input$genes2)) +scalex + scaley #+ aes(text=Cells(filedata$data))
}
}
})
......@@ -323,19 +330,29 @@ server <- function(input, output, session) {
# df.colors <- data.frame(class=unique(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2)))), color="viridis"(length(unique(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2)))))))
scalex <- scale_x_continuous(limits = c(min(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1])))
scaley <- scale_y_continuous(limits = c(min(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(filedata$data@reductions[[input$graph_compare]]@cell.embeddings[,1])))
cells_to_plot <- rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library2_compare)]
if (input$add2 %% 2 != 0) {
subset2 <- SubsetData(object = filedata$data, cells=rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library2_compare)] )
cells_to_plot2 <- SubsetData(object = subset2, cells=rownames(subset2@meta.data)[which(eval(parse(text=paste0("subset2@meta.data$",input$add_factor2))) %in% input$add_group2)])
} else {
cells_to_plot2 <- SubsetData(object = filedata$data, cells=rownames(filedata$data@meta.data)[which(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel2))) %in% input$library2_compare)] )
}
if (input$choice_compare == "f_compare") {
withProgress(DimPlot(object = filedata$data,cells=cells_to_plot, pt.size = input$ptsize_compare, reduction=input$graph_compare, group.by = input$fsel2), message = "Plot Generation", value=1) + NoLegend() + theme_bw() + NoAxes() + ggtitle(paste(filedata$name,"-", input$fsel2)) + scalex + scaley
withProgress(DimPlot(object = filedata$data,cells=rownames(cells_to_plot2@meta.data), pt.size = input$ptsize_compare, reduction=input$graph_compare, group.by = input$fsel2), message = "Plot Generation", value=1) + NoLegend() + theme_bw() + NoAxes() + ggtitle(paste(filedata$name,"-", input$fsel2)) + scalex + scaley
# cols = df.colors[df.colors$class==input$library2_compare, "color"],
} else {
if (input$featuresel2 =="d2") {
withProgress(FeaturePlot(object = filedata$data , cells=cells_to_plot, cols=c("lightgrey",plasma(ceiling(max(eval(parse(text=paste0("filedata$data@meta.data$",input$nsel2))))))), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Feature Plot -", input$nsel2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
withProgress(FeaturePlot(object = filedata$data , cells=rownames(cells_to_plot2@meta.data), cols=c("lightgrey",plasma(ceiling(max(eval(parse(text=paste0("filedata$data@meta.data$",input$nsel2))))))), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Feature Plot -", input$nsel2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
} else if (input$featuresel2 =="g2") {
withProgress(FeaturePlot(object = filedata$data , cells=cells_to_plot, cols=c("lightgrey",plasma(ceiling(max(filedata$data@assays$SCT@data[input$genes2,])))), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Gene Plot -", input$genes2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
withProgress(FeaturePlot(object = filedata$data , cells=rownames(cells_to_plot2@meta.data), cols=c("lightgrey",plasma(ceiling(max(filedata$data@assays$SCT@data[input$genes2,])))), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoAxes() + ggtitle(paste(filedata$name,"- Gene Plot -", input$genes2)) + scalex + scaley #+ aes(text=Cells(filedata$data))
}
}
})
cells_to_plot1 <- reactiveValues()
cells_to_plot2 <- reactiveValues()
## Graphs & Tables Outputs --------
output$plot_factors <-renderPlotly ({
req(filedata$data)
......@@ -563,6 +580,15 @@ server <- function(input, output, session) {
selectizeInput("fsel4", "Choose a Factor :", choices = names(rapply(filedata$data@meta.data, class=c("factor","character"), f=class)), selected = "SCT_snn_res.0.4")
})
output$addf1 <-renderUI({ # Add Compare Page 1
req(input$add1 %% 2 != 0)
selectizeInput("add_factor1", "Add a Factor :", choices = names(rapply(filedata$data@meta.data, class=c("factor","character"), f=class)), selected = input$fsel2)
})
output$addf2 <-renderUI({ # Add Compare Page 2
req(input$add2 %% 2 != 0)
selectizeInput("add_factor2", "Add a Factor :", choices = names(rapply(filedata$data@meta.data, class=c("factor","character"), f=class)), selected = input$fsel2)
})
## Link the choices --
observeEvent ({
input$fsel
......@@ -619,6 +645,22 @@ server <- function(input, output, session) {
selectInput("library2_compare", "Choose a group :",multiple = TRUE, choices = choice[order(choice)])
})
output$addg1 <- renderUI ({
req(filedata$data)
req(input$add1 %% 2 != 0)
choice <- unique(eval(parse(text=paste0("filedata$data@meta.data$",input$add_factor1))))
req(!is.na(choice))
selectInput("add_group1", "Add a group :", multiple = TRUE, choices = choice[order(choice)])
})
output$addg2 <- renderUI ({
req(filedata$data)
req(input$add2 %% 2 != 0)
choice <- unique(eval(parse(text=paste0("filedata$data@meta.data$",input$add_factor2))))
req(!is.na(choice))
selectInput("add_group2", "Add a group :", multiple = TRUE, choices = choice[order(choice)])
})
output$group <- renderUI ({ # Genes Page
req(filedata$data)
choice <- unique(eval(parse(text=paste0("filedata$data@meta.data$",input$fsel4))))
......@@ -651,16 +693,17 @@ server <- function(input, output, session) {
})
observeEvent(input$findmarkers, {
if (is.null(input$library1_compare) || is.null(input$library2_compare)) {
showModal(modalDialog("At least one of the select is empty !", title=strong("Warning !"), easyClose=TRUE, footer = NULL ))
} else if (length(intersect(input$library1_compare,input$library2_compare)) != 0) {
showModal(modalDialog("You must choose only different groups.", title=strong("Warning !"), easyClose=TRUE, footer = NULL ))
} else {
# if (is.null(rownames(cells_to_plot1@meta.data)) || is.null(rownames(cells_to_plot2@meta.data))) {
# showModal(modalDialog("At least one of the select is empty !", title=strong("Warning !"), easyClose=TRUE, footer = NULL ))
# } else if (length(intersect(rownames(cells_to_plot1@meta.data),rownames(cells_to_plot2@meta.data))) != 0) {
# showModal(modalDialog("You must choose only different groups.", title=strong("Warning !"), easyClose=TRUE, footer = NULL ))
# } else {
if (!exists("ffm")) {
ffm <- filedata$data
ffm <- filedata$data
}
# Problème des Idents (lequel choisir ?) et du type d'objet de cells_to_plot...)
Idents(object=ffm) <- input$fsel2
df <- withProgress(data.frame(FindMarkers(ffm, input$library1_compare,input$library2_compare, test.use = "MAST")), message = "Preparing data", value=1)
df <- withProgress(data.frame(FindMarkers(ffm, cells_to_plot1,cells_to_plot2, test.use = "MAST")), message = "Preparing data", value=1)
setDT(df, keep.rownames = TRUE)[]
df <- data.frame(c(df,(input$fsel2)))
names(df)[[1]] <- "Gene"
......@@ -682,7 +725,7 @@ server <- function(input, output, session) {
write.csv(df, file, row.names=FALSE)
}
)
}
# }
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment