From 5c26c87e8dbd6dac84e7ee713a38532c63bf0e63 Mon Sep 17 00:00:00 2001 From: neuronflow Date: Mon, 1 Apr 2024 16:17:09 +0200 Subject: [PATCH] handle missing suffixes Signed-off-by: neuronflow --- .../registration/eReg/eReg.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/brainles_preprocessing/registration/eReg/eReg.py b/brainles_preprocessing/registration/eReg/eReg.py index 1a7cbd2..bf043cd 100644 --- a/brainles_preprocessing/registration/eReg/eReg.py +++ b/brainles_preprocessing/registration/eReg/eReg.py @@ -1,4 +1,6 @@ # TODO add typing and docs +import os + from ereg.registration import RegistrationClass from brainles_preprocessing.registration.registrator import Registrator @@ -38,6 +40,8 @@ def register( configuration_file=self.configuration_file, ) + matrix_path = _add_txt_suffix(matrix_path) + registrator.register( target_image=fixed_image_path, moving_image=moving_image_path, @@ -69,6 +73,8 @@ def transform( configuration_file=self.configuration_file, ) + matrix_path = _add_txt_suffix(matrix_path) + registrator.resample_image( target_image=fixed_image_path, moving_image=moving_image_path, @@ -76,3 +82,19 @@ def transform( transform_file=matrix_path, log_file=log_file_path, ) + + +def _add_txt_suffix(filename: str) -> str: + """ + Adds a ".txt" suffix to the filename if it doesn't have any extension. + + Parameters: + filename (str): The filename to check and potentially modify. + + Returns: + str: The filename with ".txt" suffix added if needed. + """ + base, ext = os.path.splitext(filename) + if not ext: + filename += ".txt" + return filename