aramis-lab / clinica

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

Use regex in `_convert_subject_to_rid()` #1130

Closed NicolasGensollen closed 5 months ago

NicolasGensollen commented 5 months ago

The small function _convert_subject_to_rid() is not as robust as we'd hope since it implicitly assumes a string in the format "XXX_S_XXXX" and should return the last 4 digits:

https://github.com/aramis-lab/clinica/blob/4b1c2a4743b4d7f6d4d06804fb5a3c49bc8f5096/clinica/iotools/converters/adni_to_bids/adni_modalities/adni_fdg_pet.py#L307-L323

Returning the slice [-4:] works as long as the input string is correctly formatted but could return crazy results if badly formatted. Currently, there is no guarantee that this will be the case as the subject input string comes from the subjects list, which is simply extracted from a CSV file:

https://github.com/aramis-lab/clinica/blob/4b1c2a4743b4d7f6d4d06804fb5a3c49bc8f5096/clinica/iotools/converters/adni_to_bids/adni_modalities/adni_fdg_pet.py#L95-L98

Using a regex like mentioned in the TODO could improve the function robustness a bit.