Skip to content

Commit c0a2f82

Browse files
author
Luis de la Garza
committed
Added support for positional parameters.
1 parent 4cddfbd commit c0a2f82

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

cwl/converter.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
OUTPUT_BINDING = 'outputBinding'
2929
PREFIX = 'prefix'
3030
OUTPUTS = 'outputs'
31+
POSITION = 'position'
3132
VALUE_FROM = 'valueFrom'
3233
GLOB = 'glob'
3334
LABEL = 'label'
@@ -108,21 +109,16 @@ def convert_to_cwl(ctd_model, args):
108109
create_lists_if_missing(cwl_tool, [INPUTS, OUTPUTS])
109110
# we know the only outputs are of type _OutFile
110111
# we need an input of type string that will contain the name of the output file
111-
input_binding = {}
112-
input_binding[PREFIX] = utils.extract_command_line_prefix(param, ctd_model)
113-
if hardcoded_value is not None:
114-
input_binding[VALUE_FROM] = hardcoded_value
115-
116112
label = "Filename for %s output file" % param_name
117113
input_name_for_output_filename = get_input_name_for_output_filename(param)
118114
input_param = {}
119115
input_param[ID] = input_name_for_output_filename
120-
input_param[INPUT_BINDING] = input_binding
121116
input_param[DOC] = label
122117
input_param[LABEL] = label
123118
if param_default is not None:
124119
input_param[DEFAULT] = param_default
125120
input_param[TYPE] = generate_cwl_param_type(param, TYPE_STRING)
121+
insert_input_binding(ctd_model, param, hardcoded_value, input_param)
126122

127123
output_binding = {}
128124
output_binding[GLOB] = "$(inputs.%s)" % input_name_for_output_filename
@@ -140,19 +136,14 @@ def convert_to_cwl(ctd_model, args):
140136
else:
141137
create_lists_if_missing(cwl_tool, [INPUTS])
142138
# we know that anything that is not an _OutFile is an input
143-
input_binding = {}
144-
input_binding[PREFIX] = utils.extract_command_line_prefix(param, ctd_model)
145-
if hardcoded_value is not None:
146-
input_binding[VALUE_FROM] = hardcoded_value
147-
148139
input_param = {}
149140
input_param[ID] = cwl_fixed_param_name
150141
input_param[DOC] = param.description
151142
input_param[LABEL] = param.description
152143
if param_default is not None:
153144
input_param[DEFAULT] = param_default
154-
input_param[INPUT_BINDING] = input_binding
155145
input_param[TYPE] = generate_cwl_param_type(param)
146+
insert_input_binding(ctd_model, param, hardcoded_value, input_param)
156147

157148
cwl_tool[INPUTS].append(input_param)
158149

@@ -182,3 +173,24 @@ def fix_param_name(param_name):
182173
def generate_cwl_param_type(param, forced_type=None):
183174
cwl_type = TYPE_TO_CWL_TYPE[param.type] if forced_type is None else forced_type
184175
return cwl_type if param.required else ['null', cwl_type]
176+
177+
178+
# generate, and insert, the inputBinding
179+
def insert_input_binding(ctd_model, param, hardcoded_value, cwl_input_param):
180+
prefix = utils.extract_command_line_prefix(param, ctd_model)
181+
prefix = None if prefix is None or not prefix.strip() else prefix
182+
183+
input_binding = {}
184+
185+
if prefix is not None:
186+
input_binding[PREFIX] = prefix
187+
188+
if hardcoded_value is not None:
189+
input_binding[VALUE_FROM] = hardcoded_value
190+
191+
if param.is_positional():
192+
input_binding[POSITION] = param.position
193+
194+
# insert input binding if there's something in it
195+
if input_binding:
196+
cwl_input_param[INPUT_BINDING] = input_binding

0 commit comments

Comments
 (0)