aramis-lab / clinica

Software platform for clinical neuroimaging studies
http://www.clinica.run/
Other
227 stars 81 forks source link

Improvements to module `input_files` #1308

Open NicolasGensollen opened 1 month ago

NicolasGensollen commented 1 month ago

The module clinica.utils.input_files defines a long list of dictionaries which are used as query patterns in the clinica_file_reader functions.

First of all, there are a lot of these objects which are not used in the code base. A few examples:

T2W_LINEAR
FLAIR_T2W_LINEAR
T1W_EXTENSIVE
FLAIR_T2W_LINEAR_CROPPED

We clearly should get rid of them.

All these patterns could also be better represented with dataclasses since they have a defined structure. Something like that would already enrich the code:

@dataclass
class Pattern:
    pattern: str
    description: str
    needed_pipeline: str

Also, a lot of these patterns could be factorized in functions taking some parameters (the hemisphere, the name of the atlas, the pet tracer...) instead of being copy-pasted.

For example this

https://github.com/aramis-lab/clinica/blob/954d4a950aa341acf54059c1e93b27c9de18fbc2/clinica/utils/input_files.py#L51-L61

could easily be factorized in:

def get_t1_freesurfer_longitudinal_white_matter_surface_pattern(
    hemisphere: Union[str, HemiSphere],
) -> Pattern:
    hemisphere = HemiSphere(hemisphere)
    return Pattern(
        f"t1/long-*/freesurfer_longitudinal/sub-*_ses-*.long.sub-*_*/surf/{hemisphere.value}.white",
        (
            f"{'right' if hemisphere == HemiSphere.RIGHT else 'left'} white matter/gray matter border "
            f"surface ({hemisphere.value}.white) generated with t1-freesurfer-longitudinal."
        ),
        "t1-freesurfer and t1-freesurfer longitudinal"
    )
NicolasGensollen commented 9 hours ago

Keeping this open for now, but will likely be addressed in a more general way by #1398