From 4bb6abafe5aabdb8870f96ba434f9ec7b0a18f5d Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:02:24 -0600 Subject: [PATCH 1/5] adding ports to datasinks for multiruns and extra workflows with *run-* --- petdeface/petdeface.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/petdeface/petdeface.py b/petdeface/petdeface.py index 63b8ce4..4774b4d 100755 --- a/petdeface/petdeface.py +++ b/petdeface/petdeface.py @@ -199,7 +199,7 @@ def deface(args: Union[dict, argparse.Namespace]) -> None: write_out_dataset_description_json(args.bids_dir) # remove temp outputs - this is commented out to enable easier testing for now - shutil.rmtree(os.path.join(output_dir, "petdeface_wf")) + #shutil.rmtree(os.path.join(output_dir, "petdeface_wf")) def count_matching_chars(a: str, b: str) -> int: @@ -303,7 +303,12 @@ def init_single_subject_wf( ses_id = "" pet_string = f"sub-{subject_id}" - pet_wf_name = f"pet_{pet_string}_wf" + # collect run info from pet file + try: + run_id = "_" + re.search("run-[^_|\/]*", str(pet_file)).group(0) + except AttributeError: + run_id = "" + pet_wf_name = f"pet_{pet_string}{run_id}_wf" pet_wf = Workflow(name=pet_wf_name) weighted_average = Node( @@ -323,12 +328,12 @@ def init_single_subject_wf( ( coreg_pet_to_t1w, datasink, - [("out_lta_file", f"{pet_string.replace('_', '.')}.pet")], + [("out_lta_file", f"{pet_string.replace('_', '.')}.pet.@{run_id}")], ), ( deface_pet, datasink, - [("out_file", f"{pet_string.replace('_', '.')}.pet.@defaced")], + [("out_file", f"{pet_string.replace('_', '.')}.pet.@defaced{run_id}")], ), ] ) From 9665c283815fd44ed85d5013518ba30b77f757d0 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Wed, 22 Nov 2023 07:53:30 -0600 Subject: [PATCH 2/5] mostly behaving, registration file is still not differentiated between runs --- petdeface/petdeface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/petdeface/petdeface.py b/petdeface/petdeface.py index 4774b4d..b677b7e 100755 --- a/petdeface/petdeface.py +++ b/petdeface/petdeface.py @@ -199,7 +199,7 @@ def deface(args: Union[dict, argparse.Namespace]) -> None: write_out_dataset_description_json(args.bids_dir) # remove temp outputs - this is commented out to enable easier testing for now - #shutil.rmtree(os.path.join(output_dir, "petdeface_wf")) + shutil.rmtree(os.path.join(output_dir, "petdeface_wf")) def count_matching_chars(a: str, b: str) -> int: From f53d403e4997e6044dc4a3d7ed857e91255d3b65 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:16:24 -0600 Subject: [PATCH 3/5] renamed registration file tested good on inherited, each, first, and multirun data --- petdeface/petdeface.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/petdeface/petdeface.py b/petdeface/petdeface.py index b677b7e..4482f34 100755 --- a/petdeface/petdeface.py +++ b/petdeface/petdeface.py @@ -310,13 +310,19 @@ def init_single_subject_wf( run_id = "" pet_wf_name = f"pet_{pet_string}{run_id}_wf" pet_wf = Workflow(name=pet_wf_name) - + + # rename registration file to something more descriptive than registration.lta + #datasink.inputs.substitutions = [("registration.lta", f"{pet_string}{run_id}_desc-pet2anat_pet.lta")] weighted_average = Node( WeightedAverage(pet_file=pet_file), name="weighted_average" ) + + mricoreg = MRICoreg(reference_file=t1w_file) + mricoreg.inputs.out_lta_file = f"{pet_string}{run_id}_desc-pet2anat_pet.lta" coreg_pet_to_t1w = Node( - MRICoreg(reference_file=t1w_file), name="coreg_pet_to_t1w" + mricoreg, "coreg_pet_to_t1w" + #MRICoreg(reference_file=t1w_file), name="coreg_pet_to_t1w" ) deface_pet = Node(ApplyMideface(in_file=pet_file), name="deface_pet") From 5bc43240a47acc5ca8ef7959e8c79c1648779954 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:21:07 -0600 Subject: [PATCH 4/5] bump version, format with black --- petdeface/petdeface.py | 22 ++++++++++++---------- pyproject.toml | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/petdeface/petdeface.py b/petdeface/petdeface.py index 4482f34..1c0be6a 100755 --- a/petdeface/petdeface.py +++ b/petdeface/petdeface.py @@ -310,20 +310,17 @@ def init_single_subject_wf( run_id = "" pet_wf_name = f"pet_{pet_string}{run_id}_wf" pet_wf = Workflow(name=pet_wf_name) - - # rename registration file to something more descriptive than registration.lta - #datasink.inputs.substitutions = [("registration.lta", f"{pet_string}{run_id}_desc-pet2anat_pet.lta")] + weighted_average = Node( WeightedAverage(pet_file=pet_file), name="weighted_average" ) - + + # rename registration file to something more descriptive than registration.lta + # we do this here to account for mulitple runs during the same session mricoreg = MRICoreg(reference_file=t1w_file) - mricoreg.inputs.out_lta_file = f"{pet_string}{run_id}_desc-pet2anat_pet.lta" + mricoreg.inputs.out_lta_file = f"{pet_string}{run_id}_desc-pet2anat_pet.lta" - coreg_pet_to_t1w = Node( - mricoreg, "coreg_pet_to_t1w" - #MRICoreg(reference_file=t1w_file), name="coreg_pet_to_t1w" - ) + coreg_pet_to_t1w = Node(mricoreg, "coreg_pet_to_t1w") deface_pet = Node(ApplyMideface(in_file=pet_file), name="deface_pet") @@ -339,7 +336,12 @@ def init_single_subject_wf( ( deface_pet, datasink, - [("out_file", f"{pet_string.replace('_', '.')}.pet.@defaced{run_id}")], + [ + ( + "out_file", + f"{pet_string.replace('_', '.')}.pet.@defaced{run_id}", + ) + ], ), ] ) diff --git a/pyproject.toml b/pyproject.toml index 4495fc8..5524d61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "petdeface" -version = "0.0.1" +version = "0.0.2" description = "A nipype PET and MR defacing pipeline for BIDS datasets utilizing FreeSurfer's MiDeFace." authors = ["Martin Nørgaard ", "Anthony Galassi <28850131+bendhouseart@users.noreply.github.com>", "Murat Bilgel "] license = "MIT" From 50d81f753593e4131a4fceec32c05ab9f41af301 Mon Sep 17 00:00:00 2001 From: Anthony Galassi <28850131+bendhouseart@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:30:38 -0600 Subject: [PATCH 5/5] Update petdeface/petdeface.py dropped name for MRICoreg node --- petdeface/petdeface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/petdeface/petdeface.py b/petdeface/petdeface.py index 1c0be6a..4040dae 100755 --- a/petdeface/petdeface.py +++ b/petdeface/petdeface.py @@ -317,7 +317,7 @@ def init_single_subject_wf( # rename registration file to something more descriptive than registration.lta # we do this here to account for mulitple runs during the same session - mricoreg = MRICoreg(reference_file=t1w_file) + mricoreg = MRICoreg(reference_file=t1w_file, name="coreg_pet_to_t1w") mricoreg.inputs.out_lta_file = f"{pet_string}{run_id}_desc-pet2anat_pet.lta" coreg_pet_to_t1w = Node(mricoreg, "coreg_pet_to_t1w")