app.R 57.4 KB
Newer Older
1
# Load packages --------
2
3
library(shiny)
library(shinythemes)
4
5
6
library(Seurat)
library(dplyr)
library(sctransform)
7
8
library(ggplot2)
library(viridis)
9
10
library(stringr)
library(plotly)
Bagueneau Mathias's avatar
Bagueneau Mathias committed
11
library(BiocManager)
12
library(shinydashboard)
13
library(shinyjs)
14
15
library(DT)          
library(RColorBrewer) 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
16
library(MAST)     
17
library(data.table)
18
library(clusterProfiler)
19
library(org.Hs.eg.db) 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
20
library(tools)
21
library(PANTHER.db)
22

23
24
25

### ----------------------------- User interface -----------------------------------------------------

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## HEADER --------
useShinyjs()
header <- dashboardHeader(tags$li(class="dropdown",
                                  conditionalPanel(condition="input.tabs == 'visu_item'",
                                                   tags$p(style="color:white;font-size:25px;margin-right:20px","- Visualization -")), 
                                  conditionalPanel(condition="input.tabs == 'heatmap_item'",
                                                   tags$p(style="color:white;font-size:25px;margin-right:20px","- HeatMap -")),
                                  conditionalPanel(condition="input.tabs == 'genes_item'",
                                                   tags$p(style="color:white;font-size:25px;margin-right:20px","- Genes -")),
                                  conditionalPanel(condition="input.tabs == 'compare_item'",
                                                   tags$p(style="color:white;font-size:25px;margin-right:20px","- Compare -")),
                                  conditionalPanel(condition="input.tabs == 'pipeline_item'",
                                                   tags$p(style="color:white;font-size:25px;margin-right:20px","- Pipeline -")),
                                  tags$head(HTML("<link rel='icon' href='min.png'>"))
))
anchor <- tags$a(tags$img(src='logo.png', height='30', width='20'),'Shiny SChnurR', style="color: white")
header$children[[2]]$children <- tags$div(tags$head(tags$style(HTML(".name { background-color:  transparent } .content-wrapper, .right-side {background-color: white}"))),anchor)    
header[["children"]][[2]][["children"]][["name"]] <- "Shiny SChnurR"

## SIDEBAR --------
46
sidebar <- dashboardSidebar(
47
48
49
50
  tags$style(type="text/css",
             ".shiny-output-error { visibility: hidden; }",
             ".shiny-output-error:before { visibility: hidden; }"
  ),
51
  br(),
52
  # Menu -------
53
54
  sidebarMenu(id="tabs",
              menuItem("Visualization", tabName="visu_item", icon=icon("area-chart"), selected = TRUE),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
55
              menuItem("HeatMap", tabName = "heatmap_item", icon=icon("fas fa-align-justify")),
56
57
              menuItem("Genes", tabName = "genes_item", icon=icon("dna")),
              menuItem("Compare", tabName="compare_item", icon = icon("table")),
58
              menuItem("Pipeline", tabName="pipeline_item", icon = icon("fas fa-bezier-curve")),
59
              menuItem("About", tabName = "about_item", icon = icon("far fa-id-card"))
60
61
  ),
  br(),
62
  # Genes Panel --------
63
  conditionalPanel(condition="input.tabs=='genes_item'",align="center",
64
65
                   fluidRow(
                     column(1),
66
67
                     column(10, h4(align="center", "Control Panel"),
                            div(actionLink("help2", "", icon = icon("far fa-question-circle")), align="center"),
68
                            verbatimTextOutput(outputId = "no_file2"), 
69
70
                            conditionalPanel(condition= "output.fileUploaded",align="center",
                                             uiOutput("fchoice4"), br(),
71
72
                                             uiOutput("group"), br(),
                                             radioButtons("gographtype", label="Choose a graph type :", choices=c("Dotplot"="dplot", "Barplot"="bplot", "Emapplot" = "eplot")), br(),
73
                                             radioButtons("ontology", label="Choose an ontology :", choices=c("Biological Process"="BP", "Molecular Function"="MF", "Cellular Component" = "CC")), br(),
74
                                             br(), actionButton("gogo", icon = icon("far fa-arrow-alt-circle-right"), label="Do Gene Ontology")
75
76
77
                            )
                     )
                   )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
78
  ),
79
  # About Panel --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
80
81
82
  conditionalPanel(condition="input.tabs=='about_item'",
                   fluidRow(
                     column(1),
83
                     column(10, tags$img(src='logo.png', height='300', width='175')
Bagueneau Mathias's avatar
Bagueneau Mathias committed
84
85
                     )
                   )
86
  ),
87
  # Compare Panel --------
88
  conditionalPanel(condition="input.tabs=='compare_item'", align="center",
89
90
91
                   fluidRow(
                     column(1),
                     column(10, h4(align="center", "Control Panel"),
92
93
                            div(actionLink("help3", "", icon = icon("far fa-question-circle")), align="center"),
                            verbatimTextOutput(outputId = "no_file3"),
94
                            conditionalPanel(condition= "output.fileUploaded",align="center",
95
96
                                             radioButtons(inputId="choice_compare", label= "Compare :", c("Factors" = "f_compare", "Features" = "features_compare"), selected = "f_compare"),
                                             conditionalPanel(condition = "input.choice_compare == 'features_compare'",
97
98
99
100
101
                                                              uiOutput("featurechoice2"),
                                                              conditionalPanel(condition ="input.featuresel2 == 'g2'",
                                                                               selectizeInput(inputId="genes2", label="Choose a gene :", choices ="")),
                                                              conditionalPanel(condition ="input.featuresel2 == 'd2'",
                                                                               uiOutput("nchoice2"))),
102
103
                                             radioButtons(inputId="graph_compare", label= "Choose the graph mode :", c("t-SNE" = "tsne", "UMAP" = "umap")),
                                             sliderInput(inputId="ptsize_compare", label="Point size :", min=0.1, max=2, step=0.1, value = 0.6, ticks = FALSE),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
104
                                             conditionalPanel(condition = "input.choice_compare == 'f_compare'",
105
                                                              checkboxInput(inputId="show_clusters_compare", label="Clusters information", value=FALSE)
106
107
                                             ),
                                             radioButtons("ontology2", label="Choose an ontology :", choices=c("Biological Process"="BP", "Molecular Function"="MF", "Cellular Component" = "CC"))
108
                            )
109
110
111
                     )
                   )
  ),
112
113
114
115
116
117
118
119
120
121
122
123
  # HeatMap Panel --------
  conditionalPanel(condition="input.tabs=='heatmap_item'", align="center",
                   fluidRow(
                     column(1),
                     column(10, h4(align="center", "Control Panel"),
                            div(actionLink("help4", "", icon = icon("far fa-question-circle")), align="center"),
                            verbatimTextOutput(outputId = "no_file4"),
                            conditionalPanel(condition= "output.fileUploaded",align="center",
                                             uiOutput("fchoice3"), br(),
                                             uiOutput("heat_numb"), br(),
                                             actionButton("goheatmap", icon = icon("far fa-arrow-alt-circle-right"), label="Do HeatMap")
                            )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
124
                     )
125
126
127
                   )
  ),
  # Visu Panel --------
128
129
130
131
132
  conditionalPanel(condition="input.tabs=='visu_item'",
                   fluidRow(
                     column(1),
                     column(10,
                            h4(align="center", "Control Panel"), 
133
                            div(actionLink("help1", "", icon = icon("far fa-question-circle")), align="center"),
134
                            fileInput(inputId="file1", label="Upload your *.rds file :", accept = ".rds", placeholder=""),
135
                            uiOutput("selectfile"),
136
                            conditionalPanel(condition= "output.fileUploaded", align="center",
137
                                             radioButtons(inputId="graph", label= "Choose the graph mode :", c("t-SNE" = "tsne", "UMAP" = "umap")),
138
139
                                             checkboxInput(inputId="show_clusters", label="Clusters information", value=FALSE),
                                             # checkboxInput(inputId="show_gene", label="Gene information", value=FALSE),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
140
                                             sliderInput(inputId="ptsize", label="Point size :", min=0.1, max=2, step=0.1, value = 0.6, ticks = FALSE)
141
142
143
144
145
                            )
                     )
                   )
  )
)
146

147
## BODY --------
148
149
150
151
body <- dashboardBody(
  tabItems(
    
    # Visualize Item --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
152
    tabItem(tabName="visu_item", align="center", 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
153
            conditionalPanel(condition="output.fileUploaded", 
154
155
156
157
158
159
160
161
162
163
                             br(),
                             htmlOutput(outputId = "information"),
                             br(),
                             uiOutput(outputId = "clusters_infos"),
                             verbatimTextOutput(outputId = "select_infos"),  
                             br(),
                             fluidRow(column(align="center", width = 6, plotlyOutput("plot_factors", width="575", height="500"), uiOutput("fchoice"),downloadButton("dlleftplot", label="")),
                                      column(align="center", width = 6, plotlyOutput("plot_numerics", width="500", height="500"),uiOutput("featurechoice"), uiOutput("nchoice"), 
                                             conditionalPanel(condition ="input.featuresel == 'g'", selectizeInput(inputId="genes", label="Choose a gene :", choices ="")),downloadButton("dlrightplot", label=""))#  br(), verbatimTextOutput(outputId="genes_analyse"))
                             ), 
164
165
166
167
168
                             hr(),
                             br(),
                             dataTableOutput("markers_table"),
                             uiOutput(align="left","dlmarkbutton_visu")
                             
169
170
            )         
    ),
171
    
Bagueneau Mathias's avatar
Bagueneau Mathias committed
172
173
174
175
    # HeatMap Item --------
    tabItem(tabName="heatmap_item", align="center",
            conditionalPanel(condition= "output.fileUploaded",
                             br(), br(),
176
                             plotOutput("heatmap", height = 850),
177
178
                             br(), 
                             uiOutput(align="left","dlheat")
Bagueneau Mathias's avatar
Bagueneau Mathias committed
179
180
181
                             
            )
    ),
182
    # Genes Item --------
183
    tabItem(tabName="genes_item", align="left",
184
185
            conditionalPanel(condition= "output.fileUploaded",
                             br(), br(),
186
                             fluidRow(column(align="center", width = 6, plotOutput("goplot", height = 600),uiOutput(align="left","dlgenegraph")),
187
                                      column(align="center", width = 6, dataTableOutput("dtgenes"),uiOutput(align="left","dlgenedt"))),
188
189
190
191
                             br(), hr(),
                             br(),
                             dataTableOutput("dtonto"),
                             uiOutput(align="left","dlontodt")
192
            )
193
    ),
194
    
195
    # Compare Item --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
196
    tabItem(tabName="compare_item", align="center", 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
197
            br(),
198
            uiOutput(outputId="compare_helptext"),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
199
200
            verbatimTextOutput(outputId = "select_infos_compare"),  
            uiOutput(outputId = "clusters_infos_compare"),
201
            br(),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
202
            conditionalPanel(condition="output.fileUploaded",
203
                             fluidRow(column(align="center", width = 2, plotOutput(outputId="miniplot_compare", width="225px", height="225px"), br(), plotOutput(outputId="miniplot_compare2", width="225px", height="225px"), uiOutput("fchoice2"), div(actionLink("add", "", icon = icon("far fa-plus-square")), align="center"), uiOutput("addf")),
204
205
                                      column(align="center", width = 5, plotlyOutput("plot1_compare", width="450px", height="450px"), br(), uiOutput("plot1_library"), br(), uiOutput("addg1"), br(), downloadButton("dl_compare1", label=""), downloadButton("dl_comparebarcodes1", label="Export barcodes")),
                                      column(align="center", width = 5, plotlyOutput("plot2_compare", width="450px", height="450px"), br(), uiOutput("plot2_library"), br(), uiOutput("addg2"), br(), downloadButton("dl_compare2", label=""), downloadButton("dl_comparebarcodes2", label="Export barcodes"))
206
                             ),
207
                             hr(),
208
209
                             br(), 
                             uiOutput(align="left","markbutton"), uiOutput(align="left","dlmarkbutton_compare"), br(), 
210
                             dataTableOutput("markers_compare"),
211
                             hr(),
212
                             br(),
213
214
215
216
                             uiOutput(align="left","ontobutton"),
                             fluidRow(column(align="center",width=6, column(align="center", width=2, uiOutput("topgenes1"),br(), uiOutput(align="center","dlontobutton_compare1") ) , column(align="center", width=10, br(), dataTableOutput("onto_compare1"))),
                                      column(align="center",width=6, column(align="center", width=10, br(), dataTableOutput("onto_compare2")), column(align="align", width=2, uiOutput("topgenes2"),br(), uiOutput(align="align","dlontobutton_compare2") )))
                             )
217
    ),
218
    # Pipeline Item --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
219
    tabItem(tabName="pipeline_item", align="center", 
220
            br(),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
221
222
223
            helpText("Here you can find the pipeline used."),
            br(),
            img(src = "pipe.png", height = 700, width = 400)
224
    ),
225
    # About Item --------
226
    tabItem(tabName="about_item", align="center", h3(strong("Shiny SChnurR")), br(), br(), br(),
227
228
229
230
231
232
            strong("Centre de Recherche en Cancérologie et Immunologie Nantes-Angers"), br(),
            p("UMR1232, CNRS ERL6001"), 
            p("Equipe 11 'Oncogénomique intégrative de la genèse et de la progression du Myélome Multiple'"), 
            p("IRS-UN"), 
            p("8 Quai Moncousu"), 
            p("44007 Nantes"), br(),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
233
            img(src = "crcina.png", height = 180, width = 400, align="center"),
234
            br(), hr(), br(),  p(em("Development Team : Jean-Baptiste ALBERGE, Jonathan CRUARD, Mathias BAGUENEAU"), br(), em("Beta-test : Benjamin DELAUNE")),
Bagueneau Mathias's avatar
Bagueneau Mathias committed
235
            br(), p(strong("Git repository :"),a(href="https://gitlab.univ-nantes.fr/MathBgn/myelome", "Shiny SChnurR"), br(), em("A complete tutorial is available at this adress."))
236
237
    )
  )
238
239
)            

240
## PAGE --------
241
ui <- dashboardPage(
Bagueneau Mathias's avatar
Bagueneau Mathias committed
242
  header,
243
244
  sidebar,
  body
245
246
)

247

248
### ----------------------------- Server logic -----------------------------------------------------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
249

250
server <- function(input, output, session) {
251
  options(shiny.maxRequestSize = 2500*1024^2)
252
  
253
  ## Upload and gestion of files --------
254
255
  filedata <- reactiveValues()
  observe ({
256
257
258
259
    if (!is.null(input$file1)) {
      infile <- input$file1
      if (is.null(infile)) {return (NULL)}
      filedata$data <- readRDS(infile$datapath)
260
      filedata$name <- input$file1$name
261
262
    } else {
      req(input$file)
263
264
      filedata$data <- withProgress(readRDS(paste0("./data/",input$file)), message = "Uploading file...", value=1)
      filedata$name <- input$file
265
    }
266
    genesList <- filedata$data@assays$SCT@data@Dimnames[1]
Bagueneau Mathias's avatar
Bagueneau Mathias committed
267
268
    updateSelectizeInput(session, "genes", choices = genesList[[1]], selected = "IGKC")
    updateSelectizeInput(session, "genes2", choices = genesList[[1]], selected = "IGKC")
269
    return(filedata$data)
270
    return(filedata$name)
271
  })
272
  output$fileUploaded <- reactive({
273
    return(!is.null(filedata$data))
274
275
276
  })
  outputOptions(output, 'fileUploaded', suspendWhenHidden=FALSE)
  
277
278
279
280
281
282
  ## Select File --
  output$selectfile <- renderUI ({
    req(is.null(input$file1))
    selectInput(inputId="file", label="Or choose a file :", choices = c("",list.files(path = "./data",full.names = FALSE,recursive = FALSE)))
  })
  
Bagueneau Mathias's avatar
Bagueneau Mathias committed
283
284
285
286
287
288
289
290
291
292
293
  ## Creating a usefull object for filedata (readable & writable) and assay gestion --------
  wrfile <- reactive ({
    req(filedata$data)
    wrdata <- filedata$data
    if (!is.null(wrdata@assays$SCT)) {
      DefaultAssay(wrdata) <- "SCT"
    } else {
      DefaultAssay(wrdata) <- "RNA"
    }
    return (wrdata)
  })
294
  
295
  
296
  ## Graphs & one table Generations --------
297
  markersData <- reactive ({
298
299
300
    mD <- wrfile()@misc$markers[[input$fsel]]
    # setDT(mD, keep.rownames = TRUE)[]
    return(mD)
301
  })
302
  
303
  factorsplotData <- reactive ({ # Left Graph Visu page
304
305
    scalex <- scale_x_continuous(limits = c(min(wrfile()@reductions[[input$graph]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph]]@cell.embeddings[,1])))
    scaley <- scale_y_continuous(limits = c(min(wrfile()@reductions[[input$graph]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph]]@cell.embeddings[,1])))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
306
    withProgress(DimPlot(object = wrfile(), label=FALSE, pt.size = input$ptsize, reduction=input$graph, group.by = input$fsel), message = "Plot Generation", value=1) + NoLegend() + theme_bw()+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) + NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$fsel)) + scalex + scaley 
307
308
  })
  
309
  numericsplotData <- reactive ({ # Right Graph Visu page
310
311
    scalex <- scale_x_continuous(limits = c(min(wrfile()@reductions[[input$graph]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph]]@cell.embeddings[,1])))
    scaley <- scale_y_continuous(limits = c(min(wrfile()@reductions[[input$graph]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph]]@cell.embeddings[,1])))
312
    if (input$featuresel =="d") {
313
      # withProgress(FeaturePlot(object = wrfile(), cols=c("lightgrey",plasma(ceiling(max(eval(parse(text=paste0("wrfile()@meta.data$",input$nsel))))))), pt.size = input$ptsize, features = input$nsel, reduction = input$graph), message = "Plot Generation", value=1) + theme_bw()+  NoAxes() + ggtitle(paste(filedata$name,"- Feature Plot -", input$nsel)) + scalex + scaley  #+ aes(text=Cells(wrfile())) 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
314
      withProgress(FeaturePlot(object = wrfile(), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize, features = input$nsel, reduction = input$graph), message = "Plot Generation", value=1) + theme_bw() + NoLegend() + theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) +  NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$nsel)) + scalex + scaley 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
315
      
316
    } else if (input$featuresel =="g") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
317
      withProgress(FeaturePlot(object = wrfile(), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize, features = input$genes, reduction = input$graph), message = "Plot Generation", value=1) + theme_bw() + NoLegend() + theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) +   NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$genes)) + scalex + scaley  
Bagueneau Mathias's avatar
Bagueneau Mathias committed
318
      
319
    }
320
321
  })
  
322
  
323
  miniplot_compareData <- reactive ({ # Mini Graph 1 Compare page
324
    withProgress(DimPlot(object = wrfile(), label=TRUE, pt.size = input$ptsize_compare, legend="none", reduction=input$graph_compare, group.by = input$fsel2), message = "Plot Generation", value=1)  + theme_bw() + theme(panel.grid.major=element_blank(),plot.title = element_text(size=12),panel.grid.minor=element_blank(),plot.background=element_blank()) + NoAxes() + NoLegend()
Bagueneau Mathias's avatar
Bagueneau Mathias committed
325
326
  })
  
327
  miniplot_compare2Data <- reactive ({ # Mini Graph 2 Compare page
Bagueneau Mathias's avatar
Bagueneau Mathias committed
328
    if (input$choice_compare == "features_compare") {
329
      if (input$featuresel2 =="d2") {
330
        withProgress(FeaturePlot(object = wrfile(),   cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoLegend() + NoAxes() + theme(panel.grid.major=element_blank(),plot.title = element_text(size=12),panel.grid.minor=element_blank(),plot.background=element_blank())
331
      } else if (input$featuresel2 =="g2") {
332
        withProgress(FeaturePlot(object = wrfile(),   cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoLegend() + NoAxes() + theme(panel.grid.major=element_blank(),plot.title = element_text(size=12),panel.grid.minor=element_blank(),plot.background=element_blank())
333
334
335
336
      }      
    }
  })
  
337
  cells_to_plot1 <- reactive({ # Data for Compare Left Graph
338
339
    if (input$add %% 2 != 0) {
      subset1 <- SubsetData(object = wrfile(), cells=rownames(wrfile()@meta.data)[which(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2))) %in% input$library1_compare)] )
340
      selectedCells <- SubsetData(object = subset1, cells=rownames(subset1@meta.data)[which(eval(parse(text=paste0("subset1@meta.data$",input$add_factor))) %in% input$add_group1)])
341
    } else {
342
      selectedCells <- SubsetData(object = wrfile(), cells=rownames(wrfile()@meta.data)[which(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2))) %in% input$library1_compare)] )                                        
343
    } 
344
345
346
347
348
349
  return(selectedCells)
  })
  
  plot1_compareData <- reactive ({ # Left Graph Compare page
    scalex <- scale_x_continuous(limits = c(min(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1])))
    scaley <- scale_y_continuous(limits = c(min(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1])))
350
    if (input$choice_compare == "f_compare") {
351
      withProgress(DimPlot(object = wrfile(), 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(file_path_sans_ext(filedata$name),"-",input$fsel2)) + scalex + scaley+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank())
352
    } else {
353
      if (input$featuresel2 =="d2") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
354
        withProgress(FeaturePlot(object = wrfile(), cells=rownames(cells_to_plot1()@meta.data), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoLegend() + NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$nsel2))+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) + scalex + scaley 
355
      } else if (input$featuresel2 =="g2") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
356
        withProgress(FeaturePlot(object = wrfile(), cells=rownames(cells_to_plot1()@meta.data), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw()+ NoLegend() + NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$genes2))+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) +scalex + scaley  
357
358
      }      
    }
359
  })
360
  
361
362
363
364
365
366
367
368
369
370
371
  
  cells_to_plot2 <- reactive({ # Data for Compare Right Graph
    if (input$add %% 2 != 0) {
      subset2 <- SubsetData(object = wrfile(), cells=rownames(wrfile()@meta.data)[which(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2))) %in% input$library2_compare)] )
      selectedCells2 <- SubsetData(object = subset2, cells=rownames(subset2@meta.data)[which(eval(parse(text=paste0("subset2@meta.data$",input$add_factor))) %in% input$add_group2)])
    } else {
      selectedCells2 <- SubsetData(object = wrfile(), cells=rownames(wrfile()@meta.data)[which(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2))) %in% input$library2_compare)] )                                        
    }
    return(selectedCells2)
  })
  
372
  plot2_compareData <- reactive ({ # Right Graph Compare page
373
374
375
376
    #  df.colors <- data.frame(class=unique(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2)))), color="viridis"(length(unique(eval(parse(text=paste0("wrfile()@meta.data$",input$fsel2)))))))
    scalex <- scale_x_continuous(limits = c(min(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1])))
    scaley <- scale_y_continuous(limits = c(min(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1]), max(wrfile()@reductions[[input$graph_compare]]@cell.embeddings[,1])))
    
377
    if (input$choice_compare == "f_compare") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
378
      withProgress(DimPlot(object = wrfile(), 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(file_path_sans_ext(filedata$name),"-", input$fsel2))+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) + scalex + scaley
379
      # cols = df.colors[df.colors$class==input$library2_compare, "color"],
380
    } else {
381
      if (input$featuresel2 =="d2") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
382
        withProgress(FeaturePlot(object = wrfile(), cells=rownames(cells_to_plot2()@meta.data), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$nsel2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw() + NoLegend() + NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$nsel2))+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) + scalex + scaley   
383
      } else if (input$featuresel2 =="g2") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
384
        withProgress(FeaturePlot(object = wrfile(), cells=rownames(cells_to_plot2()@meta.data), cols=c("lightgrey",plasma(200)), pt.size = input$ptsize_compare, features = input$genes2, reduction = input$graph_compare), message = "Plot Generation", value=1) + theme_bw() + NoLegend() + NoAxes() + ggtitle(paste(file_path_sans_ext(filedata$name),"-", input$genes2))+ theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank()) + scalex + scaley 
385
      }    
386
387
    }
  })
388
  
389
  ## Graphs & Tables Outputs --------
390
  output$plot_factors <-renderPlotly ({
391
    req(wrfile())
392
    ggplotly(factorsplotData(),tooltip = c("colour","text")) %>% config(displaylogo = F,  modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
393
  })
394
  
395
  output$plot_numerics <-renderPlotly ({
396
    req(wrfile())
Bagueneau Mathias's avatar
Bagueneau Mathias committed
397
    ggplotly(numericsplotData(),tooltip = "none") %>% config(displaylogo = F,  modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
398
  })
399
400
  
  output$markers_table <- renderDataTable ({
401
    req(wrfile())
Bagueneau Mathias's avatar
Bagueneau Mathias committed
402
    req(markersData() != "")
403
    datatable(markersData()[c(7,6,3,4,2,1,5)], rownames = FALSE, filter="top", caption = paste("Table : All significant markers for the factor :", input$fsel ,"| Test used : MAST" ))  %>% formatRound(columns=c(3,4,5), digits=3) %>% formatSignif(columns=c(7,6), digits=3)
404
  })
405
  
406
  output$miniplot_compare <- renderPlot({
407
    req(wrfile())
408
409
    plot(miniplot_compareData())
  })
Bagueneau Mathias's avatar
Bagueneau Mathias committed
410
411
  
  output$miniplot_compare2 <- renderPlot({
412
    req(wrfile())
Bagueneau Mathias's avatar
Bagueneau Mathias committed
413
414
    plot(miniplot_compare2Data())
  })
415
  
416
  output$plot1_compare <- renderPlotly ({
417
    req(wrfile())
Bagueneau Mathias's avatar
Bagueneau Mathias committed
418
    if (input$choice_compare == "features_compare") {
419
      ggplotly(plot1_compareData(),tooltip ="none") %>% config(displaylogo = F, modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
420
    } else {
421
      ggplotly(plot1_compareData(),tooltip = c("colour","x","y")) %>% config(displaylogo = F, modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
422
    }
423
  })
424
425
  
  output$plot2_compare <- renderPlotly ({
426
    req(wrfile())
Bagueneau Mathias's avatar
Bagueneau Mathias committed
427
    if (input$choice_compare == "features_compare") {
428
      ggplotly(plot2_compareData(),tooltip ="none") %>% config(displaylogo = F, modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
429
    } else {
430
      ggplotly(plot2_compareData(),tooltip = c("colour","x","y")) %>% config(displaylogo = F, modeBarButtonsToRemove = c('resetScale2d', 'toggleSpikelines', 'toImage', 'hoverCompareCartesian','hoverClosestCartesian'))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
431
    }
432
  })
433
  
434
  ## Heatmap Generation & Output --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
435
  output$heat_numb <- renderUI ({
436
    sliderInput("top_number", label="Choose the number of top genes :", min=1, max=5, step=1, value=3)
Bagueneau Mathias's avatar
Bagueneau Mathias committed
437
  })
438
  heatmapData <- reactive ({
Bagueneau Mathias's avatar
Bagueneau Mathias committed
439
    req(input$goheatmap)
440
    if (is.null(wrfile()@misc$markers[[input$fsel3]])) { 
441
442
      showModal(modalDialog("The markers may have not been calculated for this factor yet.", title=strong("Warning !"), easyClose=TRUE, footer = NULL )) 
    } else {
443
444
445
      topgenes <- wrfile()@misc$markers[[input$fsel3]] %>% group_by(cluster) %>% top_n(n = input$top_number, wt = avg_logFC)
      datascale <- withProgress(ScaleData(object = wrfile(), features = topgenes$gene), message = "Scaling data...", value=1)
      withProgress(DoHeatmap(object = datascale, features = topgenes$gene, group.by=input$fsel3), message = "HeatMap Generation", value=1) + NoLegend() + ggtitle(paste(file_path_sans_ext(filedata$name),"- HeatMap -", input$fsel3,"- top",input$top_number,"genes")) + theme(plot.title = element_text(size=20))
446
    }
447
448
  }) 
  output$heatmap <-renderPlot ({
449
    req(wrfile())
450
    heatmapData()
451
  })
452
  
453
  ## Genes Page --------
454
455
456
457
458
  observeEvent(input$gogo, {
    if (is.null(input$group_genepage)) {
      showModal(modalDialog("You must choose at least one group to do the Gene Ontology.", title=strong("Warning !"), easyClose=TRUE, footer = NULL ))
    }
  })
459
460
461
462
463
464
465
  egot <- reactive({
    genes <- wrfile()@misc$markers[[input$fsel4]]$cluster == input$group_genepage
    genes <- wrfile()@misc$markers[[input$fsel4]]$gene[genes]
    genes <- bitr(genes, fromType = "SYMBOL",toType = "ENTREZID",OrgDb = org.Hs.eg.db,drop = TRUE)
    ego <- withProgress(enrichGO(gene = genes$ENTREZID, OrgDb = "org.Hs.eg.db", keyType= "ENTREZID", ont = input$ontology, readable = TRUE), value = 1, message = "Ontology in progress...")
    return(ego)
  })
466
  
467
  goplotData <- reactive ({ # Ontology Graph
468
    req(input$gogo)
469
470
471
    req(!is.null(input$group_genepage))
    if (is.null(wrfile()@misc$markers[[input$fsel4]])) { 
      showModal(modalDialog("The markers may have not been calculated for this factor yet.", title=strong("Warning !"), easyClose=TRUE, footer = NULL )) 
472
    } else {
473
      if (input$gographtype == "dplot") {
474
        dotplot(egot()) + ggtitle(paste(file_path_sans_ext(filedata$name),"-",input$ontology,"-",input$fsel4)) + theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank())
475
      } else if (input$gographtype == "bplot") {
476
        barplot(egot(), drop=TRUE) + ggtitle(paste(file_path_sans_ext(filedata$name),"-",input$ontology,"-",input$fsel4)) + theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank())
477
      } else {
478
        emapplot(egot()) + ggtitle(paste(file_path_sans_ext(filedata$name),"-",input$ontology,"-",input$fsel4)) + theme(panel.grid.major=element_blank(),plot.title = element_text(size=18),panel.grid.minor=element_blank(),plot.background=element_blank())
479
      }
480
    }
481
  })
482

483
  output$goplot <-renderPlot ({
484
    req(wrfile())
485
486
487
    goplotData()
  })
  
488
  dtgoData <- reactive ({ # Genes Table
489
    filegene <- wrfile()
490
    req(input$gogo)
491
492
    Idents(filegene) <- as.factor(paste0(eval(parse(text=paste0("filegene@meta.data$",input$fsel4)))))
    dtgenes <- data.table(filegene@misc$markers[[input$fsel4]]$gene[which(eval(parse(text=paste0("filegene@misc$markers$",input$fsel4,"$cluster"))) %in% input$group_genepage)])
493
494
495
    setDT(dtgenes)[]
    names(dtgenes)[1] <- "Gene"
    return(dtgenes)
496
497
498
499
  })
  output$dtgenes <-renderDataTable ({
    req(wrfile())
    req(!is.null(input$group_genepage))
500
    datatable(dtgoData(), filter="top", caption = paste("Table : Markers for the following group(s) : ",paste(sapply(input$group_genepage, paste, collapse=""), collapse=" + "), "and this factor : ", input$fsel4))
501
502
  })

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
  
  dtontoData <- reactive ({ # Ontology Table
    filegene <- wrfile()
    req(input$gogo)
    Idents(filegene) <- as.factor(paste0(eval(parse(text=paste0("filegene@meta.data$",input$fsel4)))))
    dtonto <- data.table(egot()$Description, egot()$GeneRatio, egot()$pvalue, egot()$p.adjust)[which(egot()$Count > 3)]
    colnames(dtonto) <- c("Description","Gene Ratio","P-value","FDR")
    return(dtonto)
  })
  output$dtonto <-renderDataTable ({
    req(wrfile())
    req(!is.null(input$group_genepage))
    datatable(dtontoData(), filter="top", caption = paste("Table : Gene Ontology (",input$ontology,") for the following group(s) : ",paste(sapply(input$group_genepage, paste, collapse=""), collapse=" + "), "and this factor : ", input$fsel4,"| Only takes groups with a ratio > 3/Total, p-value cutoff : 0.05")) %>% formatSignif(columns=c(3,4), digits=3)
  })
  
518
  ## Downloads functions --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
519
  output$dlmarkbutton_visu <- renderUI ({ # visualization Page
Bagueneau Mathias's avatar
Bagueneau Mathias committed
520
521
522
    req(markersData() != "")
    downloadButton("dlmarkers", label="")
  })
Bagueneau Mathias's avatar
Bagueneau Mathias committed
523
  output$dlmarkers <- downloadHandler( # visualization Page
524
    filename = function() {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
525
      paste0(file_path_sans_ext(filedata$name),"_allmarkers_",input$fchoice,".csv")
526
527
528
529
530
    },
    content = function(file) {
      write.csv(markersData(), file)
    }
  )
531
  
Bagueneau Mathias's avatar
Bagueneau Mathias committed
532
  output$dlleftplot <- downloadHandler( # visualization Page
533
    filename = function() {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
534
      paste0(file_path_sans_ext(filedata$name),"_plot_",input$fsel,"_",input$graph,".svg")
535
536
537
    },
    content = function(file) {
      svg(file)
538
      print(factorsplotData())
539
540
541
      dev.off()
    }
  )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
542
  
Bagueneau Mathias's avatar
Bagueneau Mathias committed
543
  output$dlrightplot <- downloadHandler( # visualization Page
544
    filename = function() {
545
546
547
548
549
      if (input$featuresel =="g") {
        paste0(file_path_sans_ext(filedata$name),"_",input$genes,"_plot_",input$graph,".svg")
      } else {
        paste0(file_path_sans_ext(filedata$name),"_",input$nsel,"_plot_",input$graph,".svg")
      }
550
551
552
    },
    content = function(file) {
      svg(file)
553
      print(numericsplotData())
554
555
556
      dev.off()
    }
  )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
557
  
558
  
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
  output$dlgenegraph <- renderUI ({ # Genes Page
    req(goplotData() !="")
    downloadButton("dl_gene", label="")
  })
  output$dl_gene <- downloadHandler(
    filename = function() {
      if (input$gographtype == "dplot") {
        paste0(file_path_sans_ext(filedata$name),"_",input$ontology,"_dotplot_",input$fsel4,".png")
      } else if (input$gographtype == "bplot") {
        paste0(file_path_sans_ext(filedata$name),"_",input$ontology,"_barplot_",input$fsel4,".png")
      } else {
        paste0(file_path_sans_ext(filedata$name),"_",input$ontology,"_emapplot_",input$fsel4,".png")
      }
    },
    content = function(file) {
      png(file, width = 800, height = 600)
      print(goplotData())
      dev.off()
    }
  )
  
  output$dlgenedt <- renderUI ({ # Genes Page
    req(dtgoData() !="")
    downloadButton("dl_godt", label="")
  })
  output$dl_godt <- downloadHandler(
    filename = function() {
586
        paste0(file_path_sans_ext(filedata$name),"_genes_datatable_",input$fsel4,".csv")
587
588
589
590
591
592
    },
    content = function(file) {
      write.csv(dtgoData(), file)
    }
  )
  
593
594
595
596
597
598
599

  output$dlontodt <- renderUI ({ # Genes Page
    req(dtgoData() !="")
    downloadButton("dl_ontodt", label="")
  })
  output$dl_ontodt <- downloadHandler(
    filename = function() {
600
      paste0(file_path_sans_ext(filedata$name),"_onto_",input$ontology,"_datatable_",input$fsel4,".csv")
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
    },
    content = function(file) {
      write.csv(dtontoData(), file)
    }
  )
  
  
  
  output$dlheat <- renderUI ({ # HeatMap Page
    req(heatmapData() !="")
    downloadButton("dl_heatmap", label="")
  })
  output$dl_heatmap <- downloadHandler(
    filename = function() {
      paste0(file_path_sans_ext(filedata$name),"_heatmap_",input$fsel3,"_top",input$top_number,"genes",".png")
    },
    content = function(file) {
      png(file, width = 800, height = 600)
      print(heatmapData())
      dev.off()
    }
  )
  
  
625
  
626
  output$dl_compare1 <- downloadHandler( # Compare Page
627
    filename = function() {
628
      if (input$choice_compare == "f_compare") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
629
        paste0(file_path_sans_ext(filedata$name),"_plot_",input$fsel2,"_",input$graph_compare,".svg")
630
      } else {
631
632
633
634
635
        if (input$featuresel2 =="g2") {
          paste0(file_path_sans_ext(filedata$name),"_",input$genes2,"_plot_",input$graph_compare,".svg")  
        } else {
          paste0(file_path_sans_ext(filedata$name),"_",input$nsel2,"_plot_",input$graph_compare,".svg")  
          }
636
      }
637
638
639
640
    },
    content = function(file) {
      svg(file)
      print(plot1_compareData())
641
642
      dev.off()        
    }                
643
  )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
644
  
645
  output$dl_compare2 <- downloadHandler( # Compare Page
646
    filename = function() {
647
      if (input$choice_compare == "f_compare") {
Bagueneau Mathias's avatar
Bagueneau Mathias committed
648
        paste0(file_path_sans_ext(filedata$name),"_plot_",input$fsel2,"_",input$graph_compare,".svg")
649
      } else {
650
651
652
653
654
        if (input$featuresel2 =="g2") {
          paste0(file_path_sans_ext(filedata$name),"_",input$genes2,"_plot_",input$graph_compare,".svg")  
        } else {
          paste0(file_path_sans_ext(filedata$name),"_",input$nsel2,"_plot_",input$graph_compare,".svg")  
        }
655
      }
656
657
658
659
660
661
662
    },
    content = function(file) {
      svg(file)
      print(plot2_compareData())
      dev.off()
    }
  )
663
  
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
  output$dl_comparebarcodes1 <- downloadHandler( # Compare Page
    filename = function() {
      paste0(file_path_sans_ext(filedata$name),"_selectedbarcodes.csv")
    },
    content = function(file) {
      write.csv(cbar1Data(), file)
    }
  )
  
  output$dl_comparebarcodes2 <- downloadHandler( # Compare Page
    filename = function() {
      paste0(file_path_sans_ext(filedata$name),"_selectedbarcodes.csv")
    },
    content = function(file) {
      write.csv(cbar2Data(), file)
    }
  )

682
683
  ## Information Visualize text --------
  output$information  <- renderUI({
684
    req(wrfile())
685
    az <- paste(strong("Filename :"), filedata$name)
686
687
688
689
    er <- paste(strong("Genes number :"), length(wrfile()@assays$SCT@data@Dimnames[[1]]), " | ",strong("Cells number :"), length(wrfile()@assays$SCT@data@Dimnames[[2]]), " | ",strong("Median genes/cell :"), median(wrfile()@meta.data$nFeature_SCT))
    ty <- paste(strong("Assay used :"), wrfile()@active.assay)
    HTML(paste(az,er,ty, sep='</br>'))
  })
690
  
691
692
693
  
  ## No file texts --------
  output$no_file2  <- renderText({
Bagueneau Mathias's avatar
Bagueneau Mathias committed
694
695
    req(input$file =="")
    req(is.null(input$file1))
696
697
    print("Please upload or \n choose a file")
  }) 
698
  output$no_file3  <- renderText({
Bagueneau Mathias's avatar
Bagueneau Mathias committed
699
700
    req(input$file =="")
    req(is.null(input$file1))
701
    print("Please upload or \n choose a file")
702
  })
Bagueneau Mathias's avatar
Bagueneau Mathias committed
703
  output$no_file4  <- renderText({
Bagueneau Mathias's avatar
Bagueneau Mathias committed
704
705
    req(input$file =="")
    req(is.null(input$file1))
706
    print("Please upload or \n choose a file")
Bagueneau Mathias's avatar
Bagueneau Mathias committed
707
  })
708
  
Bagueneau Mathias's avatar
Bagueneau Mathias committed
709
  
710
  ## Clusters + selection information text in visualization page --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
711
  output$clusters_infos <- renderTable({ 
712
    req(input$fsel != "")
713
    req(input$show_clusters == "TRUE")
714
    clDATA <- data.table("Cluster" = levels(as.factor(wrfile()@meta.data[[input$fsel]])), "Cells_nb" = as.vector(summary(as.factor(wrfile()@meta.data[[input$fsel]]))), "Percentage" =formatC(((as.vector(summary(as.factor(wrfile()@meta.data[[input$fsel]])))/length(as.factor(wrfile()@meta.data[[input$fsel]])))*100),digits=2, format ="f" ))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
715
716
    t(head( clDATA, n=999 ))}, align="c", striped = TRUE, hover = TRUE, spacing = 'xs',   width = '100%',  colnames = FALSE, rownames=TRUE
  )
717
  
718
  output$select_infos <- renderText({
719
720
    req(wrfile())
    d <- paste0("Your selection : Cells nb : ", nrow(event_data("plotly_selected")), " | % : ", formatC(((nrow(event_data("plotly_selected"))/length(wrfile()@meta.data[[input$fsel]]))*100),digits=2, format ="f" )  ) 
Bagueneau Mathias's avatar
Bagueneau Mathias committed
721
    if (is.null(nrow(event_data("plotly_selected")))) "Please select some cells" else d
722
  })
Bagueneau Mathias's avatar
Bagueneau Mathias committed
723
  
724
  ## Clusters + selection information text in compare page --------
Bagueneau Mathias's avatar
Bagueneau Mathias committed
725
  output$clusters_infos_compare  <- renderTable ({
726
    req(input$fsel2 != "")
727
    req(input$show_clusters_compare == "TRUE")
728
    clDATA2 <- data.table("Cluster" = levels(as.factor(wrfile()@meta.data[[input$fsel2]])), "Cells_nb" = as.vector(summary(as.factor(wrfile()@meta.data[[input$fsel2]]))), "Percentage" =formatC(((as.vector(summary(as.factor(wrfile()@meta.data[[input$fsel2]])))/length(as.factor(wrfile()@meta.data[[input$fsel2]])))*100),digits=2, format ="f" ))
Bagueneau Mathias's avatar
Bagueneau Mathias committed
729
730
    t(head( clDATA2, n=999 ))}, align="c",  striped = TRUE, hover = TRUE, spacing = 'xs',   width = '100%',  colnames = FALSE, rownames=TRUE
  ) 
731
  output$select_infos_compare <- renderText({
732
733
    req(wrfile())
    d <- paste0("Your selection : Cells nb : ", nrow(event_data("plotly_selected")), " | % : ", formatC(((nrow(event_data("plotly_selected"))/length(wrfile()@meta.data[[input$fsel2]]))*100),digits=2, format ="f" )  )
Bagueneau Mathias's avatar
Bagueneau Mathias committed
734
    if (is.null(nrow(event_data("plotly_selected")))) "Please select some cells" else d