Skip to content

Commit

Permalink
added fix for set_unique_cl_names_dt
Browse files Browse the repository at this point in the history
  • Loading branch information
darsoo committed Sep 24, 2024
1 parent 6f1d0a7 commit d6ea4fd
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions R/standardize_MAE.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,33 @@ set_unique_cl_names_dt <- function(col_data, sep = " ") {
clid <- get_env_identifiers("cellline")

if (!is.null(col_data[[cellline_name]])) {
duplicated_ids <- col_data[[cellline_name]][duplicated(col_data[[cellline_name]])]
if (data.table::is.data.table(col_data)) {
# for data.table check multiple columns; and update cl names only if adding clid suffix can make them different
unique_col_names <- c(unlist(get_default_identifiers()[
c("cellline_name", "drug_name", "drug_name2",
"concentration2", "duration", "data_source")
]), "normalization_type")
unique_col_names <- intersect(unique_col_names, names(col_data))
duplicated_ids <- col_data[[cellline_name]][duplicated(col_data, by = unique_col_names)]
unique_col_names_clid <- c(unique_col_names, get_default_identifiers()$cellline)
duplicated_ids_with_clid <- col_data[[cellline_name]][duplicated(col_data, by = unique_col_names_clid)]
duplicated_ids <- setdiff(duplicated_ids, duplicated_ids_with_clid)
} else {
duplicated_ids <- col_data[[cellline_name]][duplicated(col_data[[cellline_name]])]
}

if (length(duplicated_ids) > 0) {
for (dup_id in unique(duplicated_ids)) {
dup_indices <- which(col_data[[cellline_name]] == dup_id)
col_data[[cellline_name]][dup_indices] <-
paste0(
col_data[[cellline_name]][dup_indices],
sep,
"(",
col_data[[clid]][dup_indices],
")"
)
}
for (dup_id in unique(duplicated_ids)) {
dup_indices <- which(col_data[[cellline_name]] == dup_id)
col_data[[cellline_name]][dup_indices] <-
paste0(
col_data[[cellline_name]][dup_indices],
sep,
"(",
col_data[[clid]][dup_indices],
")"
)
}
}
}

Expand Down

0 comments on commit d6ea4fd

Please sign in to comment.