Skip to content

Commit

Permalink
Merge branch 'master' into 36-cell-level-metadata
Browse files Browse the repository at this point in the history
Signed-off-by: German Beldorati Stark <[email protected]>
  • Loading branch information
gerbeldo committed Oct 26, 2023
2 parents 0f194aa + b440cf9 commit b5b448d
Show file tree
Hide file tree
Showing 12 changed files with 85,669 additions and 85,506 deletions.
4 changes: 3 additions & 1 deletion pipeline-runner/R/gem2s-7-upload_to_aws.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ get_metadata_cell_ids <- function(scdata_list, valid_metadata_name, value) {
extract_subset_user_metadata <- function(subset_cellsets) {
# metadata keys are the <track_name>-<value>, and name are the values alone
metadata <- unique(subset_cellsets[type == "metadata"], by = "key")
metadata[, metadata_track := gsub(paste0("-", name, "$"), "", key), by = "key"]
# escape regex characters to avoid errors when creating cellsets
metadata[, escaped_name := gsub("([.\\\\+*?\\[^\\]$(){}=!<>|:-])", "\\\\\\1", name, perl = TRUE)]
metadata[, metadata_track := gsub(paste0("-", escaped_name, "$"), "", key), by = "key"]

metadata <- metadata[, c("metadata_track", "name")]
data.table::setnames(metadata, "name", "metadata_value")
Expand Down
23 changes: 22 additions & 1 deletion pipeline-runner/R/qc-7-embed_and_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ format_cluster_cellsets <- function(cell_sets,
name = paste0(clustering_method, " clusters")) {
message("Formatting cluster cellsets.")

# careful with capital l on type for the key.
cell_sets_object <-
list(
key = clustering_method,
Expand All @@ -76,7 +77,7 @@ format_cluster_cellsets <- function(cell_sets,
type = "cellSets",
children = list()
)
for (cluster in sort(unique(cell_sets$cluster))) {
for (cluster in sort_cluster_names(unique(cell_sets$cluster))) {
cells <- cell_sets[cell_sets$cluster == cluster, "cell_ids"]
is.num <- !is.na(as.numeric(cluster))
set_name <- ifelse(is.num, paste("Cluster", cluster), cluster)
Expand All @@ -97,6 +98,7 @@ format_cluster_cellsets <- function(cell_sets,
}



#' replace cell class by key
#'
#' Replaces an entire cell class (group of cellsets) by key. Used to replace
Expand Down Expand Up @@ -431,3 +433,22 @@ format_cl_metadata_cellsets <-

return(cl_metadata_cellsets)
}

#' Sort cluster names
#'
#' Sorts cluster names naturally, i.e. Cluster 1, Cluster 2, Cluster 10
#'
#' @param strings cluster names
#'
#' @return sorted vector
#' @export
#'
sort_cluster_names <- function(strings) {
# extract letters and digits
char <- gsub("\\d", "", strings)
nums <- gsub("\\D", "", strings)

sorted_indices <- order(char, as.integer(nums))

return(strings[sorted_indices])
}
Loading

0 comments on commit b5b448d

Please sign in to comment.