Skip to content

Commit ad36016

Browse files
committed
put compound inputs into mutex group
1 parent ee4b935 commit ad36016

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,20 @@ def generate_boutiques_descriptor(
7878
input = get_boutiques_input(inputs, interface, name, spec,
7979
ignored_template_inputs, verbose,
8080
ignore_template_numbers)
81+
# Handle compound inputs (inputs that can be of multiple types and are mutually exclusive)
8182
if isinstance(input, list):
83+
mutex_group_members = []
8284
for i in input:
8385
tool_desc['inputs'].append(i)
8486
tool_desc['command-line'] += i['value-key'] + " "
87+
mutex_group_members.append(i['id'])
8588
if verbose:
8689
print("-> Adding input " + i['name'])
90+
# Put inputs into a mutually exclusive group
91+
tool_desc['groups'] = [{'id': input[0]['id'] + "_group",
92+
'name': input[0]['name'],
93+
'members': mutex_group_members,
94+
'mutually-exclusive': True}]
8795
else:
8896
tool_desc['inputs'].append(input)
8997
tool_desc['command-line'] += input['value-key'] + " "
@@ -123,7 +131,8 @@ def generate_boutiques_descriptor(
123131

124132
def get_boutiques_input(inputs, interface, input_name, spec,
125133
ignored_template_inputs, verbose,
126-
ignore_template_numbers, handler=None, input_number=None):
134+
ignore_template_numbers, handler=None,
135+
input_number=None):
127136
"""
128137
Returns a dictionary containing the Boutiques input corresponding to a Nipype intput.
129138
@@ -134,6 +143,8 @@ def get_boutiques_input(inputs, interface, input_name, spec,
134143
* spec: Nipype input spec.
135144
* ignored_template_inputs: input names for which no temporary value must be generated.
136145
* ignore_template_numbers: True if numbers must be ignored in output path creations.
146+
* handler: used when handling compound inputs, which don't have their own input spec
147+
* input_number: used when handling compound inputs to assign each a unique ID
137148
138149
Assumes that:
139150
* Input names are unique.
@@ -142,7 +153,7 @@ def get_boutiques_input(inputs, interface, input_name, spec,
142153

143154
input = {}
144155

145-
if input_number is not None:
156+
if input_number is not None and input_number != 0: # No need to append a number to the first of a list of compound inputs
146157
input['id'] = input_name + "_" + str(input_number + 1)
147158
else:
148159
input['id'] = input_name
@@ -158,7 +169,6 @@ def get_boutiques_input(inputs, interface, input_name, spec,
158169
handler_type = type(trait_handler).__name__
159170

160171
# Deal with compound traits
161-
# TODO create a mutually exclusive group for members of compound traits
162172
if handler_type == "TraitCompound":
163173
input_list = []
164174
# Recursively create an input for each trait
@@ -341,34 +351,6 @@ def get_boutiques_output(outputs, name, spec, interface, tool_inputs, verbose=Fa
341351
return output
342352

343353

344-
# TODO remove this
345-
def get_type_from_spec_info(spec_info):
346-
'''
347-
Returns an input type from the spec info. There must be a better
348-
way to get an input type in Nipype than to parse the spec info.
349-
'''
350-
if ("an existing file name" in spec_info) or (
351-
"input volumes" in spec_info):
352-
return "File"
353-
elif ("an integer" in spec_info or "a float" in spec_info):
354-
return "Number"
355-
elif "a boolean" in spec_info:
356-
return "Boolean"
357-
return "String"
358-
359-
360-
# TODO remove this
361-
def is_list(spec_info):
362-
'''
363-
Returns True if the spec info looks like it describes a list
364-
parameter. There must be a better way in Nipype to check if an input
365-
is a list.
366-
'''
367-
if "a list" in spec_info:
368-
return True
369-
return False
370-
371-
372354
def get_unique_value(type, id):
373355
'''
374356
Returns a unique value of type 'type', for input with id 'id',

0 commit comments

Comments
 (0)