nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
748 stars 530 forks source link

DataSink: Add possibility to replace regex match with another regex match in #3586

Open JohannesWiesner opened 1 year ago

JohannesWiesner commented 1 year ago

Summary

I have a feature request: It would be nice if it was possible to replace one regex-match with another one from the same input string for the the regexp_substitutions argument of nipype.interfaces.io.Datasink. Then one wouldn't have to define one substitution for every possible case. E.g. when the parameterization puts out something like this:

_subject_100206_task_WM
_subject_100206_task_EMOTION
_subject_100206_task_FACES

and I would like to have the folders like this:

WM
EMOTION
FACES

Then I currently have to do this:

datasink.inputs.regexp_substitutions = [('subject_[a-zA-Z0-9]+',''),
                                         ('_task_EMOTION','EMOTION'),
                                         ('_task_WM','WM'),
                                         ('_task_FACES','FACES')
                                        ]

It would be nice if one could use regex groups to something like (pseudo-code!):

datasink.inputs.regexp_substitutions = [('subject_[a-zA-Z0-9]+',''),
                                         ('_task_\w+','_task_(\w+)'),
                                        ]
effigies commented 1 year ago

It looks like we've got existing tests (https://github.com/nipy/nipype/blob/75796d554394271f1c7cd710b2a1ce8b499989ba/nipype/interfaces/tests/test_io.py#L459-L487), so I would say if you can come up with a patch that implements this that doesn't break those expectations (or those expectations are incidental), that would be fine.

It might be easier just to write your own DataSink that does what you want.