Skip to content

Commit

Permalink
Finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceJoubert committed Dec 3, 2024
1 parent 373d342 commit 0b6e4fc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
6 changes: 2 additions & 4 deletions clinica/iotools/converters/aibl_to_bids/utils/clinical.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ 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()
Expand All @@ -534,5 +532,5 @@ def write_scans_tsv(bids_dir: Path, scans_dict: dict) -> None:
)
row_to_append.insert(0, "filename", f"{mod.name} / {file.name}")
scans_df = pd.concat([scans_df, row_to_append])
scans_df = scans_df.fillna("n/a")
scans_df.to_csv(tsv_file, sep="\t", encoding="utf8", index=False)
scans_df = scans_df.fillna("n/a")
scans_df.to_csv(tsv_file, sep="\t", encoding="utf8", index=False)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
def build_bids_dir(tmp_path: Path) -> Path:
bids_dir = tmp_path / "BIDS"
bids_dir.mkdir()
(bids_dir / "sub-AIBL1" / "ses-M000").mkdir(parents=True)
(bids_dir / "sub-AIBL1" / "ses-M000" / "anat").mkdir(parents=True)
(
bids_dir / "sub-AIBL1" / "ses-M000" / "anat" / "sub-AIBL1_ses-M000_T1w.nii.gz"
).touch()
(bids_dir / "sub-AIBL100" / "ses-M000").mkdir(parents=True)
(bids_dir / "sub-AIBL100" / "ses-M012").mkdir(parents=True)
(bids_dir / "sub-AIBL109" / "ses-M000").mkdir(parents=True)
Expand Down Expand Up @@ -694,3 +697,38 @@ def test_create_scans_dict(tmp_path):
}

assert result == expected


def test_write_scans_tsv(tmp_path):
from clinica.iotools.converters.aibl_to_bids.utils.clinical import write_scans_tsv
from clinica.utils.pet import Tracer

scans_dict = {
"sub-AIBL1": {
"ses-M000": {
"T1/DWI/fMRI/FMAP": {"acq_time": "2001-01-01T00:00:00"},
Tracer.PIB: {"acq_time": "n/a"},
Tracer.AV45: {"acq_time": "n/a"},
Tracer.FMM: {"acq_time": "n/a"},
}
}
}

bids_dir = build_bids_dir(tmp_path)

write_scans_tsv(bids_dir, scans_dict)

result_list = list(bids_dir.rglob("*sub-AIBL1_ses-M000_scans.tsv"))

assert len(result_list) == 1

result = pd.read_csv(result_list[0], sep="\t")
expected = pd.DataFrame(
{
"filename": "anat / sub-AIBL1_ses-M000_T1w.nii.gz",
"acq_time": "2001-01-01T00:00:00",
},
index=[0],
)

assert_frame_equal(result, expected)

0 comments on commit 0b6e4fc

Please sign in to comment.