Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceJoubert committed Jul 17, 2024
1 parent 4c8c43d commit 0fc96fb
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions clinica/iotools/converters/ixi_to_bids/ixi_to_bids_utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 ?

0 comments on commit 0fc96fb

Please sign in to comment.