comparison planemo/lib/python3.7/site-packages/bioblend/galaxy/tools/inputs.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 class InputsBuilder(object):
2 """
3 """
4
5 def __init__(self):
6 self._input_dict = {}
7
8 def set(self, name, input):
9 self._input_dict[name] = input
10 return self
11
12 def set_param(self, name, value):
13 return self.set(name, param(value=value))
14
15 def set_dataset_param(self, name, value, src="hda"):
16 return self.set(name, dataset(value, src=src))
17
18 def to_dict(self):
19 values = {}
20 for key, value in self.flat_iter():
21 if hasattr(value, "value"):
22 value = value.value
23 values[key] = value
24 return values
25
26 def flat_iter(self, prefix=None):
27 for key, value in self._input_dict.items():
28 effective_key = key if prefix is None else "%s|%s" % (prefix, key)
29 if hasattr(value, "flat_iter"):
30 for flattened_key, flattened_value in value.flat_iter(effective_key):
31 yield flattened_key, flattened_value
32 else:
33 yield effective_key, value
34
35
36 class RepeatBuilder(object):
37
38 def __init__(self):
39 self._instances = []
40
41 def instance(self, inputs):
42 self._instances.append(inputs)
43 return self
44
45 def flat_iter(self, prefix=None):
46 for index, instance in enumerate(self._instances):
47 index_prefix = "%s_%d" % (prefix, index)
48 for key, value in instance.flat_iter(index_prefix):
49 yield key, value
50
51
52 class Param(object):
53
54 def __init__(self, value):
55 self.value = value
56
57
58 class DatasetParam(Param):
59
60 def __init__(self, value, src="hda"):
61 if not isinstance(value, dict):
62 value = dict(src=src, id=value)
63 super().__init__(value)
64
65
66 inputs = InputsBuilder
67 repeat = RepeatBuilder
68 conditional = InputsBuilder
69 param = Param
70 dataset = DatasetParam
71
72 __all__ = ("inputs", "repeat", "conditional", "param")