@@ -79,16 +79,16 @@ server <- function(input, output) {
7979 return (res )
8080 }
8181
82- getIndex <- function () {
82+ scmapCluster_index <- function () {
8383 if (input $ data_type == " existing" ) {
8484 # load indexes
85- files <- list.files(paste0(" www/refs /" , input $ organism ), pattern = " .csv" )
85+ files <- list.files(paste0(" www/scmap-cluster /" , input $ organism ), pattern = " .csv" )
8686 index <- list ()
8787 for (f in files ) {
8888 name <- strsplit(f , " \\ ." )[[1 ]][1 ]
8989 tmp <- read.csv(
9090 paste0(
91- " www/refs /" ,
91+ " www/scmap-cluster /" ,
9292 input $ organism , " /" , f
9393 )
9494 )
@@ -114,29 +114,74 @@ server <- function(input, output) {
114114 return (index )
115115 }
116116
117+ scmapCell_index <- function () {
118+ if (input $ data_type == " existing" ) {
119+ # load indexes
120+ files <- list.files(paste0(" www/scmap-cell/" , input $ organism ), pattern = " .rds" )
121+ index <- list ()
122+ for (f in files ) {
123+ name <- strsplit(f , " \\ ." )[[1 ]][1 ]
124+ tmp <- readRDS(
125+ paste0(
126+ " www/scmap-cell/" ,
127+ input $ organism , " /" , f
128+ )
129+ )
130+ index [[name ]] <- tmp
131+ }
132+ } else {
133+ # compute the index
134+ dataset <- values $ reference_data()
135+ if (values $ features ) {
136+ rowData(dataset )$ scmap_features <- values $ scmap_features
137+ rowData(dataset )$ scmap_scores <- values $ scmap_scores
138+ } else {
139+ dataset <- selectFeatures(dataset )
140+ }
141+ index <- indexCell(
142+ dataset
143+ )
144+ index <- list (metadata(index )$ scmap_cell_index )
145+ }
146+ return (index )
147+ }
148+
117149 scmap <- function () {
118150
119- # compute index
120- index <- getIndex()
121-
122151 # run scmap-cluster
152+ index_cluster <- scmapCluster_index()
123153 scmapCluster_results <- scmapCluster(
124154 values $ projection_data(),
125- index_list = index
155+ index_list = index_cluster
126156 )
127157
128158 if (! " SingleCellExperiment" %in% is(scmapCluster_results )) {
129159 # summarise results of scmap-cluster
130- values $ scmap_cluster_siml <- scmapCluster_results $ scmap_cluster_siml
131- values $ scmap_cluster_labs <- scmapCluster_results $ scmap_cluster_labs
132- values $ scmap_cluster_comb <- scmapCluster_results $ combined_labs
160+ values $ scmap_cluster_res <- scmapCluster_results
133161 values $ scmap_cluster_all <-
134- scmapClusterResults2table(index , scmapCluster_results $ scmap_cluster_labs )
162+ scmapClusterResults2table(index_cluster , scmapCluster_results $ scmap_cluster_labs )
135163 values $ scmap_cluster_combined <-
136- scmapClusterResults2table(index , data.frame (scmapCluster_results $ combined_labs ))
164+ scmapClusterResults2table(index_cluster , data.frame (scmapCluster_results $ combined_labs ))
137165 } else {
138166 values $ scmap_cluster_worked <- FALSE
139167 }
168+
169+ if (input $ run_scmap_cell == " Yes" ) {
170+ # run scmap-cell
171+ index_cell <- scmapCell_index()
172+ scmapCell_results <- scmapCell(
173+ values $ projection_data(),
174+ index_list = index_cell
175+ )
176+ if (" list" %in% is(scmapCell_results )) {
177+ # summarise results of scmap-cell
178+ values $ scmap_cell_all <- scmapCell_results
179+ } else {
180+ print(class(scmapCell_results ))
181+ values $ scmap_cell_worked <- FALSE
182+ }
183+ }
184+
140185 return ()
141186 }
142187
@@ -205,35 +250,50 @@ server <- function(input, output) {
205250 )
206251 })
207252
208- output $ results_cluster <- renderUI({
253+ output $ results <- renderUI({
209254 switch (input $ data_type ,
210255 " own" = list (
256+ fluidRow(
211257 box(width = 12 ,
212- title = " Results " ,
258+ title = " scmap-cluster " ,
213259 DT :: dataTableOutput(' results_table' ),
214- downloadButton(" scmap_cluster_labs" , ' Download All Assignments' ),
215- downloadButton(" scmap_cluster_siml" , ' Download All Similarities' ),
260+ downloadButton(" scmap_cluster_all" , ' Download' ),
216261 solidHeader = TRUE ,
217262 status = " success"
263+ ),
264+ conditionalPanel(" input.run_scmap_cell == 'Yes'" ,
265+ box(width = 12 ,
266+ title = " scmap-cell" ,
267+ downloadButton(" scmap_cell_all" , ' Download' ),
268+ solidHeader = TRUE ,
269+ status = " success"
270+ )
218271 )
272+ )
219273 ),
220274 " existing" = list (
221275 fluidRow(
222276 box(width = 12 ,
223- title = " Individual Results " ,
277+ title = " scmap-cluster " ,
224278 DT :: dataTableOutput(' results_table' ),
225- downloadButton(" scmap_cluster_labs" , ' Download All Assignments' ),
226- downloadButton(" scmap_cluster_siml" , ' Download All Similarities' ),
279+ downloadButton(" scmap_cluster_all" , ' Download' ),
227280 solidHeader = TRUE ,
228281 status = " success"
229282 ),
230283 box(width = 12 ,
231- title = " Consensus Results " ,
284+ title = " scmap-cluster (combined) " ,
232285 DT :: dataTableOutput(' consensus_results_table' ),
233- downloadButton(" consensus_results_assignments" , ' Download Consensus Assignments' ),
234286 solidHeader = TRUE ,
235287 status = " success"
236- )
288+ ),
289+ conditionalPanel(" input.run_scmap_cell == 'Yes'" ,
290+ box(width = 12 ,
291+ title = " scmap-cell" ,
292+ downloadButton(" scmap_cell_all" , ' Download' ),
293+ solidHeader = TRUE ,
294+ status = " success"
295+ )
296+ )
237297 )
238298 )
239299 )
@@ -331,30 +391,21 @@ server <- function(input, output) {
331391 values $ feature_table <- row_data
332392 })
333393
334- output $ scmap_cluster_labs <- downloadHandler(
394+ output $ scmap_cluster_all <- downloadHandler(
335395 filename = function () {
336- paste( ' scmap_results_assignments.csv ' , sep = ' ' )
396+ ' scmap-cluster.rds '
337397 },
338398 content = function (con ) {
339- write.csv (values $ scmap_cluster_labs , con , quote = FALSE )
399+ saveRDS (values $ scmap_cluster_res , con )
340400 }
341401 )
342402
343- output $ scmap_cluster_siml <- downloadHandler(
403+ output $ scmap_cell_all <- downloadHandler(
344404 filename = function () {
345- paste( ' scmap_results_similarities.csv ' , sep = ' ' )
405+ ' scmap-cell.rds '
346406 },
347407 content = function (con ) {
348- write.csv(values $ scmap_cluster_siml , con , quote = FALSE )
349- }
350- )
351-
352- output $ consensus_results_assignments <- downloadHandler(
353- filename = function () {
354- paste(' scmap_results_consensus.csv' , sep = ' ' )
355- },
356- content = function (con ) {
357- write.csv(values $ scmap_cluster_comb , con , quote = FALSE )
408+ saveRDS(values $ scmap_cell_all , con )
358409 }
359410 )
360411
@@ -367,10 +418,12 @@ server <- function(input, output) {
367418 })
368419 output $ reference_data <- reactive({
369420 values $ scmap_cluster_worked <- TRUE
421+ values $ scmap_cell_worked <- TRUE
370422 return (! is.null(values $ reference_data()))
371423 })
372424 output $ projection_data <- reactive({
373425 values $ scmap_cluster_worked <- TRUE
426+ values $ scmap_cell_worked <- TRUE
374427 return (! is.null(values $ projection_data()))
375428 })
376429 output $ reference_feature_symbol <- reactive({
@@ -404,6 +457,10 @@ server <- function(input, output) {
404457 return (values $ scmap_cluster_worked )
405458 })
406459
460+ output $ scmap_cell_worked <- reactive({
461+ return (values $ scmap_cell_worked )
462+ })
463+
407464 # make output variables visible for the client side
408465 outputOptions(output , " projection_file" , suspendWhenHidden = FALSE )
409466 outputOptions(output , " reference_file" , suspendWhenHidden = FALSE )
@@ -414,4 +471,5 @@ server <- function(input, output) {
414471 outputOptions(output , " pdata_cell_types" , suspendWhenHidden = FALSE )
415472 outputOptions(output , " features" , suspendWhenHidden = FALSE )
416473 outputOptions(output , " scmap_cluster_worked" , suspendWhenHidden = FALSE )
474+ outputOptions(output , " scmap_cell_worked" , suspendWhenHidden = FALSE )
417475}
0 commit comments