diff --git a/R/makeShinyFilesDEG.R b/R/makeShinyFilesDEG.R index 806eee4..03b2aae 100644 --- a/R/makeShinyFilesDEG.R +++ b/R/makeShinyFilesDEG.R @@ -121,6 +121,28 @@ makeShinyFilesDEG <- function( ) } + # Validate DEG cluster levels match metadata cluster levels + deg_clusters <- sort(unique(as.character(markergenes$cluster))) + meta_clusters <- sort(unique(as.character(obj@meta.data[[clusters]]))) + if (!all(deg_clusters %in% meta_clusters)) { + missing <- setdiff(deg_clusters, meta_clusters) + stop( + "DEG markers contain cluster(s) not found in metadata column '", clusters, "': ", + paste(missing, collapse = ", "), + "\n DEG clusters: ", paste(deg_clusters, collapse = ", "), + "\n Metadata clusters: ", paste(meta_clusters, collapse = ", ") + ) + } + + # Validate that the clusters column exists in scConf (i.e. it was not filtered out) + if (!clusters %in% scConf$ID && !clusters %in% scConf$UI) { + stop( + "Cluster label '", clusters, "' was not included in the ShinyCell config (sc1conf). ", + "It may have been removed by metadata filtering (rmmeta/unsupported assay pattern). ", + "Please ensure this column is retained in the config." + ) + } + # markergene h5 creation n_rows <- nrow(markergenes) n_cols <- ncol(markergenes) diff --git a/R/writer1.R b/R/writer1.R index eb32a8d..ea86d3d 100644 --- a/R/writer1.R +++ b/R/writer1.R @@ -131,8 +131,8 @@ wrSVmainA1 <- function(prefix) { ' return(list(res,resDef,resLen))\n', ' }})\n', ' observeEvent(gsub("^Assay: ", "", input${prefix}a1ass1), {{\n', - ' updateSelectizeInput(session, "{prefix}a1inp1", choices = getG{prefix}a1inp1()[[1]], \n', - ' server = TRUE, selected = getG{prefix}a1inp1()[[2]], options = list( \n', + ' updateSelectizeInput(session, "{prefix}a1inp1", choices = getG{prefix}a1inp1()[[1]], \n', + ' server = TRUE, selected = getG{prefix}a1inp1()[[1]][1], options = list( \n', ' maxOptions = getG{prefix}a1inp1()[[3]], create = TRUE, \n', ' persist = TRUE, render = I(optCrt))) \n', ' }})\n', diff --git a/R/writer2.R b/R/writer2.R index d721744..178d87d 100644 --- a/R/writer2.R +++ b/R/writer2.R @@ -149,7 +149,9 @@ wrUImainA1 <- function(prefix, ptsiz) { ' selectInput("{prefix}a1ass1", "Data type to colour plot:",\n', ' choices = c("Cell Information", paste0("Assay: ", {prefix}def$assay)), \n', ' selected = "Cell Information"), \n', - ' selectInput("{prefix}a1inp1", "Cell Info / Feature Name:", choices = NULL) %>% \n', + ' selectInput("{prefix}a1inp1", "Cell Info / Feature Name:", \n', + ' choices = {prefix}conf$UI, \n', + ' selected = {prefix}conf$UI[1]) %>% \n', ' helper(type = "inline", size = "m", fade = TRUE,\n', ' title = "Cell Info / Gene to colour cells by",\n', ' content = c("Select cell info / feature to colour cells",\n',