Skip to content

Commit

Permalink
update config wildcards and filtering
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaitj committed Sep 12, 2023
1 parent 0998cc7 commit 57b43b6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
13 changes: 1 addition & 12 deletions scattr/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ pybids_inputs:
wildcards:
- subject
- session
- acquisition
- part
- reconstruction
- run
pybids_inputs_dwi:
dwi:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scattr/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
8 changes: 6 additions & 2 deletions scattr/workflow/rules/freesurfer.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down Expand Up @@ -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"
),
Expand Down
2 changes: 1 addition & 1 deletion scattr/workflow/rules/mrtpipelines.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions scattr/workflow/rules/mrtpipelines/preproc.smk
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ rule nii2mif:
mask=bids(
root=mrtrix_dir,
datatype="dwi",
suffix="brainmask.mif",
desc="brain",
suffix="mask.mif",
**inputs_dwi.subj_wildcards
),
threads: 4
resources:
mem_mb=16000,
time=10,
log:
bids_log(suffix="nii2mif.log"),
bids_log(suffix="nii2mif.log", **inputs_dwi.subj_wildcards),
group:
"dwiproc"
container:
Expand Down
4 changes: 3 additions & 1 deletion scattr/workflow/rules/zona_bb_subcortex.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 57b43b6

Please sign in to comment.