diff --git a/smriprep/cli/tests/test_utils.py b/smriprep/cli/tests/test_utils.py index 83bbf50011..6e4636240d 100644 --- a/smriprep/cli/tests/test_utils.py +++ b/smriprep/cli/tests/test_utils.py @@ -42,3 +42,18 @@ def test_template_parser(monkeypatch): with pytest.raises(ValueError): u._template(['MNI152NLin6Asym:res-2', 'UnkownTemplate:res-2']) + + with pytest.raises(ValueError): + u._template(['MNI152NLin6Asym:res-2', 'func']) + + assert u._template(['MNI152NLin6Asym:res-2', 'fsnative']) == \ + OrderedDict([('MNI152NLin6Asym', {'res': '2'}), ('fsnative', None)]) + + u.ParseTemplates.set_nonstandard_spaces('func') + assert u._template(['MNI152NLin2009cAsym:res-2', 'func']) == \ + OrderedDict([('MNI152NLin2009cAsym', {'res': '2'}), ('func', None)]) + + u.ParseTemplates.set_nonstandard_spaces(['func', 'fsnative']) + assert u._template(['MNI152NLin2009cAsym:res-2', 'func', 'fsnative']) == \ + OrderedDict([('MNI152NLin2009cAsym', {'res': '2'}), + ('func', None), ('fsnative', None)]) diff --git a/smriprep/cli/utils.py b/smriprep/cli/utils.py index 319bdeeab7..5d22b64ae5 100644 --- a/smriprep/cli/utils.py +++ b/smriprep/cli/utils.py @@ -2,15 +2,25 @@ # vi: set ft=python sts=4 ts=4 sw=4 et: """CLI Utilities.""" from argparse import Action -from ..conf import TF_TEMPLATES as _TF_TEMPLATES +from ..conf import TF_TEMPLATES as _TF_TEMPLATES, LEGACY_SPACES class ParseTemplates(Action): """Manipulate a string of templates with modifiers.""" + EXCEPTIONS = tuple() + def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, _template(values)) + @classmethod + def set_nonstandard_spaces(cls, inlist): + """Set permissible nonstandard spaces names.""" + if isinstance(inlist, str): + inlist = [inlist] + + cls.EXCEPTIONS = tuple(inlist) + def _template(inlist): """Return an OrderedDict with templates.""" @@ -34,6 +44,12 @@ def output_space(value): mitems = modifier.split('-', 1) spec[mitems[0]] = len(mitems) == 1 or mitems[1] + if template in ParseTemplates.EXCEPTIONS: + return template, None + + if template in LEGACY_SPACES: + return template, None + if template not in _TF_TEMPLATES: raise ValueError("""\ Template identifier "{}" not found. Please, make sure TemplateFlow is \ diff --git a/smriprep/conf/__init__.py b/smriprep/conf/__init__.py index c32c4a4389..96f582faec 100644 --- a/smriprep/conf/__init__.py +++ b/smriprep/conf/__init__.py @@ -2,3 +2,5 @@ from templateflow.api import templates as _get_templates TF_TEMPLATES = tuple(_get_templates()) +LEGACY_SPACES = ('fsnative', 'fsaverage4', 'fsaverage5', + 'fsaverage6', 'fsaverage')