Skip to content

Commit

Permalink
[TEST] Improve tests for bids_utils (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceJoubert authored Jul 1, 2024
1 parent cb8300a commit f34a302
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
2 changes: 2 additions & 0 deletions clinica/iotools/bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def write_modality_agnostic_files(
_write_bidsignore(bids_dir)


# todo : move to oasis utils ?
def write_sessions_tsv(bids_dir: Path, sessions_dict: dict) -> None:
"""Create <participant_id>_sessions.tsv files.
Expand Down Expand Up @@ -933,6 +934,7 @@ def run_dcm2niix(
return True


# todo : place in genfi utils ?
def identify_modality(filename: str) -> Optional[str]:
"""Identifies the modality of a file given its name.
Expand Down
69 changes: 20 additions & 49 deletions test/unittests/iotools/test_bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ def create_clinical_data(tmp_path: Path, study_name: StudyName) -> Path:
"oasis_cross-sectional.csv",
np.nan,
],
"OASIS3": [np.nan, "Subject", np.nan, "M/F", np.nan],
"OASIS3 location": [
np.nan,
"oasis3_participants.csv",
np.nan,
"oasis3_participants.csv",
np.nan,
],
}
)
spec_df.to_csv(tmp_path / "participant.tsv", sep="\t", index=False)
Expand Down Expand Up @@ -105,31 +97,21 @@ def create_clinical_data(tmp_path: Path, study_name: StudyName) -> Path:
)
df_adnimerge.to_csv(clinical_path / "ADNIMERGE.csv", index=False)
df_apoeres.to_csv(clinical_path / "APOERES.csv", index=False)
elif study_name == StudyName.OASIS:
if study_name == StudyName.OASIS:
df_oasis = pd.DataFrame(
{
"ID": [
"OAS1_0001_MRI1",
"OAS1_0002_MRI1",
"OAS1_0003_MRI1",
"OAS1_0004_MRI1",
"OAS1_0001_MR1",
"OAS1_0002_MR1",
"OAS1_0003_MR1",
"OAS1_0004_MR1",
"OAS1_0004_MR2",
],
"M/F": ["F", "M", "F", "M"],
"Age": ["45", "50", "55", "60"],
"M/F": ["F", "M", "F", "M", "M"],
"Age": ["45", "50", "55", "60", "60"],
}
)
df_oasis.to_csv(clinical_path / "oasis_cross-sectional.csv", index=False)

elif study_name == StudyName.OASIS3:
df_oasis3 = pd.DataFrame(
{
"Subject": ["OAS30001", "OAS30002", "OAS30003", "OAS30004"],
"M/F": ["F", "F", "M", "M"],
"Age": ["45", "55", "65", "75"],
}
)
df_oasis3.to_csv(clinical_path / "oasis3_participants.csv", index=False)

return clinical_path


Expand All @@ -138,32 +120,21 @@ def create_clinical_data(tmp_path: Path, study_name: StudyName) -> Path:
[
(
StudyName.OASIS,
["0001"],
["sub-OASIS10001"],
pd.DataFrame(
{
"participant_id": ["0001"],
"alternative_id_1": ["OAS1_0001_MRI1"],
"participant_id": ["sub-OASIS10001"],
"alternative_id_1": ["OAS1_0001_MR1"],
"sex": ["F"],
}
),
),
(
StudyName.OASIS3,
["0001"],
pd.DataFrame(
{
"participant_id": ["0001"],
"alternative_id_1": ["OAS30001"],
"sex": ["F"],
}
),
),
( # todo : introducing None or np.nan in data changes the format for scalar values
StudyName.ADNI,
["001S0001"],
["sub-ADNI001S0001"],
pd.DataFrame(
{
"participant_id": ["001S0001"],
"participant_id": ["sub-ADNI001S0001"],
"alternative_id_1": ["001_S_0001"],
"sex": ["Male"],
"apoegen1": [3.0],
Expand All @@ -172,21 +143,21 @@ def create_clinical_data(tmp_path: Path, study_name: StudyName) -> Path:
),
(
StudyName.OASIS,
["0002", "0004", "0007"],
["sub-OASIS10002", "sub-OASIS10004", "sub-OASIS10007"],
pd.DataFrame(
{
"participant_id": ["0002", "0004"],
"alternative_id_1": ["OAS1_0002_MRI1", "OAS1_0004_MRI1"],
"participant_id": ["sub-OASIS10002", "sub-OASIS10004"],
"alternative_id_1": ["OAS1_0002_MR1", "OAS1_0004_MR1"],
"sex": ["M", "M"],
}
),
),
(
StudyName.ADNI,
["001S0005"],
["sub-ADNI001S0005"],
pd.DataFrame(
{
"participant_id": ["001S0005"],
"participant_id": ["sub-ADNI001S0005"],
"alternative_id_1": ["001_S_0005"],
"sex": ["Female"],
"apoegen1": ["n/a"],
Expand All @@ -195,10 +166,10 @@ def create_clinical_data(tmp_path: Path, study_name: StudyName) -> Path:
),
(
StudyName.ADNI,
["001S0006"],
["sub-ADNI001S0006"],
pd.DataFrame(
{
"participant_id": ["001S0006"],
"participant_id": ["sub-ADNI001S0006"],
"alternative_id_1": ["001_S_0006"],
"sex": ["n/a"],
"apoegen1": [3.0],
Expand Down

0 comments on commit f34a302

Please sign in to comment.