Skip to content

Commit 0814073

Browse files
Working version of prefetch; correction for output spaces
1 parent d8f7f38 commit 0814073

5 files changed

Lines changed: 476 additions & 54 deletions

File tree

‎R/process_subject.R‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,7 @@ submit_fmriprep <- function(scfg, sub_dir = NULL, sub_id = NULL, ses_id = NULL,
324324
return(NULL)
325325
}
326326

327-
if (isTRUE(scfg$aroma$enable) && (is.null(scfg$fmriprep$output_spaces) || !grepl("MNI152NLin6Asym:res-2", scfg$fmriprep$output_spaces, fixed = TRUE))) {
328-
message("Adding MNI152NLin6Asym:res-2 to output spaces for fmriprep to allow AROMA to run.")
329-
scfg$fmriprep$output_spaces <- paste(scfg$fmriprep$output_spaces, "MNI152NLin6Asym:res-2")
330-
}
327+
scfg <- ensure_aroma_output_space(scfg, require_aroma = isTRUE(scfg$aroma$enable), verbose = FALSE)
331328

332329
# for the mem request, have fmriprep request a bit less than the job gets itself
333330
# https://neurostars.org/t/fmriprep-failing-on-hpc-via-singularity/26342/27
@@ -337,7 +334,7 @@ submit_fmriprep <- function(scfg, sub_dir = NULL, sub_id = NULL, ses_id = NULL,
337334
glue("--participant_label {sub_id}"),
338335
glue("-w {scfg$metadata$scratch_directory}"),
339336
glue("--fs-license-file {scfg$fmriprep$fs_license_file}"),
340-
glue("--output-spaces {scfg$fmriprep$output_spaces}"),
337+
glue("--output-spaces {shQuote(trimws(scfg$fmriprep$output_spaces))}"),
341338
glue("--mem {format(max(4, scfg$fmriprep$memgb - 4)*1000, scientific=FALSE)}") # convert to MB
342339
), collapse = TRUE)
343340

@@ -433,7 +430,8 @@ submit_aroma <- function(scfg, sub_dir = NULL, sub_id = NULL, ses_id = NULL, env
433430
), collapse = TRUE)
434431

435432
cleanup <- isTRUE(scfg$aroma$cleanup)
436-
if (cleanup && !is.null(scfg$fmriprep$output_spaces) &&
433+
auto_added_aroma <- isTRUE(scfg$fmriprep$auto_added_aroma_space)
434+
if (cleanup && !auto_added_aroma && !is.null(scfg$fmriprep$output_spaces) &&
437435
grepl("MNI152NLin6Asym:res-2", scfg$fmriprep$output_spaces, fixed = TRUE)) {
438436
msg <- "AROMA cleanup requested but will not occur because MNI152NLin6Asym:res-2 is in fmriprep --output-spaces."
439437
if (!is.null(lg)) lg$warn(msg) else warning(msg)

‎R/run_project.R‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ run_project <- function(scfg, steps = NULL, subject_filter = NULL, postprocess_s
191191
stop("Cannot run postprocessing without a valid FSL container.")
192192
}
193193

194+
scfg <- ensure_aroma_output_space(scfg, require_aroma = isTRUE(steps["aroma"]))
195+
194196
flywheel_id <- NULL
195197
if (isTRUE(steps["flywheel_sync"])) flywheel_id <- submit_flywheel_sync(scfg)
196198

@@ -474,3 +476,29 @@ submit_prefetch_templates <- function(scfg, steps) {
474476

475477
return(job_id)
476478
}
479+
480+
ensure_aroma_output_space <- function(scfg, require_aroma = isTRUE(scfg$aroma$enable), verbose = TRUE) {
481+
checkmate::assert_class(scfg, "bg_project_cfg")
482+
if (!isTRUE(require_aroma)) return(scfg)
483+
484+
if (is.null(scfg$fmriprep$auto_added_aroma_space)) scfg$fmriprep$auto_added_aroma_space <- FALSE
485+
486+
spaces <- scfg$fmriprep$output_spaces
487+
has_required_space <- !is.null(spaces) && grepl("MNI152NLin6Asym:res-2", spaces, fixed = TRUE)
488+
if (has_required_space) return(scfg)
489+
490+
addition <- "MNI152NLin6Asym:res-2"
491+
if (is.null(spaces) || !nzchar(trimws(spaces))) {
492+
scfg$fmriprep$output_spaces <- addition
493+
} else {
494+
scfg$fmriprep$output_spaces <- trimws(paste(spaces, addition))
495+
}
496+
497+
if (isTRUE(verbose)) {
498+
message("Adding MNI152NLin6Asym:res-2 to output spaces for fmriprep to allow AROMA to run.")
499+
}
500+
501+
scfg$fmriprep$auto_added_aroma_space <- TRUE
502+
503+
return(scfg)
504+
}

‎R/setup_extract.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ setup_extract_stream <- function(scfg, fields = NULL, stream_name = NULL) {
141141
}
142142

143143
if (!is.null(stream_name)) {
144-
cat(glue("\n--- Specifying extraction stream: {stream_name} ---\n"))
144+
cat(glue("\n--- Specifying extraction stream: {stream_name} ---\n", .trim = FALSE))
145145
}
146146

147147
defaults <- list(

‎R/setup_project.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ setup_compute_environment <- function(scfg = list(), fields = NULL) {
838838
if (nzchar(fw_path)) {
839839
use_fw <- prompt_input(
840840
instruct = glue("Found Flywheel CLI at {fw_path}"),
841-
prompt = "Use this location?",
841+
prompt = "Use this to run flywheel?",
842842
type = "flag",
843843
default = TRUE
844844
)

0 commit comments

Comments
 (0)