From 57b43b6c2547e4a97ddb7e772844a4b9565486a9 Mon Sep 17 00:00:00 2001 From: Jason Kai Date: Tue, 12 Sep 2023 11:23:40 -0400 Subject: [PATCH] update config wildcards and filtering Previously, the usage of `wildcards` was vast in the config file, allowing for wildcards for all sorts of entities. This PR constrains the wildcards to just subject, session, and run (can consider others in the future, but these make the most sense at the moment). Dwi filters are constrained to be in the "T1w" space, as we assume dwi processing should be performed in the same space as T1w. Alternatively, can consider "orig" space as well, but will need to think about to handle transformations to the T1w in that case. If multiple entities are found (e.g. "res"), Snakebids will throw an error reflecting the files found and suggest to the user to make use of the `--filter` option to constrain the files. --- scattr/config/snakebids.yml | 13 +------------ scattr/workflow/Snakefile | 4 +++- scattr/workflow/rules/freesurfer.smk | 8 ++++++-- scattr/workflow/rules/mrtpipelines.smk | 2 +- scattr/workflow/rules/mrtpipelines/preproc.smk | 5 +++-- scattr/workflow/rules/zona_bb_subcortex.smk | 4 +++- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/scattr/config/snakebids.yml b/scattr/config/snakebids.yml index 7f4241fd..90132051 100644 --- a/scattr/config/snakebids.yml +++ b/scattr/config/snakebids.yml @@ -30,9 +30,6 @@ pybids_inputs: wildcards: - subject - session - - acquisition - - part - - reconstruction - run pybids_inputs_dwi: dwi: @@ -41,27 +38,19 @@ pybids_inputs_dwi: extension: ".nii.gz" datatype: "dwi" space: "T1w" - part: ["mag", false] wildcards: - subject - session - - acquisition - - direction - - part - - reconstruction - run - - res mask: filters: suffix: "mask" extension: ".nii.gz" datatype: "dwi" - space: ["orig", "scanner", "individual", "T1w"] + space: "T1w" wildcards: - subject - session - - acquisition - - res - run # Configuration for the command-line parameters to make available diff --git a/scattr/workflow/Snakefile b/scattr/workflow/Snakefile index a53b06bb..d00fca75 100644 --- a/scattr/workflow/Snakefile +++ b/scattr/workflow/Snakefile @@ -26,7 +26,9 @@ inputs_dwi = generate_inputs( bids_dir=config["dwi_dir"] if config["dwi_dir"] else config["bids_dir"], pybids_inputs=config["pybids_inputs_dwi"], pybids_config=["bids", "derivatives"], - pybidsdb_dir=config.get("pybidsdb_dwi_dir") if config["pybidsdb_dwi_dir"] else config.get("pybidsdb_dir"), + pybidsdb_dir=config.get("pybidsdb_dwi_dir") + if config["pybidsdb_dwi_dir"] + else config.get("pybidsdb_dir"), pybidsdb_reset=config.get("pybidsdb_reset"), derivatives=config["derivatives"], participant_label=config["participant_label"], diff --git a/scattr/workflow/rules/freesurfer.smk b/scattr/workflow/rules/freesurfer.smk index 92f8c7bf..84162863 100644 --- a/scattr/workflow/rules/freesurfer.smk +++ b/scattr/workflow/rules/freesurfer.smk @@ -76,7 +76,9 @@ rule thalamic_segmentation: subj_dir=str(Path(bids(**inputs_t1w.subj_wildcards)).parent), output: thal_seg=str( - Path(bids(root=freesurfer_dir, **inputs_t1w.subj_wildcards)).parent + Path( + bids(root=freesurfer_dir, **inputs_t1w.subj_wildcards) + ).parent / "mri" / "ThalamicNuclei.v12.T1.mgz" ), @@ -113,7 +115,9 @@ rule mgz2nii: if not config.get("skip_thal_seg") else [], aparcaseg=str( - Path(bids(root=freesurfer_dir, **inputs_t1w.subj_wildcards)).parent + Path( + bids(root=freesurfer_dir, **inputs_t1w.subj_wildcards) + ).parent / "mri" / "aparc+aseg.mgz" ), diff --git a/scattr/workflow/rules/mrtpipelines.smk b/scattr/workflow/rules/mrtpipelines.smk index 42d3b39f..181d34b7 100644 --- a/scattr/workflow/rules/mrtpipelines.smk +++ b/scattr/workflow/rules/mrtpipelines.smk @@ -58,7 +58,7 @@ bids_labelmerge = partial( bids_log = partial( bids, root=log_dir, - **inputs_t1w.subj_wildcards, + **inputs_dwi.subj_wildcards, ) """Mrtrix3 reference (additional citations are included per rule as necessary): diff --git a/scattr/workflow/rules/mrtpipelines/preproc.smk b/scattr/workflow/rules/mrtpipelines/preproc.smk index 4bd344a9..b0f717d2 100644 --- a/scattr/workflow/rules/mrtpipelines/preproc.smk +++ b/scattr/workflow/rules/mrtpipelines/preproc.smk @@ -14,7 +14,8 @@ rule nii2mif: mask=bids( root=mrtrix_dir, datatype="dwi", - suffix="brainmask.mif", + desc="brain", + suffix="mask.mif", **inputs_dwi.subj_wildcards ), threads: 4 @@ -22,7 +23,7 @@ rule nii2mif: mem_mb=16000, time=10, log: - bids_log(suffix="nii2mif.log"), + bids_log(suffix="nii2mif.log", **inputs_dwi.subj_wildcards), group: "dwiproc" container: diff --git a/scattr/workflow/rules/zona_bb_subcortex.smk b/scattr/workflow/rules/zona_bb_subcortex.smk index 52282937..681c6d4f 100644 --- a/scattr/workflow/rules/zona_bb_subcortex.smk +++ b/scattr/workflow/rules/zona_bb_subcortex.smk @@ -71,7 +71,9 @@ rule reg2native: / Path(config["zona_bb_subcortex"][config["Space"]]["dir"]) / Path(config["zona_bb_subcortex"][config["Space"]]["T1w"]) ), - target=lambda wildcards: inputs_t1w["T1w"].filter(**wildcards).expand()[0], + target=lambda wildcards: inputs_t1w["T1w"] + .filter(**wildcards) + .expand()[0], params: out_dir=directory(str(Path(bids_anat()).parent)), out_prefix=bids_anat(