aramis-lab/clinica

Improve Modality Detection in Clinica's ADNI to BIDS Converter

Closed this issue · 2 comments

Bug Description
Clinica encounters an error during the conversion of ADNI files into BIDS format. The specific error arises when attempting to convert the file sub-ADNI100S4469_ses-M066_dwi_ADC.nii.gz. The error message indicates that the conversion modality could not be determined for this file.

To Reproduce

  1. Execute the command: clinica convert adni-to-bids extracted_data/image_collections/ADNI extracted_data/study_data/ADNI-all-tabular-data bids -xml extracted_data/image_collections/ADNI/.
  2. Observe the error message similar to the provided traceback.

Expected Behavior
The conversion process should accurately identify the modality of the provided file and proceed with the conversion accordingly. Even if there are errors, it should convert the files it can and terminate with a notification about the nonconvertible files.

Traceback

Traceback (most recent call last):                                                                              
  File "/DATA/user/miniconda3/envs/clinica-stable/bin/clinica", line 8, in <module>
    sys.exit(main())
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/clinica/cmdline.py", line 92,
 in main
    cli()                                               
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 1157, in
 __call__
    return self.main(*args, **kwargs)    
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 1078, in
 main    
    rv = self.invoke(ctx)                                                                                       
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 1688, in
 invoke                                                                                                         
    return _process_result(sub_ctx.command.invoke(sub_ctx))         
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 1688, in
 invoke                                                                                                         
    return _process_result(sub_ctx.command.invoke(sub_ctx))                         
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 1434, in
 invoke                                                 
    return ctx.invoke(self.callback, **ctx.params)
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/click/core.py", line 783, in 
invoke                                                  
    return __callback(*args, **kwargs)                                                                          
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/clinica/iotools/converters/ad
ni_to_bids/adni_to_bids_cli.py", line 79, in cli
    adni_to_bids.convert_clinical_data(
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/clinica/iotools/converters/ad
ni_to_bids/adni_to_bids.py", line 152, in convert_clinical_data
    adni_utils.create_adni_scans_files(conversion_path, bids_subjs_paths)
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/clinica/iotools/converters/ad
ni_to_bids/adni_utils.py", line 1108, in create_adni_scans_files
    converted_mod = find_conversion_mod(file_name)
  File "/DATA/user/miniconda3/envs/clinica-stable/lib/python3.8/site-packages/clinica/iotools/converters/ad
ni_to_bids/adni_utils.py", line 1149, in find_conversion_mod
    raise ValueError(f"Conversion modality could not be found for file {file_name}")
ValueError: Conversion modality could not be found for file sub-ADNI100S4469_ses-M066_dwi_ADC.nii.gz

Additional Context

  • Operating System: Ubuntu 20.04
  • Clinica Version: 0.7.7

Issue Identification
The current method for determining conversion modality within the find_conversion_mod function appears to be simplistic and prone to errors, as it relies solely on the filename. An enhancement is needed to improve modality detection.

Hi @souravraha

Thanks for reporting !
I agree with you that the logic of find_conversion_mod is a bit primitive and that raising a ValueError might be seen as a tad extreme as opposed to giving a warning to the user, ignoring the problematic image file, and proceeding with the rest of the conversion.

That being said, you shouldn't have apparent diffusion coefficient (ADC) images in your data since they aren't supported by Clinica. Moreover, they aren't BIDS-compliant (at least in this way where ADC acts as the suffix instead of being in the entities). For these reasons, they are explicitly deleted by the converter here:

# Removing images with unsupported suffixes if generated by dcm2niix
for suffix in ("ADC", "real", "imaginary"):
file_with_bad_suffix = output_path / f"{output_filename}_{suffix}"
if file_with_bad_suffix.with_suffix(".nii").exists():
cprint(
f"Image with bad suffix {suffix} was generated by dcm2niix "
f"for subject {subject} and session {session} : "
f"{file_with_bad_suffix.with_suffix('.nii.gz')}. This image will NOT "
"be converted as the suffix is not supported by Clinica.",
lvl="warning",

So, the find_conversion_mod function isn't so wrong giving you an error since there is indeed an error in the conversion process which will break the BIDS compliance of the output.

I downloaded the subject sub-100S4469 and ran the conversion and was able to reproduce the error with the dev version of Clinica. I believe this is happening because the ADC images aren't captured correctly by the code above (they end in ".nii.gz" and not ".nii").

I will open a PR to fix this. I'll let you know once it's merged in dev.

@NicolasGensollen

I see, thanks for your help.