Skip to content

Commit bb260f8

Browse files
committed
added method to get all the mutex and all-or-none groups from the input specs
1 parent ad36016 commit bb260f8

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def generate_boutiques_descriptor(
6464
'description'] = interface_name + ", as implemented in Nipype (module: " + module_name + ", interface: " + interface_name + ")."
6565
tool_desc['inputs'] = []
6666
tool_desc['output-files'] = []
67+
tool_desc['groups'] = []
6768
tool_desc['tool-version'] = interface.version if interface.version is not None else "No version provided."
6869
tool_desc['schema-version'] = '0.5'
6970
if container_image:
@@ -88,16 +89,21 @@ def generate_boutiques_descriptor(
8889
if verbose:
8990
print("-> Adding input " + i['name'])
9091
# 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}]
92+
tool_desc['groups'].append({'id': input[0]['id'] + "_group",
93+
'name': input[0]['name'] + " group",
94+
'members': mutex_group_members,
95+
'mutually-exclusive': True})
9596
else:
9697
tool_desc['inputs'].append(input)
9798
tool_desc['command-line'] += input['value-key'] + " "
9899
if verbose:
99100
print("-> Adding input " + input['name'])
100101

102+
# Generates input groups
103+
tool_desc['groups'] += get_boutiques_groups(interface.inputs.traits(transient=None).items())
104+
if len(tool_desc['groups']) == 0:
105+
del tool_desc['groups']
106+
101107
# Generates tool outputs
102108
for name, spec in sorted(outputs.traits(transient=None).items()):
103109
output = get_boutiques_output(outputs, name, spec, interface, tool_desc['inputs'],
@@ -245,15 +251,6 @@ def get_boutiques_input(inputs, interface, input_name, spec,
245251
if value_choices is not None:
246252
input['value-choices'] = value_choices
247253

248-
if spec.requires is not None:
249-
input['requires-inputs'] = spec.requires
250-
251-
if spec.xor is not None:
252-
input['disables-inputs'] = list(spec.xor)
253-
# Make sure input does not disable itself
254-
if input['id'] in input['disables-inputs']:
255-
input['disables-inputs'].remove(input['id'])
256-
257254
# Create unique, temporary value.
258255
temp_value = must_generate_value(input_name, input['type'],
259256
ignored_template_inputs, spec_info, spec,
@@ -351,6 +348,37 @@ def get_boutiques_output(outputs, name, spec, interface, tool_inputs, verbose=Fa
351348
return output
352349

353350

351+
def get_boutiques_groups(input_traits):
352+
desc_groups = []
353+
all_or_none_input_sets = []
354+
mutex_input_sets = []
355+
356+
# Get all the groups
357+
for name, spec in input_traits:
358+
if spec.requires is not None:
359+
group_members = set([name] + list(spec.requires))
360+
if group_members not in all_or_none_input_sets:
361+
all_or_none_input_sets.append(group_members)
362+
if spec.xor is not None:
363+
group_members = set([name] + list(spec.xor))
364+
if group_members not in mutex_input_sets:
365+
mutex_input_sets.append(group_members)
366+
367+
# Create a dictionary for each one
368+
for i in range(0, len(all_or_none_input_sets)):
369+
desc_groups.append({'id': "all_or_none_group" + ("_" + str(i + 1) if i != 0 else ""),
370+
'name': "All or none group" + (" " + str(i + 1) if i != 0 else ""),
371+
'members': list(all_or_none_input_sets[i]),
372+
'all-or-none': True})
373+
374+
for i in range(0, len(mutex_input_sets)):
375+
desc_groups.append({'id': "mutex_group" + ("_" + str(i + 1) if i != 0 else ""),
376+
'name': "Mutex group" + (" " + str(i + 1) if i != 0 else ""),
377+
'members': list(mutex_input_sets[i]),
378+
'mutually-exclusive': True})
379+
380+
return desc_groups
381+
354382
def get_unique_value(type, id):
355383
'''
356384
Returns a unique value of type 'type', for input with id 'id',

0 commit comments

Comments
 (0)