diff --git a/hippunfold/workflow/rules/gifti.smk b/hippunfold/workflow/rules/gifti.smk index 46805e9c..2ae35706 100644 --- a/hippunfold/workflow/rules/gifti.smk +++ b/hippunfold/workflow/rules/gifti.smk @@ -466,7 +466,7 @@ rule metric_to_nii: params: interp="-nearest-vertex 1", refflatnii=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"]["multihist7"]["label_nii"], + / config["atlas_files"]["multihist7"]["label_nii"].format(**wildcards), output: metric_nii=bids( root=work, @@ -531,11 +531,11 @@ rule unfolded_registration: warpfn="tmp1Warp.nii.gz", invwarpfn="tmp1InverseWarp.nii.gz", refthickness=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"][wildcards.atlas]["thickness"], + / config["atlas_files"][wildcards.atlas]["thickness"].format(**wildcards), refcurvature=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"][wildcards.atlas]["curvature"], + / config["atlas_files"][wildcards.atlas]["curvature"].format(**wildcards), refgyrification=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"][wildcards.atlas]["gyrification"], + / config["atlas_files"][wildcards.atlas]["gyrification"].format(**wildcards), output: warp=bids( root=work, @@ -1058,7 +1058,7 @@ rule resample_atlas_to_refvol: atlas_dir=lambda wildcards: Path(download_dir) / "atlas" / wildcards.atlas, params: atlas=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"][wildcards.atlas]["label_nii"], + / config["atlas_files"][wildcards.atlas]["label_nii"].format(**wildcards), output: label_nii=bids( root=work, @@ -1110,7 +1110,7 @@ rule nii_to_label_gii: atlas_dir=lambda wildcards: Path(download_dir) / "atlas" / wildcards.atlas, params: label_list=lambda wildcards, input: Path(input.atlas_dir) - / config["atlas_files"][wildcards.atlas]["label_list"], + / config["atlas_files"][wildcards.atlas]["label_list"].format(**wildcards), structure_type=lambda wildcards: hemi_to_structure[wildcards.hemi], output: label_gii=bids( @@ -1131,7 +1131,7 @@ rule nii_to_label_gii: shadow: "minimal" shell: - "wb_command -volume-to-surface-mapping {params.label_list} {input.surf} temp.shape.gii -enclosing && " + "wb_command -volume-to-surface-mapping {input.label_nii} {input.surf} temp.shape.gii -enclosing && " "wb_command -metric-label-import temp.shape.gii {params.label_list} {output.label_gii} && " "wb_command -set-structure {output.label_gii} {params.structure_type}" diff --git a/hippunfold/workflow/rules/nnunet.smk b/hippunfold/workflow/rules/nnunet.smk index 84e76103..054f0ecf 100644 --- a/hippunfold/workflow/rules/nnunet.smk +++ b/hippunfold/workflow/rules/nnunet.smk @@ -203,15 +203,13 @@ rule unflip_nnunet_nii: def get_f3d_ref(wildcards, input): if config["modality"] == "T2w": - nii = ( - Path(input.template_dir) - / config["template_files"][config["template"]]["crop_ref"] - ) + nii = Path(input.template_dir) / config["template_files"][config["template"]][ + "crop_ref" + ].format(**wildcards) elif config["modality"] == "T1w": - nii = ( - Path(input.template_dir) - / config["template_files"][config["template"]]["crop_refT1w"] - ) + nii = Path(input.template_dir) / config["template_files"][config["template"]][ + "crop_refT1w" + ].format(**wildcards) else: raise ValueError("modality not supported for nnunet!") return nii @@ -302,8 +300,12 @@ rule qc_nnunet_dice: template_dir=Path(download_dir) / "template" / config["template"], params: hipp_lbls=[1, 2, 7, 8], - ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["Mask_crop"], + ref=lambda wildcards, input: ( + Path(input.template_dir) + / config["template_files"][config["template"]]["Mask_crop"].format( + **wildcards + ) + ), output: dice=report( bids( diff --git a/hippunfold/workflow/rules/preproc_seg.smk b/hippunfold/workflow/rules/preproc_seg.smk index 1f9afab0..1bfbcf86 100644 --- a/hippunfold/workflow/rules/preproc_seg.smk +++ b/hippunfold/workflow/rules/preproc_seg.smk @@ -42,7 +42,7 @@ rule warp_seg_to_corobl_crop: template_dir=Path(download_dir) / "template" / config["template"], params: ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["crop_ref"], + / config["template_files"][config["template"]]["crop_ref"].format(**wildcards), output: nii=bids( root=work, diff --git a/hippunfold/workflow/rules/preproc_t1.smk b/hippunfold/workflow/rules/preproc_t1.smk index 02b2e841..96bf100f 100644 --- a/hippunfold/workflow/rules/preproc_t1.smk +++ b/hippunfold/workflow/rules/preproc_t1.smk @@ -72,9 +72,11 @@ else: def reg_to_template_cmd(wildcards, input, output): - ref = ( + ref = str( Path(input.template_dir) - / config["template_files"][config["template"]][wildcards.modality], + / config["template_files"][config["template"]][wildcards.modality].format( + **wildcards + ), ) if config["no_reg_template"]: cmd = f"reg_resample -flo {input.flo} -ref {ref} -res {output.warped_subj} -aff {input.xfm_identity}; cp {input.xfm_identity} {output.xfm_ras}" @@ -183,7 +185,9 @@ rule compose_template_xfm_corobl: template_dir=Path(download_dir) / "template" / config["template"], params: std_to_cor=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["xfm_corobl"], + / config["template_files"][config["template"]]["xfm_corobl"].format( + **wildcards + ), output: sub_to_cor=bids( root=work, @@ -288,7 +292,7 @@ rule warp_t1_to_corobl_crop: template_dir=Path(download_dir) / "template" / config["template"], params: ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["crop_ref"], + / config["template_files"][config["template"]]["crop_ref"].format(**wildcards), output: t1=bids( root=work, diff --git a/hippunfold/workflow/rules/preproc_t2.smk b/hippunfold/workflow/rules/preproc_t2.smk index 0573498b..4dc43e60 100644 --- a/hippunfold/workflow/rules/preproc_t2.smk +++ b/hippunfold/workflow/rules/preproc_t2.smk @@ -308,10 +308,9 @@ def get_cmd_compose_t2_xfm_corobl(wildcards, input): # xfm0: t2 to template xfm0 = input.t2_to_std # xfm1: template to corobl - xfm1 = ( - Path(input.template_dir) - / config["template_files"][config["template"]]["xfm_corobl"] - ) + xfm1 = Path(input.template_dir) / config["template_files"][config["template"]][ + "xfm_corobl" + ].format(**wildcards) return "c3d_affine_tool -itk {xfm0} -itk {xfm1} -mult -oitk {output}" @@ -394,7 +393,7 @@ rule warp_t2_to_corobl_crop: template_dir=Path(download_dir) / "template" / config["template"], params: ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["crop_ref"], + / config["template_files"][config["template"]]["crop_ref"].format(**wildcards), output: nii=bids( root=work, diff --git a/hippunfold/workflow/rules/qc.smk b/hippunfold/workflow/rules/qc.smk index bf9c8650..b2b9d028 100644 --- a/hippunfold/workflow/rules/qc.smk +++ b/hippunfold/workflow/rules/qc.smk @@ -10,8 +10,12 @@ rule qc_reg_to_template: ), template_dir=Path(download_dir) / "template" / config["template"], params: - ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]][wildcards.native_modality], + ref=lambda wildcards, input: str( + Path(input.template_dir) + / config["template_files"][config["template"]][ + wildcards.native_modality + ].format(**wildcards) + ), output: png=report( bids(