Skip to content

Commit

Permalink
Add permutations and use new paradigms
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <psychelzh@outlook.com>
  • Loading branch information
psychelzh committed Feb 29, 2024
1 parent a6fe43c commit 2f9b30a
Showing 1 changed file with 70 additions and 37 deletions.
107 changes: 70 additions & 37 deletions _scripts/predict_phenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,104 @@ tar_option_set(
)
setup_parallel_plan()

config_cpm <- prepare_config_cpm(
config == "gsr",
run == "full",
thresh_method == "alpha",
thresh_level == 0.01
)
cpm_branches <- tarchetypes::tar_map(
config_cpm,
names = !starts_with("file"),
tarchetypes::tar_rep(
names = !c(file_fc, fd),
tar_target(
cpm_result,
apply(
qs::qread(file_scores_factor)[subjs_to_keep, ], 2,
\(scores) {
cpmr::cpm(
qs::qread(file_fc)[subjs_to_keep, ],
scores,
confounds = qs::qread(file_confounds)[subjs_to_keep, ],
thresh_method = thresh_method,
thresh_level = thresh_level,
kfolds = 10
)
}
scores, 2,
perform_cpm,
fc = qs::qread(file_fc)[subjs_keep_neural, ],
confounds = match_confounds(users_confounds, fd),
bias_correct = FALSE,
thresh_method = thresh_method,
thresh_level = thresh_level
),
batches = 4,
reps = 5,
iteration = "list",
retrieval = "worker",
storage = "worker"
),
tarchetypes::tar_rep2(
tar_target(
cpm_performance,
lapply_tar_batches(
cpm_result,
extract_cpm_performance
) |>
list_rbind(names_to = "latent"),
cpm_result,
retrieval = "worker",
storage = "worker"
)
)
list(
tar_target(
file_scores_factor,
path_obj_from_proj("scores_bf_full", "confirm_factors"),
format = "file_fast"

cpm_branches_perms <- tarchetypes::tar_map(
dplyr::filter(
config_cpm,
task == "am",
thresh_method == "alpha",
thresh_level == 0.01
),
names = !c(file_fc, fd),
tarchetypes::tar_rep(
cpm_result_perm,
apply(
scores, 2,
perform_cpm_perm,
fc = qs::qread(file_fc)[subjs_keep_neural, ],
confounds = match_confounds(users_confounds, fd),
bias_correct = FALSE,
thresh_method = thresh_method,
thresh_level = thresh_level
),
batches = 100,
reps = 10,
iteration = "list",
retrieval = "worker",
storage = "worker"
),
tarchetypes::tar_rep2(
cpm_performance_perm,
lapply_tar_batches(
cpm_result_perm,
extract_cpm_performance
) |>
list_rbind_tar_batches(names_to = "index"),
cpm_result_perm,
retrieval = "worker",
storage = "worker"
)
)

list(
tarchetypes::tar_file_read(
subjs_keep_neural,
path_obj_from_proj("subjs_keep_neural", "prepare_neural"),
scores,
path_obj_from_proj("scores", "cognition_structure"),
read = qs::qread(!!.x)
),
tar_target(
subjs_to_keep,
# intersect() does not work for integer64
# https://github.com/truecluster/bit64/issues/29
intersect(
as.character(subjs_keep_neural),
rownames(qs::qread(file_scores_factor))
)
),
tar_prep_files_cpm(),
tar_prepare_cpm(),
cpm_branches,
tarchetypes::tar_combine(
cpm_performance,
cpm_branches$cpm_performance,
command = bind_rows_meta(
!!!.x,
.prefix = "cpm_performance",
.type = "cpm"
.names = c(names(config_fc), names(hypers_cpm)),
.prefix = "cpm_performance"
)
),
cpm_branches_perms,
tarchetypes::tar_combine(
cpm_performance_perm,
cpm_branches_perms$cpm_performance_perm,
command = bind_rows_meta(
!!!.x,
.names = c(names(config_fc), names(hypers_cpm)),
.prefix = "cpm_performance_perm"
)
)
)

0 comments on commit 2f9b30a

Please sign in to comment.