Skip to content

Commit

Permalink
Testing - 2811
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceJoubert committed Nov 28, 2024
1 parent 8b3f0ab commit 373d342
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 0 additions & 1 deletion clinica/iotools/bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion clinica/iotools/converters/aibl_to_bids/utils/clinical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
33 changes: 33 additions & 0 deletions test/unittests/iotools/test_bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit 373d342

Please sign in to comment.