-
Notifications
You must be signed in to change notification settings - Fork 88
GENFI to BIDS converter #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2103a1
2ad7720
6816b45
dc3bf18
16bded2
c5b66a8
4d55573
6607336
2ebf961
12b8eba
e73c2a5
6b0f012
7d9e673
0ea27c7
970fb64
c463913
4b8914e
a13d860
4afdfde
9290a83
91ad74f
115b109
3d1d29b
ad756cc
3878853
7c58f9f
e1411c8
47ce632
eabc029
cf08ef0
5ec3f95
8a40630
60391ca
84fcfa5
7162d75
8394825
72d4c72
879f0bf
a337588
355d891
342e2f3
d63491f
ff1a8ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Convert the GENFI dataset into BIDS.""" | ||
|
||
from os import PathLike | ||
from typing import Optional | ||
|
||
|
||
def convert_images( | ||
path_to_dataset: PathLike, | ||
bids_dir: PathLike, | ||
path_to_clinical: Optional[PathLike], | ||
gif: bool, | ||
MatthieuJoulot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> None: | ||
"""Convert the entire dataset to BIDS. | ||
|
||
Scans available files in the path_to_dataset, | ||
identifies the patients that have images described by the JSON file, | ||
converts the image with the highest quality for each category. | ||
MatthieuJoulot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Parameters | ||
---------- | ||
path_to_dataset: PathLike | ||
Path to the raw images | ||
|
||
bids_dir: PathLike | ||
Path to directory where the bids will be written | ||
|
||
path_to_clinical: PathLike, optional | ||
Path to the clinical data associated with the dataset. | ||
If None, the clinical data won't be converted. | ||
|
||
gif: bool | ||
If True, indicates the user wants to have the values of the gif parcellation | ||
""" | ||
import os | ||
|
||
import clinica.iotools.bids_utils as bids | ||
|
||
from .genfi_to_bids_utils import ( | ||
complete_clinical_data, | ||
dataset_to_bids, | ||
find_clinical_data, | ||
intersect_data, | ||
merge_imaging_data, | ||
read_imaging_data, | ||
write_bids, | ||
) | ||
|
||
# read the clinical data files | ||
if path_to_clinical: | ||
MatthieuJoulot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
df_demographics, df_imaging, df_clinical = find_clinical_data(path_to_clinical) | ||
# makes a df of the imaging data | ||
imaging_data = read_imaging_data(path_to_dataset) | ||
|
||
# complete the data extracted | ||
imaging_data = merge_imaging_data(imaging_data) | ||
|
||
# complete clinical data | ||
if path_to_clinical: | ||
df_clinical_complete = complete_clinical_data( | ||
df_demographics, df_imaging, df_clinical | ||
) | ||
|
||
# intersect the data | ||
if path_to_clinical: | ||
df_complete = intersect_data(imaging_data, df_clinical_complete) | ||
else: | ||
df_complete = imaging_data | ||
# build the tsv | ||
results = dataset_to_bids(df_complete, gif) | ||
|
||
write_bids( | ||
to=bids_dir, | ||
participants=results["participants"], | ||
sessions=results["sessions"], | ||
scans=results["scans"], | ||
) | ||
# fetch data for readme from markdown | ||
readme_path = os.path.join( | ||
os.path.dirname( | ||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) | ||
), | ||
"docs", | ||
"Converters", | ||
"GENFItoBIDS.md", | ||
) | ||
try: | ||
readme_data = { | ||
"link": bids.parse_url(readme_path)[0], | ||
"desc": bids.parse_description(readme_path, 4, 5), | ||
} | ||
except IndexError: | ||
raise ValueError("Could not parse information for dataset.") | ||
bids.write_modality_agnostic_files( | ||
study_name="GENFI", readme_data=readme_data, bids_dir=bids_dir | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from os import PathLike | ||
from typing import Optional | ||
|
||
import click | ||
|
||
from clinica.iotools.converters import cli_param | ||
|
||
clinical_data_directory = click.option( | ||
"-cdd", | ||
"--clinical-data-dir", | ||
"clinical_data_directory", | ||
type=click.Path(exists=True, file_okay=False, resolve_path=True), | ||
help="Path to the clinical data directory", | ||
) | ||
|
||
gif = click.option("-gif", is_flag=True, help="Add values from gif to session.tsv") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what I would also avoid short option flags only. Modern CLI design tends to favor long option flags by default, and long + short option flags for popular use cases. Since this option maps to a boolean variable, I'd expect something along the lines of |
||
|
||
|
||
@click.command(name="genfi-to-bids") | ||
@cli_param.dataset_directory | ||
@cli_param.bids_directory | ||
@clinical_data_directory | ||
@gif | ||
def cli( | ||
dataset_directory: PathLike, | ||
bids_directory: PathLike, | ||
clinical_data_directory: Optional[PathLike] = None, | ||
gif: bool = False, | ||
) -> None: | ||
"""GENFI to BIDS converter. | ||
|
||
Convert the imaging and clinical data of GENFI, located in DATASET_DIRECTORY and | ||
CLINICAL_DATA_DIRECTORY respectively, to a BIDS dataset in the target BIDS_DIRECTORY. | ||
""" | ||
from clinica.iotools.bids_utils import _write_bidsignore | ||
from clinica.iotools.converters.genfi_to_bids.genfi_to_bids import convert_images | ||
from clinica.utils.check_dependency import check_dcm2niix | ||
from clinica.utils.stream import cprint | ||
|
||
check_dcm2niix() | ||
|
||
convert_images(dataset_directory, bids_directory, clinical_data_directory, gif) | ||
_write_bidsignore(str(bids_directory)) | ||
|
||
cprint("Conversion to BIDS succeeded.") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
Uh oh!
There was an error while loading. Please reload this page.