-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONV] Implementing new converter for IXI dataset (#1239)
* wip1 * wip2 * add todos * wip2 * add dti * Fix concat img * print1 * Sessions/scans.tsv * Testing1 * Function description * Testing2 * fix * Add docstrings * Changes as suggested * add func subj_from_file * Add test func * Add participants.tsv * Fix prints * cleanup * unittesting1 * Changes according to suggestions * unittesting2 * unittesting 3 * add mapping class * more unittesting * Suggestions + testing * Finish unit tests * Add test for check_modalities * Changes according to suggestions * Change check_mod * use ClinicalDataMapping enum
- Loading branch information
1 parent
06ec7a1
commit 5d022e1
Showing
10 changed files
with
1,265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .ixi_to_bids import convert | ||
|
||
__all__ = ["convert"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""Convert IXI dataset (https://brain-development.org/ixi-dataset/) to BIDS.""" | ||
|
||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import nibabel as nb | ||
import numpy as np | ||
|
||
from clinica.iotools.bids_utils import write_modality_agnostic_files | ||
from clinica.iotools.converters.ixi_to_bids.ixi_to_bids_utils import ( | ||
check_modalities, | ||
define_participants, | ||
read_clinical_data, | ||
write_participants, | ||
write_scans, | ||
write_sessions, | ||
write_subject_data, | ||
) | ||
from clinica.utils.filemanip import UserProvidedPath | ||
|
||
__all__ = ["convert"] | ||
|
||
|
||
def convert( | ||
path_to_dataset: UserProvidedPath, | ||
bids_dir: UserProvidedPath, | ||
path_to_clinical: UserProvidedPath, | ||
subjects: Optional[UserProvidedPath] = None, | ||
n_procs: Optional[int] = 1, | ||
**kwargs, | ||
): | ||
from clinica.iotools.bids_utils import StudyName | ||
from clinica.iotools.converters.factory import get_converter_name | ||
from clinica.utils.stream import cprint | ||
|
||
from ..utils import validate_input_path | ||
|
||
path_to_dataset = validate_input_path(path_to_dataset) | ||
bids_dir = validate_input_path(bids_dir, check_exist=False) | ||
path_to_clinical = validate_input_path(path_to_clinical) | ||
if subjects: | ||
subjects = validate_input_path(subjects) | ||
|
||
if n_procs != 1: | ||
cprint( | ||
f"{get_converter_name(StudyName.IXI)} converter does not support multiprocessing yet. n_procs set to 1.", | ||
lvl="warning", | ||
) | ||
|
||
clinical_data = read_clinical_data(path_to_clinical) | ||
participants = define_participants(path_to_dataset, subjects) | ||
check_modalities(data_directory=path_to_dataset, participants=participants) | ||
|
||
write_participants( | ||
bids_dir=bids_dir, clinical_data=clinical_data, participants=participants | ||
) | ||
|
||
for participant in participants: | ||
cprint(f"Converting IXI subject {participant} to BIDS", lvl="debug") | ||
write_subject_data( | ||
bids_dir=bids_dir, participant=participant, path_to_dataset=path_to_dataset | ||
) | ||
write_sessions( | ||
bids_dir=bids_dir, participant=participant, clinical_data=clinical_data | ||
) | ||
write_scans(bids_dir=bids_dir, participant=participant) | ||
|
||
readme_data = { | ||
"link": "https://brain-development.org/ixi-dataset/", | ||
"desc": ( | ||
"IXI is the nickname for the Information eXtraction from Images project, " | ||
"which issued a dataset of nearly 600 images from healthy subjects. The MR" | ||
"acquisition protocol includes T1,T2, PD weighted, MRA and diffusion-weighted" | ||
"images. Three hospitals in London were involved in data collection." | ||
), | ||
} | ||
|
||
write_modality_agnostic_files( | ||
study_name=StudyName.IXI, readme_data=readme_data, bids_dir=bids_dir | ||
) | ||
|
||
cprint("Conversion to BIDS finished.", lvl="info") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from os import PathLike | ||
from typing import Optional | ||
|
||
import click | ||
|
||
from clinica.iotools.converters import cli_param | ||
|
||
|
||
@click.command(name="ixi-to-bids") | ||
@cli_param.dataset_directory | ||
@cli_param.bids_directory | ||
@cli_param.clinical_data_directory | ||
@cli_param.subjects_list | ||
def cli( | ||
dataset_directory: PathLike, | ||
bids_directory: PathLike, | ||
clinical_data_directory: PathLike, | ||
subjects_list: Optional[PathLike] = None, | ||
) -> None: | ||
"""IXI to BIDS converter.""" | ||
from .ixi_to_bids import convert | ||
|
||
convert(dataset_directory, bids_directory, clinical_data_directory, subjects_list) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
Oops, something went wrong.