Skip to content

Commit

Permalink
Merge pull request #114 from biomage-org/patch-ensure-cell-ids-are-li…
Browse files Browse the repository at this point in the history
…st-in-cell-sets

Patch, ensure `cellIds` is sent as an array always
  • Loading branch information
cosa65 committed Jan 24, 2023
2 parents 8a472d8 + a28f523 commit 957f276
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pipeline-runner/R/gem2s-7-upload_to_aws.R
Expand Up @@ -146,7 +146,7 @@ build_sample_cellsets <- function(input, scdata_list, color_pool) {
key = sample_ids[i],
name = sample_names[i],
color = color_pool[i],
cellIds = unname(cell_ids)
cellIds = ensure_is_list_in_json(unname(cell_ids))
)
}

Expand Down Expand Up @@ -375,7 +375,7 @@ build_scratchpad_cellsets <- function(color_pool, subset_cellsets) {
key = scratchpad_ids[i],
name = scratchpad_names[i],
color = color_pool[i],
cellIds = subset_cellsets[key == scratchpad_ids[i], cell_id]
cellIds = ensure_is_list_in_json(subset_cellsets[key == scratchpad_ids[i], cell_id])
)
}

Expand Down
22 changes: 21 additions & 1 deletion pipeline-runner/R/qc-7-embed_and_cluster.R
Expand Up @@ -49,6 +49,26 @@ embed_and_cluster <-
return(result)
}

#' Ensure is list in json
#'
#' When sending responses as json, Vectors of length 0 or 1 are converted to
#' null and scalar (respectively) Using as.list fixes this, however, long R
#' lists take a VERY long time to be converted to JSON.
#' This function deals with the problematic cases, leaving vector as a vector
#' when it isnt a problem.
#'
#' @param vector
#'
#' @export
#'
ensure_is_list_in_json <- function(vector) {
if (length(vector) <= 1) {
return(as.list(vector))
} else {
return(vector)
}
}

format_cell_sets_object <-
function(cell_sets, clustering_method, color_pool) {
name <- paste0(clustering_method, " clusters")
Expand All @@ -70,7 +90,7 @@ format_cell_sets_object <-
rootNode = FALSE,
type = "cellSets",
color = color_pool[1],
cellIds = unname(cells)
cellIds = ensure_is_list_in_json(unname(cells))
)
color_pool <- color_pool[-1]
cell_sets_object$children <-
Expand Down
2 changes: 2 additions & 0 deletions pipeline-runner/R/subset-1-subset_seurat.R
@@ -1,3 +1,5 @@
library(uuid)

#' create a subset experiment
#'
#' This is the first step of a subset pipeline, which basically takes the parent
Expand Down

0 comments on commit 957f276

Please sign in to comment.