Added support for positional parameters.
Luis de la Garza
6 years ago
27 | 27 | OUTPUT_BINDING = 'outputBinding' |
28 | 28 | PREFIX = 'prefix' |
29 | 29 | OUTPUTS = 'outputs' |
30 | POSITION = 'position' | |
30 | 31 | VALUE_FROM = 'valueFrom' |
31 | 32 | GLOB = 'glob' |
32 | 33 | LABEL = 'label' |
107 | 108 | create_lists_if_missing(cwl_tool, [INPUTS, OUTPUTS]) |
108 | 109 | # we know the only outputs are of type _OutFile |
109 | 110 | # we need an input of type string that will contain the name of the output file |
110 | input_binding = {} | |
111 | input_binding[PREFIX] = utils.extract_command_line_prefix(param, ctd_model) | |
112 | if hardcoded_value is not None: | |
113 | input_binding[VALUE_FROM] = hardcoded_value | |
114 | ||
115 | 111 | label = "Filename for %s output file" % param_name |
116 | 112 | input_name_for_output_filename = get_input_name_for_output_filename(param) |
117 | 113 | input_param = {} |
118 | 114 | input_param[ID] = input_name_for_output_filename |
119 | input_param[INPUT_BINDING] = input_binding | |
120 | 115 | input_param[DOC] = label |
121 | 116 | input_param[LABEL] = label |
122 | 117 | if param_default is not None: |
123 | 118 | input_param[DEFAULT] = param_default |
124 | 119 | input_param[TYPE] = generate_cwl_param_type(param, TYPE_STRING) |
120 | insert_input_binding(ctd_model, param, hardcoded_value, input_param) | |
125 | 121 | |
126 | 122 | output_binding = {} |
127 | 123 | output_binding[GLOB] = "$(inputs.%s)" % input_name_for_output_filename |
139 | 135 | else: |
140 | 136 | create_lists_if_missing(cwl_tool, [INPUTS]) |
141 | 137 | # we know that anything that is not an _OutFile is an input |
142 | input_binding = {} | |
143 | input_binding[PREFIX] = utils.extract_command_line_prefix(param, ctd_model) | |
144 | if hardcoded_value is not None: | |
145 | input_binding[VALUE_FROM] = hardcoded_value | |
146 | ||
147 | 138 | input_param = {} |
148 | 139 | input_param[ID] = cwl_fixed_param_name |
149 | 140 | input_param[DOC] = param.description |
150 | 141 | input_param[LABEL] = param.description |
151 | 142 | if param_default is not None: |
152 | 143 | input_param[DEFAULT] = param_default |
153 | input_param[INPUT_BINDING] = input_binding | |
154 | 144 | input_param[TYPE] = generate_cwl_param_type(param) |
145 | insert_input_binding(ctd_model, param, hardcoded_value, input_param) | |
155 | 146 | |
156 | 147 | cwl_tool[INPUTS].append(input_param) |
157 | 148 | |
181 | 172 | def generate_cwl_param_type(param, forced_type=None): |
182 | 173 | cwl_type = TYPE_TO_CWL_TYPE[param.type] if forced_type is None else forced_type |
183 | 174 | return cwl_type if param.required else ['null', cwl_type] |
175 | ||
176 | ||
177 | # generate, and insert, the inputBinding | |
178 | def insert_input_binding(ctd_model, param, hardcoded_value, cwl_input_param): | |
179 | prefix = utils.extract_command_line_prefix(param, ctd_model) | |
180 | prefix = None if prefix is None or not prefix.strip() else prefix | |
181 | ||
182 | input_binding = {} | |
183 | ||
184 | if prefix is not None: | |
185 | input_binding[PREFIX] = prefix | |
186 | ||
187 | if hardcoded_value is not None: | |
188 | input_binding[VALUE_FROM] = hardcoded_value | |
189 | ||
190 | if param.is_positional(): | |
191 | input_binding[POSITION] = param.position | |
192 | ||
193 | # insert input binding if there's something in it | |
194 | if input_binding: | |
195 | cwl_input_param[INPUT_BINDING] = input_binding |