nipreps / fmriprep

fMRIPrep is a robust and easy-to-use pipeline for preprocessing of diverse fMRI data. The transparent workflow dispenses of manual intervention, thereby ensuring the reproducibility of the results.
https://fmriprep.org
Apache License 2.0
638 stars 294 forks source link

Select consistent parcellation for producing aparcaseg derivatives #1337

Closed effigies closed 6 years ago

effigies commented 6 years ago

From Neurostars #2656, the aparcaseg derivatives may have different labels across subjects. This would appear to be a failure of selection in the following lines:

https://github.com/poldracklab/fmriprep/blob/c05b7bb7cf26ebd47be7b1a9c17f8ed937cb1133/fmriprep/workflows/anatomical.py#L1137-L1144

Currently the code assumes that the order of files is lexical, i.e.:

0) mri/aparc+aseg.mgz 1) mri/aparc.a2009s+aseg.mgz 2) mri/aparc.DKTatlas+aseg.mgz

The reported behavior is consistent with unsorted outputs of FreeSurferSource. The simplest patch would be:

    if segmentation.startswith('aparc'):
        if segmentation == 'aparc_aseg':
            def _sel(x): return sorted(x)[0]
        elif segmentation == 'aparc_a2009s':
            def _sel(x): return sorted(x)[1]
        elif segmentation == 'aparc_dkt':
            def _sel(x): return sorted(x)[2]
        segmentation = (segmentation, _sel)

Possibly a more future-durable approach would be to assume any number of parcellations might be present, and perform a string comparison:

    if segmentation.startswith('aparc'):
        if segmentation == 'aparc_aseg':
            def _sel(x): return [parc for parc in x if 'aparc+' in parc][0]
        elif segmentation == 'aparc_a2009s':
            def _sel(x): return [parc for parc in x if 'a2009s+' in parc][0]
        elif segmentation == 'aparc_dkt':
            def _sel(x): return [parc for parc in x if 'DKTatlas+' in parc][0]
        segmentation = (segmentation, _sel)
effigies commented 6 years ago

Fixed in #1369.