From 68364a5a8a46d4cfede2ff357e1f3d262ccc30e5 Mon Sep 17 00:00:00 2001 From: Gensollen Date: Tue, 9 Jul 2024 08:00:05 +0200 Subject: [PATCH] [REF] Move `PETLinear` pipeline to new `clinica.pipelines.pet` module (#1224) * move PETLinear pipeline to new pet module * update tests * remove unused crop_nifti_image --- clinica/pipelines/__init__.py | 2 +- clinica/pipelines/pet/__init__.py | 1 + clinica/pipelines/pet/linear/__init__.py | 1 + .../pet_linear_cli.py => pet/linear/cli.py} | 2 +- .../{pet_linear => pet/linear}/info.json | 2 +- .../linear/pipeline.py} | 49 +++--- clinica/pipelines/pet/linear/tasks.py | 55 ++++++ .../linear/utils.py} | 161 +++++++++--------- clinica/pipelines/pet_linear/__init__.py | 1 - clinica/pydra/pet_linear/tasks.py | 10 +- .../test_instantiate_all_pipelines.py | 2 +- .../pipelines/pet/test_pet_linear.py | 2 +- .../pet_linear/test_pet_linear_utils.py | 22 +-- 13 files changed, 188 insertions(+), 122 deletions(-) create mode 100644 clinica/pipelines/pet/linear/__init__.py rename clinica/pipelines/{pet_linear/pet_linear_cli.py => pet/linear/cli.py} (98%) rename clinica/pipelines/{pet_linear => pet/linear}/info.json (99%) rename clinica/pipelines/{pet_linear/pet_linear_pipeline.py => pet/linear/pipeline.py} (92%) create mode 100644 clinica/pipelines/pet/linear/tasks.py rename clinica/pipelines/{pet_linear/pet_linear_utils.py => pet/linear/utils.py} (61%) delete mode 100644 clinica/pipelines/pet_linear/__init__.py diff --git a/clinica/pipelines/__init__.py b/clinica/pipelines/__init__.py index 9df226c68..e91255c20 100644 --- a/clinica/pipelines/__init__.py +++ b/clinica/pipelines/__init__.py @@ -4,7 +4,7 @@ dwi, machine_learning, machine_learning_spatial_svm, - pet_linear, + pet, pet_surface, pet_volume, statistics_surface, diff --git a/clinica/pipelines/pet/__init__.py b/clinica/pipelines/pet/__init__.py index e69de29bb..40739c042 100644 --- a/clinica/pipelines/pet/__init__.py +++ b/clinica/pipelines/pet/__init__.py @@ -0,0 +1 @@ +from . import linear diff --git a/clinica/pipelines/pet/linear/__init__.py b/clinica/pipelines/pet/linear/__init__.py new file mode 100644 index 000000000..f00831fce --- /dev/null +++ b/clinica/pipelines/pet/linear/__init__.py @@ -0,0 +1 @@ +from . import cli diff --git a/clinica/pipelines/pet_linear/pet_linear_cli.py b/clinica/pipelines/pet/linear/cli.py similarity index 98% rename from clinica/pipelines/pet_linear/pet_linear_cli.py rename to clinica/pipelines/pet/linear/cli.py index 5ed9b9671..cb7d8a7dd 100644 --- a/clinica/pipelines/pet_linear/pet_linear_cli.py +++ b/clinica/pipelines/pet/linear/cli.py @@ -63,7 +63,7 @@ def cli( from clinica.utils.ux import print_end_pipeline - from .pet_linear_pipeline import PETLinear + from .pipeline import PETLinear parameters = { "acq_label": acq_label, diff --git a/clinica/pipelines/pet_linear/info.json b/clinica/pipelines/pet/linear/info.json similarity index 99% rename from clinica/pipelines/pet_linear/info.json rename to clinica/pipelines/pet/linear/info.json index f7928412e..3161d5946 100644 --- a/clinica/pipelines/pet_linear/info.json +++ b/clinica/pipelines/pet/linear/info.json @@ -11,4 +11,4 @@ "version": ">=2.2.0" } ] -} \ No newline at end of file +} diff --git a/clinica/pipelines/pet_linear/pet_linear_pipeline.py b/clinica/pipelines/pet/linear/pipeline.py similarity index 92% rename from clinica/pipelines/pet_linear/pet_linear_pipeline.py rename to clinica/pipelines/pet/linear/pipeline.py index 82962d58d..e94e92448 100644 --- a/clinica/pipelines/pet_linear/pet_linear_pipeline.py +++ b/clinica/pipelines/pet/linear/pipeline.py @@ -144,16 +144,16 @@ def _build_output_node(self): from clinica.utils.nipype import container_from_filename, fix_join - from .pet_linear_utils import rename_into_caps + from .tasks import rename_into_caps_task write_node = npe.Node(name="WriteCaps", interface=DataSink()) write_node.inputs.base_directory = str(self.caps_directory) write_node.inputs.parameterization = False rename_file_node_inputs = [ - "pet_filename_bids", - "pet_filename_raw", - "transformation_filename_raw", + "pet_bids_image_filename", + "pet_preprocessed_image_filename", + "pet_to_mri_transformation_filename", "suvr_reference_region", "uncropped_image", ] @@ -167,7 +167,7 @@ def _build_output_node(self): "transformation_filename_caps", "pet_filename_in_t1w_caps", ], - function=rename_into_caps, + function=rename_into_caps_task, ), name="renameFileCAPS", ) @@ -193,11 +193,11 @@ def _build_output_node(self): write_node, [(("container", fix_join, "pet_linear"), "container")], ), - (self.input_node, rename_files, [("pet", "pet_filename_bids")]), + (self.input_node, rename_files, [("pet", "pet_bids_image_filename")]), ( self.output_node, rename_files, - [("affine_mat", "transformation_filename_raw")], + [("affine_mat", "pet_to_mri_transformation_filename")], ), ( rename_files, @@ -212,7 +212,7 @@ def _build_output_node(self): ( self.output_node, rename_files, - [("outfile_crop", "pet_filename_raw")], + [("outfile_crop", "pet_preprocessed_image_filename")], ), ( rename_files, @@ -227,7 +227,7 @@ def _build_output_node(self): ( self.output_node, rename_files, - [("suvr_pet", "pet_filename_raw")], + [("suvr_pet", "pet_preprocessed_image_filename")], ), ( rename_files, @@ -258,15 +258,16 @@ def _build_core_nodes(self): import nipype.pipeline.engine as npe from nipype.interfaces import ants - import clinica.pipelines.pet_linear.pet_linear_utils as utils from clinica.pipelines.tasks import crop_nifti_task - # Utilitary nodes + from .tasks import perform_suvr_normalization_task + from .utils import concatenate_transforms, init_input_node, print_end_pipeline + init_node = npe.Node( interface=nutil.Function( input_names=["pet"], output_names=["pet"], - function=utils.init_input_node, + function=init_input_node, ), name="initPipeline", ) @@ -274,7 +275,7 @@ def _build_core_nodes(self): interface=nutil.Function( input_names=["pet_to_t1w_transform", "t1w_to_mni_transform"], output_names=["transforms_list"], - function=utils.concatenate_transforms, + function=concatenate_transforms, ), name="concatenateTransforms", ) @@ -330,12 +331,16 @@ def _build_core_nodes(self): normalize_intensity_node = npe.Node( name="intensityNormalization", interface=nutil.Function( - function=utils.suvr_normalization, - input_names=["input_img", "norm_img", "ref_mask"], + function=perform_suvr_normalization_task, + input_names=[ + "pet_image_path", + "normalizing_image_path", + "reference_mask_path", + ], output_names=["output_img"], ), ) - normalize_intensity_node.inputs.ref_mask = self.ref_mask + normalize_intensity_node.inputs.reference_mask_path = self.ref_mask # 4. Crop image (using nifti). It uses custom interface, from utils file crop_nifti_node = npe.Node( @@ -343,7 +348,7 @@ def _build_core_nodes(self): interface=nutil.Function( function=crop_nifti_task, input_names=["input_image", "output_path"], - output_names=["output_img"], + output_names=["output_image"], ), ) crop_nifti_node.inputs.output_path = self.base_dir @@ -351,7 +356,7 @@ def _build_core_nodes(self): # 5. Print end message print_end_message = npe.Node( interface=nutil.Function( - input_names=["pet", "final_file"], function=utils.print_end_pipeline + input_names=["pet", "final_file"], function=print_end_pipeline ), name="WriteEndMessage", ) @@ -404,12 +409,12 @@ def _build_core_nodes(self): ( ants_applytransform_node, normalize_intensity_node, - [("output_image", "input_img")], + [("output_image", "pet_image_path")], ), ( ants_applytransform_nonlinear_node, normalize_intensity_node, - [("output_image", "norm_img")], + [("output_image", "normalizing_image_path")], ), # Connect to DataSink ( @@ -437,12 +442,12 @@ def _build_core_nodes(self): ( crop_nifti_node, self.output_node, - [("output_img", "outfile_crop")], + [("output_image", "outfile_crop")], ), ( crop_nifti_node, print_end_message, - [("output_img", "final_file")], + [("output_image", "final_file")], ), ] ) diff --git a/clinica/pipelines/pet/linear/tasks.py b/clinica/pipelines/pet/linear/tasks.py new file mode 100644 index 000000000..0a799faec --- /dev/null +++ b/clinica/pipelines/pet/linear/tasks.py @@ -0,0 +1,55 @@ +def perform_suvr_normalization_task( + pet_image_path: str, + normalizing_image_path: str, + reference_mask_path: str, +) -> str: + from pathlib import Path + + from clinica.pipelines.pet.linear.utils import perform_suvr_normalization + + return str( + perform_suvr_normalization( + Path(pet_image_path), + Path(normalizing_image_path), + Path(reference_mask_path), + ) + ) + + +def rename_into_caps_task( + pet_bids_image_filename: str, + pet_preprocessed_image_filename: str, + pet_to_mri_transformation_filename: str, + suvr_reference_region: str, + uncropped_image: bool, + pet_filename_in_t1w_raw: str = None, + output_dir: str = None, +) -> tuple: + from pathlib import Path + + from clinica.pipelines.pet.linear.utils import rename_into_caps + + if pet_filename_in_t1w_raw: + pet_filename_in_t1w_raw = Path(pet_filename_in_t1w_raw) + if output_dir: + output_dir = Path(output_dir) + ( + pet_filename_caps, + transformation_filename_caps, + pet_filename_in_t1w_caps, + ) = rename_into_caps( + Path(pet_bids_image_filename), + Path(pet_preprocessed_image_filename), + Path(pet_to_mri_transformation_filename), + suvr_reference_region, + uncropped_image, + pet_filename_in_t1w_raw, + output_dir, + ) + if pet_filename_in_t1w_caps: + pet_filename_in_t1w_caps = str(pet_filename_in_t1w_caps) + return ( + str(pet_filename_caps), + str(transformation_filename_caps), + pet_filename_in_t1w_caps, + ) diff --git a/clinica/pipelines/pet_linear/pet_linear_utils.py b/clinica/pipelines/pet/linear/utils.py similarity index 61% rename from clinica/pipelines/pet_linear/pet_linear_utils.py rename to clinica/pipelines/pet/linear/utils.py index ddd65dbca..2a08ae9d5 100644 --- a/clinica/pipelines/pet_linear/pet_linear_utils.py +++ b/clinica/pipelines/pet/linear/utils.py @@ -1,13 +1,22 @@ -# Functions used by nipype interface. +from pathlib import Path +from typing import Optional, Tuple, Union + from clinica.utils.pet import SUVRReferenceRegion +_all__ = [ + "init_input_node", + "concatenate_transforms", + "perform_suvr_normalization", + "rename_into_caps", + "print_end_pipeline", +] + -def init_input_node(pet): +def init_input_node(pet: str) -> str: """Initiate the pipeline.""" from clinica.utils.filemanip import get_subject_id from clinica.utils.ux import print_begin_image - # Extract image ID image_id = get_subject_id(pet) print_begin_image(image_id) return pet @@ -34,81 +43,80 @@ def concatenate_transforms( return [t1w_to_mni_transform, pet_to_t1w_transform] -# Normalize the images based on the reference mask region -def suvr_normalization( - input_img: str, - norm_img: str, - ref_mask: str, -) -> str: +def perform_suvr_normalization( + pet_image_path: Path, + normalizing_image_path: Path, + reference_mask_path: Path, +) -> Path: """Normalize the input image according to the reference region. It uses nilearn `resample_to_img` and scipy `trim_mean` functions. This function is different than the one in other PET pipelines - because there is a downsampling step. + because there is a down-sampling step. Parameters ---------- - input_img : str - Path to the image to be processed. + pet_image_path : Path + The path to the image to be processed. - norm_img : str - Path to the image used to compute the mean of the reference region. + normalizing_image_path : Path + The path to the image used to compute the mean of the reference region. - ref_mask : str - Path to the mask of the reference region. + reference_mask_path : Path + The path to the mask of the reference region. Returns ------- - output_img : str - Path to the normalized nifti image. + output_img : Path + The path to the normalized nifti image. """ - import os - import nibabel as nib import numpy as np from nilearn.image import resample_to_img from scipy.stats import trim_mean - pet = nib.load(input_img) - norm = nib.load(norm_img) - mask = nib.load(ref_mask) + from clinica.utils.filemanip import get_filename_no_ext + from clinica.utils.stream import cprint - # Downsample the pet image used for normalization so we can multiply it with the mask - ds_img = resample_to_img(norm, mask, interpolation="nearest") + pet_image = nib.load(pet_image_path) + normalizing_image = nib.load(normalizing_image_path) + reference_mask = nib.load(reference_mask_path) + + # Down-sample the pet image used for normalization so we can multiply it with the mask + down_sampled_image = resample_to_img( + normalizing_image, reference_mask, interpolation="nearest" + ) # Compute the mean of the region - region = np.multiply(ds_img.get_fdata(), mask.get_fdata(dtype="float32")) + region = np.multiply( + down_sampled_image.get_fdata(), reference_mask.get_fdata(dtype="float32") + ) array_region = np.where(region != 0, region, np.nan).flatten() region_mean = trim_mean(array_region[~np.isnan(array_region)], 0.1) - - from clinica.utils.stream import cprint - - cprint(region_mean) + cprint(region_mean, lvl="info") # Divide the value of the image voxels by the computed mean - data = pet.get_fdata(dtype="float32") / region_mean + data = pet_image.get_fdata(dtype="float32") / region_mean # Create and save the normalized image - output_img = os.path.join( - os.getcwd(), - os.path.basename(input_img).split(".nii")[0] + "_suvr_normalized.nii.gz", + output_image = ( + Path.cwd() / f"{get_filename_no_ext(pet_image_path)}_suvr_normalized.nii.gz" ) + normalized_img = nib.Nifti1Image(data, pet_image.affine, header=pet_image.header) + normalized_img.to_filename(output_image) - normalized_img = nib.Nifti1Image(data, pet.affine, header=pet.header) - normalized_img.to_filename(output_img) - - return output_img + return output_image def rename_into_caps( - pet_filename_bids: str, - pet_filename_raw: str, - transformation_filename_raw: str, - suvr_reference_region: str, + pet_bids_image_filename: Path, + pet_preprocessed_image_filename: Path, + pet_to_mri_transformation_filename: Path, + suvr_reference_region: Union[str, SUVRReferenceRegion], uncropped_image: bool, - pet_filename_in_t1w_raw: str = None, - output_dir: str = None, -): + pet_filename_in_t1w_raw: Optional[Path] = None, + output_dir: Optional[Path] = None, +) -> Tuple[Path, Path, Optional[Path]]: """ Rename the outputs of the pipelines into CAPS format. @@ -120,18 +128,18 @@ def rename_into_caps( Parameters ---------- - pet_filename_bids : str + pet_bids_image_filename : Path Input PET image file from the BIDS dataset. This file is used to extract the entities from the source file like subject, session, run, tracer... - pet_filename_raw : str + pet_preprocessed_image_filename : Path Preprocessed PET file as outputted by Nipype. - transformation_filename_raw : str + pet_to_mri_transformation_filename : Path Transformation file from PET to MRI space as outputted by Nipype. - suvr_reference_region : str + suvr_reference_region : str or SUVRReferenceRegion SUVR mask name for file name output. This will be used to derive the prefix of the PET image. @@ -153,35 +161,29 @@ def rename_into_caps( Returns ------- - pet_filename_caps : str + pet_filename_caps : Path The renamed preprocessed PET file to match CAPS conventions. - transformation_filename_caps : str + transformation_filename_caps : Path The transformation file from PET to MRI space renamed to match CAPS conventions. - pet_filename_in_t1w_caps : str or None + pet_filename_in_t1w_caps : Path or None Intermediate PET in T1w MRI space renamed to match CAPS conventions. If 'pet_filename_in_t1w_raw' is None, this will be None. """ - import os - - from clinica.pipelines.pet_linear.pet_linear_utils import ( # noqa - _get_bids_entities_without_suffix, - _rename_intermediate_pet_in_t1w_space_into_caps, - _rename_pet_into_caps, - _rename_transformation_into_caps, + bids_entities = _get_bids_entities_without_suffix( + pet_bids_image_filename, suffix="pet" ) - from clinica.utils.pet import SUVRReferenceRegion - - suvr_reference_region = SUVRReferenceRegion(suvr_reference_region) - bids_entities = _get_bids_entities_without_suffix(pet_filename_bids, suffix="pet") if output_dir: - bids_entities = os.path.join(output_dir, bids_entities) + bids_entities = str(output_dir / bids_entities) pet_filename_caps = _rename_pet_into_caps( - bids_entities, pet_filename_raw, not uncropped_image, suvr_reference_region + bids_entities, + pet_preprocessed_image_filename, + not uncropped_image, + SUVRReferenceRegion(suvr_reference_region), ) transformation_filename_caps = _rename_transformation_into_caps( - bids_entities, transformation_filename_raw + bids_entities, pet_to_mri_transformation_filename ) pet_filename_in_t1w_caps = None if pet_filename_in_t1w_raw is not None: @@ -192,42 +194,41 @@ def rename_into_caps( return pet_filename_caps, transformation_filename_caps, pet_filename_in_t1w_caps -def _get_bids_entities_without_suffix(filename: str, suffix: str) -> str: +def _get_bids_entities_without_suffix(filename: Path, suffix: str) -> str: """Return the BIDS entities without the suffix from a BIDS path.""" - from nipype.utils.filemanip import split_filename + from clinica.utils.filemanip import get_filename_no_ext - _, stem, _ = split_filename(filename) - return stem.rstrip(f"_{suffix}") + return get_filename_no_ext(filename).rstrip(f"_{suffix}") def _rename_pet_into_caps( - entities: str, filename: str, cropped: bool, region: SUVRReferenceRegion -) -> str: + entities: str, filename: Path, cropped: bool, region: SUVRReferenceRegion +) -> Path: """Rename into CAPS PET.""" return _rename(filename, entities, _get_pet_bids_components(cropped, region)) -def _rename_transformation_into_caps(entities: str, filename: str) -> str: +def _rename_transformation_into_caps(entities: str, filename: Path) -> Path: """Rename into CAPS transformation file.""" return _rename(filename, entities, "_space-T1w_rigid.mat") def _rename_intermediate_pet_in_t1w_space_into_caps( - entities: str, filename: str -) -> str: + entities: str, filename: Path +) -> Path: """Rename intermediate PET in T1w MRI space.""" return _rename(filename, entities, "_space-T1w_pet.nii.gz") -def _rename(filename: str, entities: str, suffix: str): +def _rename(filename: Path, entities: str, suffix: str) -> Path: """Rename 'filename' into '{entities}{suffix}'.""" from nipype.interfaces.utility import Rename rename = Rename() - rename.inputs.in_file = filename - rename.inputs.format_string = entities + suffix + rename.inputs.in_file = str(filename) + rename.inputs.format_string = f"{entities}{suffix}" - return rename.run().outputs.out_file + return Path(rename.run().outputs.out_file) def _get_pet_bids_components(cropped: bool, region: SUVRReferenceRegion) -> str: @@ -242,7 +243,7 @@ def _get_pet_bids_components(cropped: bool, region: SUVRReferenceRegion) -> str: return f"{space}{desc}{resolution}{suvr}_pet.nii.gz" -def print_end_pipeline(pet, final_file): +def print_end_pipeline(pet: str, final_file): """ Display end message for when is connected. """ diff --git a/clinica/pipelines/pet_linear/__init__.py b/clinica/pipelines/pet_linear/__init__.py deleted file mode 100644 index a65f1196f..000000000 --- a/clinica/pipelines/pet_linear/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import pet_linear_cli diff --git a/clinica/pydra/pet_linear/tasks.py b/clinica/pydra/pet_linear/tasks.py index d972e725d..855063b67 100644 --- a/clinica/pydra/pet_linear/tasks.py +++ b/clinica/pydra/pet_linear/tasks.py @@ -16,7 +16,7 @@ def concatenate_transforms_task( `clinica.pipelines.pet_linear.pet_linear_utils.concatenate_transforms`. """ - from clinica.pipelines.pet_linear.pet_linear_utils import concatenate_transforms + from clinica.pipelines.pet.linear.utils import concatenate_transforms return concatenate_transforms(t1w_to_mni_tranform, pet_to_t1w_tranform) @@ -35,9 +35,13 @@ def suvr_normalization_task( `clinica.pipelines.pet_linear.pet_linear_utils.suvr_normalization`. """ - from clinica.pipelines.pet_linear.pet_linear_utils import suvr_normalization + from pathlib import Path + + from clinica.pipelines.pet.linear.utils import perform_suvr_normalization - return suvr_normalization(input_img, norm_img, ref_mask) + return str( + perform_suvr_normalization(Path(input_img), Path(norm_img), Path(ref_mask)) + ) @task diff --git a/test/instantiation/test_instantiate_all_pipelines.py b/test/instantiation/test_instantiate_all_pipelines.py index 5dae34b6c..b66dd1372 100644 --- a/test/instantiation/test_instantiate_all_pipelines.py +++ b/test/instantiation/test_instantiate_all_pipelines.py @@ -209,7 +209,7 @@ def run_pet_volume(input_dir: Path) -> None: def test_instantiate_pet_linear(cmdopt): - from clinica.pipelines.pet_linear.pet_linear_pipeline import PETLinear + from clinica.pipelines.pet.linear.pipeline import PETLinear from clinica.utils.pet import SUVRReferenceRegion, Tracer input_dir = Path(cmdopt["input"]) diff --git a/test/nonregression/pipelines/pet/test_pet_linear.py b/test/nonregression/pipelines/pet/test_pet_linear.py index 2d783aeb1..e7aa81180 100644 --- a/test/nonregression/pipelines/pet/test_pet_linear.py +++ b/test/nonregression/pipelines/pet/test_pet_linear.py @@ -16,7 +16,7 @@ def test_pet_linear(cmdopt, tmp_path): def run_pet_linear( input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path ) -> None: - from clinica.pipelines.pet_linear.pet_linear_pipeline import PETLinear + from clinica.pipelines.pet.linear.pipeline import PETLinear shutil.copytree(input_dir / "caps", output_dir / "caps", copy_function=shutil.copy) diff --git a/test/unittests/pipelines/pet_linear/test_pet_linear_utils.py b/test/unittests/pipelines/pet_linear/test_pet_linear_utils.py index 0874e528b..5e2ddca06 100644 --- a/test/unittests/pipelines/pet_linear/test_pet_linear_utils.py +++ b/test/unittests/pipelines/pet_linear/test_pet_linear_utils.py @@ -21,13 +21,13 @@ ], ) def test_get_pet_bids_components(cropped, suvr_reference_region, expected): - from clinica.pipelines.pet_linear.pet_linear_utils import _get_pet_bids_components + from clinica.pipelines.pet.linear.utils import _get_pet_bids_components assert _get_pet_bids_components(cropped, suvr_reference_region) == expected def test_rename(tmp_path): - from clinica.pipelines.pet_linear.pet_linear_utils import _rename + from clinica.pipelines.pet.linear.utils import _rename file_to_rename = tmp_path / "foo.nii.gz" file_to_rename.touch() @@ -35,16 +35,16 @@ def test_rename(tmp_path): source_file.touch() output_file = _rename( - str(file_to_rename), str(tmp_path / "sub-01_ses-M000_run-01"), "_pet.nii.gz" + file_to_rename, str(tmp_path / "sub-01_ses-M000_run-01"), "_pet.nii.gz" ) assert file_to_rename.exists() assert source_file.exists() - assert Path(output_file) == tmp_path / "sub-01_ses-M000_run-01_pet.nii.gz" - assert Path(output_file).exists() + assert output_file == tmp_path / "sub-01_ses-M000_run-01_pet.nii.gz" + assert output_file.exists() def test_rename_into_caps(tmp_path): - from clinica.pipelines.pet_linear.pet_linear_utils import rename_into_caps + from clinica.pipelines.pet.linear.utils import rename_into_caps pet_file_to_rename = tmp_path / "foobarbaz.nii.gz" pet_file_to_rename.touch() @@ -53,17 +53,17 @@ def test_rename_into_caps(tmp_path): source_file = tmp_path / "sub-01_ses-M000_run-01_pet.nii.gz" source_file.touch() a, b, c = rename_into_caps( - str(source_file), - str(pet_file_to_rename), - str(transformation_file_to_rename), + source_file, + pet_file_to_rename, + transformation_file_to_rename, SUVRReferenceRegion.PONS, True, output_dir=tmp_path, # Force the writing to tmp_path instead of current folder... ) assert ( - Path(a) + a == tmp_path / "sub-01_ses-M000_run-01_space-MNI152NLin2009cSym_res-1x1x1_suvr-pons_pet.nii.gz" ) - assert Path(b) == tmp_path / "sub-01_ses-M000_run-01_space-T1w_rigid.mat" + assert b == tmp_path / "sub-01_ses-M000_run-01_space-T1w_rigid.mat" assert c is None