nipype
nipype copied to clipboard
DataSink: Add possibility to replace regex match with another regex match in
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+)'),
]
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.