From faa19072a9be409128e456fee5de4086419871b8 Mon Sep 17 00:00:00 2001 From: Cornelius Kronlage Date: Fri, 3 Oct 2025 15:47:58 +0000 Subject: [PATCH 1/2] Fix subject_id formatting in run_hippunfold_parallel --- scripts/preprocess/run_script_segmentation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/preprocess/run_script_segmentation.py b/scripts/preprocess/run_script_segmentation.py index 65ffd55..929957f 100644 --- a/scripts/preprocess/run_script_segmentation.py +++ b/scripts/preprocess/run_script_segmentation.py @@ -43,7 +43,8 @@ def run_hippunfold_parallel(subjects, bids_dir=None, hippo_dir=None, num_procs=1 if subjects_to_run!=[]: print(get_m(f'Start Hippunfold segmentation in parallel for {subjects_to_run}', None, 'INFO')) - command = format(f"hippunfold {bids_dir} {hippo_dir} participant --participant-label {' '.join(subjects_to_run)} --core {num_procs} --modality T1w") + subjects_to_run_shortformat = [subject_id.split('sub-')[-1] for subject_id in subjects_to_run] + command = format(f"hippunfold {bids_dir} {hippo_dir} participant --participant-label {' '.join(subjects_to_run_shortformat)} --core {num_procs} --modality T1w") if verbose: print(command) proc = Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8') @@ -55,8 +56,8 @@ def run_hippunfold_parallel(subjects, bids_dir=None, hippo_dir=None, num_procs=1 if delete_intermediate: print(get_m(f'Delete intermediate files that takes lot of space: hippunfold_outputs/hippunfold//warps and hippunfold_outputs/work folders', subjects_to_run, 'INFO')) for subject in subjects_to_run: - shutil.rmtree(hippo_dir, 'hippunfold', subject, 'warps') - shutil.rmtree(hippo_dir, 'work', f'{subject}_work.tar.gz') + shutil.rmtree(os.path.join(hippo_dir, 'hippunfold', subject, 'warps')) + shutil.rmtree(os.path.join(hippo_dir, 'work')) return True else: print(get_m(f'Hippunfold segmentation failed for 1 of the subject. Please check the logs at {hippo_dir}/logs/', None, 'ERROR')) From fda1e1cff8b43ff9f925109090ded2544a2285a1 Mon Sep 17 00:00:00 2001 From: Cornelius Kronlage Date: Wed, 15 Oct 2025 12:56:47 +0000 Subject: [PATCH 2/2] Add checks before deleting intermediate files in run_hippunfold_parallel --- scripts/preprocess/run_script_segmentation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/preprocess/run_script_segmentation.py b/scripts/preprocess/run_script_segmentation.py index 929957f..57d8777 100644 --- a/scripts/preprocess/run_script_segmentation.py +++ b/scripts/preprocess/run_script_segmentation.py @@ -56,8 +56,10 @@ def run_hippunfold_parallel(subjects, bids_dir=None, hippo_dir=None, num_procs=1 if delete_intermediate: print(get_m(f'Delete intermediate files that takes lot of space: hippunfold_outputs/hippunfold//warps and hippunfold_outputs/work folders', subjects_to_run, 'INFO')) for subject in subjects_to_run: - shutil.rmtree(os.path.join(hippo_dir, 'hippunfold', subject, 'warps')) - shutil.rmtree(os.path.join(hippo_dir, 'work')) + if os.path.exists(os.path.join(hippo_dir, 'hippunfold', subject, 'warps')): + shutil.rmtree(os.path.join(hippo_dir, 'hippunfold', subject, 'warps')) + if os.path.isfile(os.path.join(hippo_dir, 'work', f'{subject_bids_id}_work.tar.gz')): + os.remove(os.path.join(hippo_dir, 'work', f'{subject_bids_id}_work.tar.gz')) return True else: print(get_m(f'Hippunfold segmentation failed for 1 of the subject. Please check the logs at {hippo_dir}/logs/', None, 'ERROR'))