diff --git a/brainles_preprocessing/registration/functional.py b/brainles_preprocessing/registration/functional.py index 3f57dfd..52c8848 100644 --- a/brainles_preprocessing/registration/functional.py +++ b/brainles_preprocessing/registration/functional.py @@ -1,4 +1,3 @@ -from .niftyreg import niftyreg_caller from .niftyreg import NiftyRegRegistrator diff --git a/brainles_preprocessing/registration/niftyreg.py b/brainles_preprocessing/registration/niftyreg.py index 9055fa9..a09da89 100644 --- a/brainles_preprocessing/registration/niftyreg.py +++ b/brainles_preprocessing/registration/niftyreg.py @@ -1,7 +1,4 @@ -import datetime import os -import shlex -import subprocess from auxiliary.runscript import ScriptRunner from auxiliary.turbopath import turbopath @@ -70,8 +67,6 @@ def register( turbopath(__file__).parent + "/niftyreg_scripts/reg_aladin", ) - print("niftyreg_executable:", niftyreg_executable) - input_params = [ turbopath(niftyreg_executable), turbopath(fixed_image), @@ -80,10 +75,9 @@ def register( turbopath(matrix), ] - print("Input Params:", input_params) - # Call the run method to execute the script and capture the output in the log file success, error = runner.run(input_params) + # if success: # print("Script executed successfully. Check the log file for details.") # else: @@ -116,8 +110,6 @@ def transform( turbopath(__file__).parent + "/niftyreg_scripts/reg_resample", ) - # print("niftyreg_executable:", niftyreg_executable) - input_params = [ turbopath(niftyreg_executable), turbopath(fixed_image), @@ -125,96 +117,11 @@ def transform( turbopath(transformed_image), turbopath(matrix), ] - print("Input Params:", input_params) # Call the run method to execute the script and capture the output in the log file success, error = runner.run(input_params) - -def run_bash_script_in_subprocess_and_log(): - pass - - -# TODO consider removing this legacy function -def niftyreg_caller( - fixed_image, - moving_image, - transformed_image, - matrix, - log_file, - mode, -): - """calls niftyreg for registration and transforms""" - - the_shell = "/bin/bash" - registration_abspath = os.path.dirname(os.path.abspath(__file__)) - - if mode == "registration": - shell_script = os.path.join( - registration_abspath, "niftyreg_scripts", "rigid_reg.sh" - ) - elif mode == "transformation": - shell_script = os.path.join( - registration_abspath, "niftyreg_scripts", "transform.sh" - ) - else: - raise NotImplementedError("this mode is not implemented:", mode) - - # let's try to call it - try: - starttime = str(datetime.datetime.now()) - print("** starting: " + moving_image.name + " at: " + starttime) - t = Timer() # TicToc("name") - t.start() - # your code ... - # first we create the output dir - # os.makedirs(output_dir, exist_ok=True) - - # generate subprocess call - readableCmd = ( - the_shell, - shell_script, - fixed_image, - moving_image, - transformed_image, - matrix, - ) - readableCmd = " ".join(readableCmd) - print(readableCmd) - command = shlex.split(readableCmd) - print(command) - - # cwd = pathlib.Path(__file__).resolve().parent - cwd = registration_abspath - print("*** cwd:", cwd) - - with open(log_file, "w") as outfile: - subprocess.run( - command, - stdout=outfile, - stderr=outfile, - cwd=cwd, - ) - - endtime = str(datetime.datetime.now().time()) - - elapsed = t.stop("call") - print(elapsed) - - with open(log_file, "a") as file: - file.write("\n" + "************************************************" + "\n") - file.write("cwd: " + str(cwd) + "\n") - file.write("CALL: " + readableCmd + "\n") - file.write("************************************************" + "\n") - file.write("************************************************" + "\n") - file.write("start time: " + starttime + "\n") - file.write("end time: " + endtime + "\n") - file.write("time elapsed: " + str(int(elapsed) / 60) + " minutes" + "\n") - file.write("************************************************" + "\n") - - except Exception as e: - print("error: " + str(e)) - print("registration error for: " + moving_image.name) - - endtime = str(datetime.datetime.now()) - print("** finished: " + moving_image.name + " at: " + endtime) + # if success: + # print("Script executed successfully. Check the log file for details.") + # else: + # print("Script execution failed:", error) diff --git a/example_modality_centric.py b/example_modality_centric.py index a711bed..3d59c8e 100644 --- a/example_modality_centric.py +++ b/example_modality_centric.py @@ -33,10 +33,10 @@ def preprocess(inputDir): flair_file = btk_raw_dir.files("*fla.nii.gz") if len(t1_file) == len(t1c_file) == len(t2_file) == len(flair_file) == 1: - print(t1_file) - print(t1c_file) - print(t2_file) - print(flair_file) + # print(t1_file) + # print(t1c_file) + # print(t2_file) + # print(flair_file) t1File = t1_file[0] t1cFile = t1c_file[0] @@ -107,5 +107,5 @@ def preprocess(inputDir): exams = EXAMPLE_DATA_DIR.dirs() for exam in tqdm(exams): - print(exam) + print("processing:", exam) preprocess(exam) diff --git a/pyproject.toml b/pyproject.toml index 3343c66..028a569 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ enable = true [tool.poetry] name = "brainles_preprocessing" -version = "0.0.0" # will be overwritten by poetry-dynamic-versioning but needs to be set +version = "0.0.0" # will be overwritten by poetry-dynamic-versioning but needs to be set description = "TODO." license = "AGPL-3.0" @@ -27,11 +27,17 @@ readme = "README.md" repository = "https://github.com/BrainLesion/preprocessing" #documentation = "" -keywords = ["brain tumor", "glioma", "BraTS", "skullstripping", "brain extraction"] +keywords = [ + "brain tumor", + "glioma", + "BraTS", + "skullstripping", + "brain extraction", +] classifiers = [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Affero General Public License v3", - "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", ] @@ -49,7 +55,7 @@ BrainLes-HD-BET = ">=0.0.5" # utils tqdm = "^4.64.1" -auxiliary = "^0.0.35" +auxiliary = "^0.0.37" rich = "^13.6.0" [tool.poetry.dev-dependencies]