diff env/lib/python3.7/site-packages/bioblend/galaxy/tools/inputs.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.7/site-packages/bioblend/galaxy/tools/inputs.py	Sat May 02 07:14:21 2020 -0400
@@ -0,0 +1,75 @@
+import six
+
+
+class InputsBuilder(object):
+    """
+    """
+
+    def __init__(self):
+        self._input_dict = {}
+
+    def set(self, name, input):
+        self._input_dict[name] = input
+        return self
+
+    def set_param(self, name, value):
+        return self.set(name, param(value=value))
+
+    def set_dataset_param(self, name, value, src="hda"):
+        return self.set(name, dataset(value, src=src))
+
+    def to_dict(self):
+        values = {}
+        for key, value in self.flat_iter():
+            if hasattr(value, "value"):
+                value = value.value
+            values[key] = value
+        return values
+
+    def flat_iter(self, prefix=None):
+        for key, value in six.iteritems(self._input_dict):
+            effective_key = key if prefix is None else "%s|%s" % (prefix, key)
+            if hasattr(value, "flat_iter"):
+                for flattened_key, flattened_value in value.flat_iter(effective_key):
+                    yield flattened_key, flattened_value
+            else:
+                yield effective_key, value
+
+
+class RepeatBuilder(object):
+
+    def __init__(self):
+        self._instances = []
+
+    def instance(self, inputs):
+        self._instances.append(inputs)
+        return self
+
+    def flat_iter(self, prefix=None):
+        for index, instance in enumerate(self._instances):
+            index_prefix = "%s_%d" % (prefix, index)
+            for key, value in instance.flat_iter(index_prefix):
+                yield key, value
+
+
+class Param(object):
+
+    def __init__(self, value):
+        self.value = value
+
+
+class DatasetParam(Param):
+
+    def __init__(self, value, src="hda"):
+        if not isinstance(value, dict):
+            value = dict(src=src, id=value)
+        super(DatasetParam, self).__init__(value)
+
+
+inputs = InputsBuilder
+repeat = RepeatBuilder
+conditional = InputsBuilder
+param = Param
+dataset = DatasetParam
+
+__all__ = ("inputs", "repeat", "conditional", "param")