Skip to content

Commit

Permalink
Add custom confounds for no_gsr
Browse files Browse the repository at this point in the history
The added are global signals from CSF and WM.

Signed-off-by: Liang Zhang <psychelzh@outlook.com>
  • Loading branch information
psychelzh committed Feb 24, 2024
1 parent cd9fe3d commit c8c480a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/xcpd.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ commit_xcpd <- function(sublist, file_sublist = NULL, ...) {
}
num_jobs <- nrow(sublist)
params_post <- clize_list(
config::get(
"params",
config = config_params,
file = file_config_xcpd
withr::with_envvar(
c(PROJECT_ROOT = project_root),
config::get(
"params",
config = config_params,
file = file_config_xcpd
)
)
)
job_main <- fs::path(path_qsub, "xcpd.tmpl.qsub") |>
Expand Down
1 change: 1 addition & 0 deletions config/xcpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default:
no_gsr:
params:
nuisance-regressors: 24P
custom-confounds: !expr fs::path(Sys.getenv("PROJECT_ROOT"), "xcp_d/custom_confounds")

default_mni:
params:
Expand Down
2 changes: 2 additions & 0 deletions xcp_d/custom_confounds/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
20 changes: 20 additions & 0 deletions xcp_d/prepare_confounds.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# please use this in RStudio and set a proper conda environment
library(tidyverse)
reticulate::use_condaenv("bids")
bids <- reticulate::import("bids")
layout_confounds <- bids$BIDSLayout(
fs::path("derivatives/fmriprep"),
validate = FALSE,
database_path = fs::path("derivatives/layout_fmriprep")
)$get(desc = "confounds", extension = "tsv")
path_new <- "xcp_d/custom_confounds"
for (layout in layout_confounds) {
cur_path <- layout$path
read_tsv(cur_path, show_col_types = FALSE, na = "n/a") |>
select(
# global signals for CSF and WM
(starts_with("csf") | starts_with("white_matter")) & !contains("wm")
) |>
mutate(across(everything(), \(x) replace_na(x, 0))) |>
write_tsv(fs::path(path_new, fs::path_file(cur_path)), na = "")
}

0 comments on commit c8c480a

Please sign in to comment.