diff --git a/clinica/iotools/converters/ixi_to_bids/ixi_to_bids_utils.py b/clinica/iotools/converters/ixi_to_bids/ixi_to_bids_utils.py index 467e53e22..e42ecc1e7 100644 --- a/clinica/iotools/converters/ixi_to_bids/ixi_to_bids_utils.py +++ b/clinica/iotools/converters/ixi_to_bids/ixi_to_bids_utils.py @@ -1,18 +1,28 @@ # todo : verify typing compatibility with user input +import re from pathlib import Path +from typing import List import pandas as pd def get_subjects_list_from_data(data_directory: Path) -> List[str]: - img_list = list(data_directory.rglob(pattern="*.nii.gz")) - return + return list( + dict.fromkeys( + re.match(r"IXI\d{3}", path.name).group(0) + for path in data_directory.rglob(pattern="IXI*.nii.gz") + ) + ) def filter_subjects_list( subjects_list: List[str], clinical_data: pd.DataFrame ) -> List[str]: - return [subject for subject in subjects_list if subject in clinical_data["IXI_ID"]] + return [ + subject + for subject in subjects_list + if subject in clinical_data["IXI_ID"].values + ] def read_ixi_clinical_data(clinical_data_path: Path) -> pd.DataFrame: @@ -22,3 +32,22 @@ def read_ixi_clinical_data(clinical_data_path: Path) -> pd.DataFrame: lambda x: "IXI" + "0" * (3 - len(str(x))) + str(x) ) return clinical_data + + +def get_data_df(data_directory: Path) -> pd.DataFrame: + # todo : works for all except DTI !!! (I mean we should drop it after this) + df = pd.DataFrame( + {"img_path": [path for path in data_directory.rglob(pattern="IXI*.nii.gz")]} + ) + df = ( + df.assign(img_name=lambda df: df.img_path.apply(lambda x: x.name)) + .assign(img_name_no_ext=lambda df: df.img_name.apply(lambda x: x.split(".")[0])) + .assign(subject=lambda df: df.img_name_no_ext.apply(lambda x: x.split("-")[0])) + .assign(hospital=lambda df: df.img_name_no_ext.apply(lambda x: x.split("-")[1])) + .assign(modality=lambda df: df.img_name_no_ext.apply(lambda x: x.split("-")[3])) + .assign(session="ses-M000") + ) + return df + + +# todo : question DTI - sessions différentes ou images différentes ?