From 373d342917fee11f0914c3c155253087b78fe8a0 Mon Sep 17 00:00:00 2001 From: AliceJoubert Date: Thu, 28 Nov 2024 17:41:14 +0100 Subject: [PATCH] Testing - 2811 --- clinica/iotools/bids_utils.py | 1 - .../converters/aibl_to_bids/utils/clinical.py | 3 +- test/unittests/iotools/test_bids_utils.py | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/clinica/iotools/bids_utils.py b/clinica/iotools/bids_utils.py index bebb52d04..f9e19e814 100644 --- a/clinica/iotools/bids_utils.py +++ b/clinica/iotools/bids_utils.py @@ -557,7 +557,6 @@ def write_modality_agnostic_files( _write_bidsignore(bids_dir) -# todo : test + open issue for usability across converters (though may not be useful if json from dicom) def _get_pet_tracer_from_filename(filename: str) -> Tracer: """Return the PET tracer from the provided filename. diff --git a/clinica/iotools/converters/aibl_to_bids/utils/clinical.py b/clinica/iotools/converters/aibl_to_bids/utils/clinical.py index 53873ea87..e826fb1c9 100644 --- a/clinica/iotools/converters/aibl_to_bids/utils/clinical.py +++ b/clinica/iotools/converters/aibl_to_bids/utils/clinical.py @@ -512,12 +512,13 @@ def write_scans_tsv(bids_dir: Path, scans_dict: dict) -> None: supported_modalities = ("anat", "dwi", "func", "pet") + # todo : what happens now is if it is not a recognized modality it will still write something... not worth it + for sub in scans_dict.keys(): for session in scans_dict[sub].keys(): scans_df = pd.DataFrame() tsv_file = bids_dir / sub / session / f"{sub}_{session}_scans.tsv" tsv_file.unlink(missing_ok=True) - for mod in (bids_dir / sub / session).glob("*"): if mod.name in supported_modalities: for file in [ diff --git a/test/unittests/iotools/test_bids_utils.py b/test/unittests/iotools/test_bids_utils.py index c014dbc7e..8a307af27 100644 --- a/test/unittests/iotools/test_bids_utils.py +++ b/test/unittests/iotools/test_bids_utils.py @@ -8,10 +8,12 @@ from clinica.iotools.bids_utils import ( StudyName, + _get_pet_tracer_from_filename, _write_bids_validator_config, _write_bidsignore, _write_readme, ) +from clinica.utils.pet import Tracer MODALITY_AGNOSTIC_FILE_WRITERS = { # "readme": _write_readme, @@ -41,6 +43,37 @@ ) +@pytest.mark.parametrize( + "filename, expected", + [ + ("sub-1_ses-1_trc-18FFDG_pet.nii.gz", Tracer.FDG), + ("sub-1_ses-1_acq-18FFDG_pet.nii.gz", Tracer.FDG), + ("sub-1_ses-1_trc-18FFDG_acq-18FFDG_pet.nii.gz", Tracer.FDG), + ("sub-1_ses-1_trc-11CPIB_pet.nii.gz", Tracer.PIB), + ("sub-1_ses-1_trc-18FFBB_pet.nii.gz", Tracer.FBB), + ("sub-1_ses-1_trc-18FFMM_pet.nii.gz", Tracer.FMM), + ("sub-1_ses-1_trc-18FAV1451_pet.nii.gz", Tracer.AV1451), + ("sub-1_ses-1_trc-18FAV45_pet.nii.gz", Tracer.AV45), + ], +) +def test_get_pet_tracer_from_filename_success(filename, expected): + assert expected == _get_pet_tracer_from_filename(filename) + + +@pytest.mark.parametrize( + "filename", + [ + "sub-1_ses-1_trc18FFDG_pet.nii.gz", + "sub-1_ses-1_trc-///_pet.nii.gz", + "sub-1_ses-1_trc-foo_pet.nii.gz", + "sub-1_ses-1_pet.nii.gz", + ], +) +def test_get_pet_tracer_from_filename_error(filename): + with pytest.raises(ValueError): + _get_pet_tracer_from_filename(filename) + + @pytest.mark.parametrize( "study,study_id,expected", [