2025-02-18 17:44:25 -03:00
|
|
|
read_all_experiments <- function(base_path, skip_incomplete = TRUE, prefix = '') {
|
2025-01-10 17:48:11 -03:00
|
|
|
roots <- list.files(base_path,
|
|
|
|
|
include.dirs = TRUE, no.. = TRUE, full.names = TRUE)
|
|
|
|
|
|
|
|
|
|
experiments <- lapply(roots, read_single_experiment)
|
2025-02-18 17:44:25 -03:00
|
|
|
names(experiments) <- paste0(prefix, sapply(roots, basename))
|
2025-01-10 17:48:11 -03:00
|
|
|
|
|
|
|
|
# Validates that no experiment has missing data.
|
|
|
|
|
key_sets <- lapply(experiments, ls) |> unique()
|
|
|
|
|
# Selects the largest keyset which is presumably the most complete.
|
|
|
|
|
key_set <- key_sets[[order(sapply(key_sets, length), decreasing = TRUE)[1]]]
|
|
|
|
|
|
|
|
|
|
# Discards any experiment that doesn't have all keys.
|
|
|
|
|
experiments <- lapply(experiments, function(experiment) {
|
|
|
|
|
if (!(all(key_set %in% names(experiment)))) {
|
|
|
|
|
warning(glue::glue('Experiment {experiment$experiment_id} is missing ',
|
|
|
|
|
'some keys and will be discarded.'))
|
|
|
|
|
NULL
|
|
|
|
|
} else {
|
|
|
|
|
experiment
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
experiments[!is.null(experiments)]
|
|
|
|
|
}
|
2025-02-03 15:45:53 -03:00
|
|
|
|
2025-02-18 17:44:25 -03:00
|
|
|
merge_experiments <- function(set_1, set_2) {
|
2025-02-03 15:45:53 -03:00
|
|
|
merged <- list()
|
|
|
|
|
|
|
|
|
|
for (set_1_id in ls(set_1)) {
|
|
|
|
|
merged[[set_1_id]] <- set_1[[set_1_id]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (set_2_id in ls(set_2)) {
|
2025-02-18 17:44:25 -03:00
|
|
|
if (set_2_id %in% names(merged)) {
|
|
|
|
|
stop(glue::glue('Duplicate experiment ID {set_2_id}. Cannot merge.'))
|
|
|
|
|
}
|
|
|
|
|
merged[[set_2_id]] <- set_2[[set_2_id]]
|
2025-02-03 15:45:53 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
merged
|
|
|
|
|
}
|