From 6a6d7e80593b833dc2e52d544f2746ff2b8b553c Mon Sep 17 00:00:00 2001 From: Matthieu Joulot <85217698+MatthieuJoulot@users.noreply.github.com> Date: Tue, 21 Sep 2021 18:05:15 +0200 Subject: [PATCH] Oasis3 code fetching cross-plateform (#429) * activate the oasis3tobids converter test * Change variable name in oasis3 converter for clarity * Change the creation of series for cross platform compatibility * Delete useless comments and prints * Fix file_spec_series --- .../converters/oasis3_to_bids/oasis3_utils.py | 26 ++++++++++++++++--- .../iotools/test_run_converters.py | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/clinica/iotools/converters/oasis3_to_bids/oasis3_utils.py b/clinica/iotools/converters/oasis3_to_bids/oasis3_utils.py index 2c5e72158..e9d551750 100644 --- a/clinica/iotools/converters/oasis3_to_bids/oasis3_utils.py +++ b/clinica/iotools/converters/oasis3_to_bids/oasis3_utils.py @@ -66,13 +66,31 @@ def read_clinical_data( def read_imaging_data(imaging_data_directory: PathLike) -> DataFrame: + from pathlib import Path + import pandas as pd - s = pd.Series(find_imaging_data(imaging_data_directory), name="source_path") + source_path_series = pd.Series( + find_imaging_data(imaging_data_directory), name="source_path" + ) + + source_dir_series = source_path_series.apply(lambda x: Path(str(x)).parent).rename( + "source_dir" + ) - b = s.str.rsplit(pat="/", n=1, expand=True).drop(columns=1)[0].rename("source_dir") - a = s.str.split(pat="/", n=1, expand=True).drop(columns=1)[0].rename("path") - df_source = pd.concat([s, a, b, a.str.split("_", expand=True)], axis=1) + file_spec_series = source_path_series.apply(lambda x: Path(str(x)).parts[0]).rename( + "path" + ) + + df_source = pd.concat( + [ + source_path_series, + file_spec_series, + source_dir_series, + file_spec_series.str.split("_", expand=True), + ], + axis=1, + ) df_source = df_source.rename( {0: "Subject", 1: "modality", 2: "Date"}, axis="columns" ).drop_duplicates() diff --git a/test/nonregression/iotools/test_run_converters.py b/test/nonregression/iotools/test_run_converters.py index 0bfcf32cc..bb67fb634 100644 --- a/test/nonregression/iotools/test_run_converters.py +++ b/test/nonregression/iotools/test_run_converters.py @@ -29,7 +29,7 @@ params=[ "Nifd2Bids", "Oasis2Bids", - # "Oasis3ToBids", + "Oasis3ToBids", "Adni2Bids", "Aibl2Bids", ]