Skip to content

Commit e038752

Browse files
committed
first working version of full scmap (cluster+cell)
1 parent 43c2e3e commit e038752

36 files changed

+119
-72
lines changed

server.R

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

ui.R

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dashboardPage(
2525
menuItem("About", tabName = "about", icon = icon("bank")),
2626
menuItem("Datasets", tabName = "datasets", icon = icon("cloud-upload")),
2727
menuItem("Features", tabName = "features", icon = icon("gears")),
28-
menuItem("scmap-cluster", tabName = "results_cluster", icon = icon("area-chart"))
28+
menuItem("Results", tabName = "results", icon = icon("area-chart"))
2929
)
3030
)
3131
),
@@ -40,7 +40,7 @@ dashboardPage(
4040
sidebarMenu(
4141
menuItem("About", tabName = "about", icon = icon("bank")),
4242
menuItem("Datasets", tabName = "datasets", icon = icon("cloud-upload")),
43-
menuItem("scmap-cluster", tabName = "results_cluster", icon = icon("area-chart"))
43+
menuItem("Results", tabName = "results", icon = icon("area-chart"))
4444
)
4545
)
4646
)
@@ -155,6 +155,14 @@ dashboardPage(
155155
solidHeader = TRUE
156156
)
157157
),
158+
box(width = 12,
159+
HTML("<p class='lead'>Would you like to run scmap-cell? (may take some time)</p>"),
160+
radioButtons("run_scmap_cell", NULL,
161+
c("No" = "No",
162+
"Yes" = "Yes"),
163+
selected = "No"),
164+
solidHeader = TRUE
165+
),
158166
solidHeader = TRUE,
159167
status = "primary"
160168
)
@@ -206,39 +214,20 @@ dashboardPage(
206214
)
207215
)
208216
),
209-
tabItem(tabName = "results_cluster",
217+
tabItem(tabName = "results",
210218
fluidRow(
211-
conditionalPanel("input.data_type == 'own'",
212-
box(width = 12,
213-
title = "Cell Projection",
214-
HTML("<p><b>scmap</b> projects all cells
215-
of the Projection dataset to the
216-
reference calculated from the Reference dataset.
217-
The Reference is computed by calculating
218-
the median expression in each of 500
219-
selected features across all
220-
cells in each cell type."),
221-
solidHeader = TRUE,
222-
status = "primary"
223-
)
224-
),
225-
conditionalPanel("input.data_type == 'existing'",
226-
box(width = 12,
227-
title = "Cell Projection",
228-
HTML("<p><b>scmap</b> projects all cells
229-
of the Projection dataset to the precomputed
230-
References. The references were computed by
231-
selecting 500 most informative features of each
232-
Reference dataset and calculating
233-
the median expression in each of 500 features across all
234-
cells in each cell type."),
235-
solidHeader = TRUE,
236-
status = "primary"
237-
)
238-
)
219+
box(width = 12,
220+
title = "Cell Projection",
221+
HTML("<p><b>scmap</b> projects all cells
222+
of the Projection dataset to the
223+
either cell clusters (<b>scmap-cluster</b>) or
224+
each individual cell (<b>scmap-cell</b>) of the Reference dataset."),
225+
solidHeader = TRUE,
226+
status = "primary"
227+
)
239228
),
240-
conditionalPanel(condition="!$('html').hasClass('shiny-busy') & output.scmap_cluster_worked",
241-
uiOutput("results_cluster")
229+
conditionalPanel(condition="!$('html').hasClass('shiny-busy') & output.scmap_cluster_worked & output.scmap_cell_worked",
230+
uiOutput("results")
242231
),
243232
conditionalPanel(condition="$('html').hasClass('shiny-busy')",
244233
fluidRow(
@@ -252,11 +241,11 @@ dashboardPage(
252241
offset = 2)
253242
)
254243
),
255-
conditionalPanel("!output.scmap_cluster_worked",
244+
conditionalPanel("!output.scmap_cluster_worked || !output.scmap_cell_worked",
256245
box(width = 12,
257246
HTML("
258247
<div class='alert alert-danger'>
259-
<p class = 'lead'>scmap-cluster did not work! Most probably
248+
<p class = 'lead'>scmap did not work! Most probably
260249
Reference and Projection come from different organisms,
261250
please check your inputs!</p>
262251
</div>"),
893 KB
Binary file not shown.

www/scmap-cell/human/li.rds

107 KB
Binary file not shown.

www/scmap-cell/human/muraro.rds

289 KB
Binary file not shown.

www/scmap-cell/human/pollen.rds

74.2 KB
Binary file not shown.
297 KB
Binary file not shown.

www/scmap-cell/human/xin.rds

224 KB
Binary file not shown.

www/scmap-cell/human/yan.rds

36.5 KB
Binary file not shown.
241 KB
Binary file not shown.

0 commit comments

Comments
 (0)