|
1 | 1 | from abc import ABC, abstractmethod
|
2 | 2 |
|
| 3 | +import six |
| 4 | + |
| 5 | +from .elements import parse_type, get_type_dict |
| 6 | + |
3 | 7 |
|
4 | 8 | class Requirement(ABC):
|
5 | 9 | '''
|
@@ -65,30 +69,128 @@ def get_dict(self):
|
65 | 69 | base = Requirement.get_dict(self)
|
66 | 70 | base['types'] = [t.get_dict() for t in self.types]
|
67 | 71 |
|
68 |
| - # class InputRecordSchema(object): |
69 |
| - # """ |
70 |
| - # Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputRecordSchema |
71 |
| - # """ |
72 |
| - # def __init__(self, label=None, name=None): |
73 |
| - # """ |
74 |
| - # :param fields: Defines the fields of the record. |
75 |
| - # :type fields: array<InputRecordField> |
76 |
| - # :param label: A short, human-readable label of this object. |
77 |
| - # :param name: NF (Name of the InputRecord) |
78 |
| - # """ |
79 |
| - # self.fields = [] |
80 |
| - # self.label = label |
81 |
| - # self.name = name |
82 |
| - # |
83 |
| - # def get_dict(self): |
84 |
| - # schema = {"type": "record"} |
85 |
| - # if self.fields: |
86 |
| - # schema["fields"] = {f.name: f.get_dict() for f in self.fields} |
87 |
| - # if self.label: |
88 |
| - # schema["label"] = self.label |
89 |
| - # if self.name: |
90 |
| - # schema["name"] = self.name |
91 |
| - # return schema |
| 72 | + class InputRecordSchema(object): |
| 73 | + """ |
| 74 | + Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputRecordSchema |
| 75 | + """ |
| 76 | + def __init__(self, label=None, name=None): |
| 77 | + """ |
| 78 | + :param fields: Defines the fields of the record. |
| 79 | + :type fields: array<InputRecordField> |
| 80 | + :param label: A short, human-readable label of this object. |
| 81 | + :param name: NF (Name of the InputRecord) |
| 82 | + """ |
| 83 | + self.fields = [] |
| 84 | + self.label = label |
| 85 | + self.name = name |
| 86 | + |
| 87 | + def get_dict(self): |
| 88 | + schema = {"type": "record"} |
| 89 | + if self.fields: |
| 90 | + schema["fields"] = {f.name: f.get_dict() for f in self.fields} |
| 91 | + if self.label: |
| 92 | + schema["label"] = self.label |
| 93 | + if self.name: |
| 94 | + schema["name"] = self.name |
| 95 | + return schema |
| 96 | + |
| 97 | + class InputRecordField(object): |
| 98 | + """ |
| 99 | + Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputRecordField |
| 100 | + """ |
| 101 | + def __init__(self, name, input_type, doc=None, input_binding=None, label=None): |
| 102 | + """ |
| 103 | + :param name: |
| 104 | + :param input_type: |
| 105 | + :type input_type: CWLType | InputRecordSchema | InputEnumSchema | InputArraySchema | string | |
| 106 | + array<CWLType | InputRecordSchema | InputEnumSchema | InputArraySchema | string> |
| 107 | + :param doc: A documentation string for this field |
| 108 | + :param input_binding: |
| 109 | + :type input_binding: CommandLineBinding |
| 110 | + :param label: |
| 111 | + """ |
| 112 | + self.name = name |
| 113 | + self.type = parse_type(input_type, requires_type=True) |
| 114 | + self.doc = doc |
| 115 | + self.inputBinding = input_binding |
| 116 | + self.label = label |
| 117 | + |
| 118 | + def get_dict(self): |
| 119 | + base = { |
| 120 | + 'name': self.name, |
| 121 | + "type": get_type_dict(self.type) |
| 122 | + } |
| 123 | + |
| 124 | + if self.doc: |
| 125 | + base["doc"] = self.doc |
| 126 | + if self.inputBinding: |
| 127 | + base["inputBinding"] = self.inputBinding.get_dict() |
| 128 | + if self.label: |
| 129 | + base["label"] = self.label |
| 130 | + return base |
| 131 | + |
| 132 | + class InputEnumSchema(object): |
| 133 | + """ |
| 134 | + Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputEnumSchema |
| 135 | + """ |
| 136 | + def __init__(self, symbols, label=None, name=None, input_binding=None): |
| 137 | + """ |
| 138 | + :param symbols: Defines the set of valid symbols. |
| 139 | + :type symbols: list[STRING] |
| 140 | + :param label: A short, human-readable label of this object. |
| 141 | + :type label: STRING |
| 142 | + :param name: |
| 143 | + :type name: STRING |
| 144 | + :param input_binding: |
| 145 | + :type input_binding: CommandLineBinding |
| 146 | + """ |
| 147 | + self.symbols = symbols |
| 148 | + self.label = label |
| 149 | + self.name = name |
| 150 | + self.inputBinding = input_binding |
| 151 | + |
| 152 | + def get_dict(self): |
| 153 | + base = { |
| 154 | + 'symbols': self.symbols, |
| 155 | + 'type': 'enum' |
| 156 | + } |
| 157 | + if self.label: |
| 158 | + base["label"] = self.label |
| 159 | + if self.name: |
| 160 | + base["name"] = self.name |
| 161 | + if self.inputBinding: |
| 162 | + base["inputBinding"] = self.inputBinding |
| 163 | + return base |
| 164 | + |
| 165 | + class InputArraySchema(object): |
| 166 | + """ |
| 167 | + Documentation: https://www.commonwl.org/v1.0/Workflow.html#InputArraySchema |
| 168 | + """ |
| 169 | + |
| 170 | + def __init__(self, items, label, input_binding): |
| 171 | + """ |
| 172 | + :param items: Defines the type of the array elements. |
| 173 | + :type items: CWLType | InputRecordSchema | InputEnumSchema | InputArraySchema | string | |
| 174 | + array<CWLType | InputRecordSchema | InputEnumSchema | InputArraySchema | string> |
| 175 | + :param label: A short, human-readable label of this object. |
| 176 | + :type label: STRING |
| 177 | + :param input_binding: |
| 178 | + :type input_binding: CommandLineBinding |
| 179 | + """ |
| 180 | + self.items = items |
| 181 | + self.label = label |
| 182 | + self.inputBinding = input_binding |
| 183 | + |
| 184 | + def get_dict(self): |
| 185 | + base = { |
| 186 | + 'items': get_type_dict(self.items), |
| 187 | + 'type': 'enum' |
| 188 | + } |
| 189 | + if self.label: |
| 190 | + base["label"] = self.label |
| 191 | + if self.inputBinding: |
| 192 | + base["inputBinding"] = self.inputBinding |
| 193 | + return base |
92 | 194 |
|
93 | 195 |
|
94 | 196 | class SoftwareRequirement(Requirement):
|
|
0 commit comments