Ejemplo n.º 1
0
    def __init__(self, name, spec, arg=None):
        super().__init__(name, spec, arg)
        self.branches = {}

        def _sanitize(t):
            return galaxy_ui_var(value=galaxy_esc(str(t).replace('%', 'X')))

        for type_ in spec.qiime_type:
            if type_.predicate is not None and is_union(type_.predicate):
                for pred in type_.predicate.unpack_union():
                    new_type = type_.duplicate(predicate=pred)
                    self.branches[_sanitize(new_type)] = new_type
            elif (type_.predicate is not None
                  and type_.predicate.name == 'Choices'):
                for choice in type_.predicate.template.choices:
                    new_type = type_.duplicate(predicate=Choices(choice))
                    self.branches[galaxy_esc(choice)] = new_type
            elif type_.name == 'Bool':
                for choice in [True, False]:
                    new_type = type_.duplicate(predicate=Choices(choice))
                    self.branches[galaxy_esc(choice)] = new_type
            else:
                self.branches[_sanitize(type_)] = type_

        if self.spec.default is None:
            self.branches[galaxy_esc(None)] = {None}
Ejemplo n.º 2
0
    def inputs_xml(self):
        base_types = []
        for t in self.spec.qiime_type:
            if t.predicate is not None and is_union(t.predicate):
                for pred in t.predicate.unpack_union():
                    base_types.append(t.duplicate(predicate=pred))
            else:
                base_types.append(t)

        to_add = []

        for t in base_types:
            if ((t.name == "Str" and t.predicate is None) or t.name == 'Float'
                    or t.name == 'Int'):
                to_add.append(t)

        root = None
        if to_add:
            root = XMLNode('conditional',
                           name=galaxy_ui_var(tag='conditional',
                                              name=self.name))
            select = XMLNode('param',
                             type='select',
                             name=galaxy_ui_var(tag='select'))
            root.append(select)
        else:
            select = XMLNode('param', type='select', name=self.name)

        choices = []
        for t in base_types:
            if t.predicate is not None and t.predicate.name == 'Choices':
                choices.extend(t.predicate.template.choices)
            elif t.name == 'Bool':
                choices.extend([True, False])

        display = None
        if not self.spec.has_default():
            display = 'Selection required'
        elif self.spec.default is None:
            display = 'None (Use default behavior)'

        if display is not None:
            value = galaxy_esc(None)
            select.append(
                XMLNode('option', display, value=value, selected='true'))
            if root is not None:
                when = XMLNode('when', value=value)
                hidden = XMLNode('param',
                                 type='hidden',
                                 name=self.name,
                                 value=value)
                when.append(hidden)
                root.append(when)

        for choice in choices:
            value = galaxy_esc(choice)
            option = XMLNode('option', self._display_func(choice), value=value)
            if self.spec.has_default() and self.spec.default == choice:
                option.set('selected', 'true')
            select.append(option)
            if root is not None:
                when = XMLNode('when', value=value)
                hidden = XMLNode('param',
                                 type='hidden',
                                 name=self.name,
                                 value=value)
                when.append(hidden)
                root.append(when)

        default = self.spec.default  # NOVALUE is fine
        for addition in to_add:
            value = galaxy_ui_var(value=galaxy_esc(
                # Galaxy will convert % to X internally and then complain
                # about a lack of matching cases, so we'll just do it now
                str(addition).replace('%', 'X')))
            option = XMLNode('option',
                             f'Provide a value ({addition})',
                             value=value)
            select.append(option)
            when = XMLNode('when', value=value)

            dispatch = {
                'Float': NumericCase,
                'Int': NumericCase,
                'Str': StrCase
            }
            try:
                ParamCase = dispatch[addition.name]
            except KeyError:
                raise NotImplementedError

            if default in addition:
                spec_default = default
                option.set('selected', 'true')
            else:
                spec_default = self.spec.NOVALUE

            new_spec = self.spec.duplicate(qiime_type=addition,
                                           default=spec_default)
            sub_ui = ParamCase(self.name, new_spec).inputs_xml()
            when.append(sub_ui)
            root.append(when)

        self.add_help(select)
        self.add_label(select)

        if not self.spec.has_default():
            select.append(
                XMLNode('validator',
                        f'value != {repr(galaxy_esc(None))}',
                        type='expression',
                        message='Please verify this parameter.'))

        if root is None:
            return select
        else:
            return root
Ejemplo n.º 3
0
def is_union_anywhere(qiime_type):
    return is_union(qiime_type) or (qiime_type.predicate is not None
                                    and is_union(qiime_type.predicate))