Skip to content

Commit 7c7d462

Browse files
committed
updated nipype2boutiques to conform to current schema, added default value for tool-version when interface version is null
1 parent 5a689fc commit 7c7d462

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@
2525

2626

2727
def generate_boutiques_descriptor(
28-
module, interface_name, ignored_template_inputs, docker_image,
29-
docker_index, verbose, ignore_template_numbers):
28+
module, interface_name, ignored_template_inputs, container_image,
29+
container_index, container_type, verbose, ignore_template_numbers):
3030
'''
3131
Returns a JSON string containing a JSON Boutiques description of a Nipype interface.
3232
Arguments:
3333
* module: module where the Nipype interface is declared.
34-
* interface: Nipype interface.
34+
* interface_name: name of Nipype interface.
3535
* ignored_template_inputs: a list of input names that should be ignored in the generation of output path templates.
3636
* ignore_template_numbers: True if numbers must be ignored in output path creations.
37+
* container_image: name of the container image where the tool is installed
38+
* container_index: optional index where the image is available
39+
* container_type: type of container image (Docker or Singularity)
3740
'''
3841

3942
if not module:
@@ -59,21 +62,23 @@ def generate_boutiques_descriptor(
5962
tool_desc[
6063
'description'] = interface_name + ", as implemented in Nipype (module: " + module_name + ", interface: " + interface_name + ")."
6164
tool_desc['inputs'] = []
62-
tool_desc['outputs'] = []
63-
tool_desc['tool-version'] = interface.version
64-
tool_desc['schema-version'] = '0.2-snapshot'
65-
if docker_image:
66-
tool_desc['docker-image'] = docker_image
67-
if docker_index:
68-
tool_desc['docker-index'] = docker_index
65+
tool_desc['output-files'] = []
66+
tool_desc['tool-version'] = interface.version if interface.version is not None else 'undefined'
67+
tool_desc['schema-version'] = '0.5'
68+
if container_image:
69+
tool_desc['container-image'] = {}
70+
tool_desc['container-image']['image'] = container_image
71+
tool_desc['container-image']['type'] = container_type
72+
if container_index:
73+
tool_desc['container-image']['index'] = container_index
6974

7075
# Generates tool inputs
7176
for name, spec in sorted(interface.inputs.traits(transient=None).items()):
7277
input = get_boutiques_input(inputs, interface, name, spec,
7378
ignored_template_inputs, verbose,
7479
ignore_template_numbers)
7580
tool_desc['inputs'].append(input)
76-
tool_desc['command-line'] += input['command-line-key'] + " "
81+
tool_desc['command-line'] += input['value-key'] + " "
7782
if verbose:
7883
print("-> Adding input " + input['name'])
7984

@@ -82,13 +87,13 @@ def generate_boutiques_descriptor(
8287
output = get_boutiques_output(name, interface, tool_desc['inputs'],
8388
verbose)
8489
if output['path-template'] != "":
85-
tool_desc['outputs'].append(output)
90+
tool_desc['output-files'].append(output)
8691
if verbose:
8792
print("-> Adding output " + output['name'])
8893
elif verbose:
8994
print("xx Skipping output " + output['name'] +
9095
" with no path template.")
91-
if tool_desc['outputs'] == []:
96+
if tool_desc['output-files'] == []:
9297
raise Exception("Tool has no output.")
9398

9499
# Removes all temporary values from inputs (otherwise they will
@@ -125,7 +130,7 @@ def get_boutiques_input(inputs, interface, input_name, spec,
125130
input['name'] = input_name.replace('_', ' ').capitalize()
126131
input['type'] = get_type_from_spec_info(spec_info)
127132
input['list'] = is_list(spec_info)
128-
input['command-line-key'] = "[" + input_name.upper(
133+
input['value-key'] = "[" + input_name.upper(
129134
) + "]" # assumes that input names are unique
130135
input['command-line-flag'] = ("--%s" % input_name + " ").strip()
131136
input['tempvalue'] = None
@@ -178,7 +183,6 @@ def get_boutiques_output(name, interface, tool_inputs, verbose=False):
178183
output = {}
179184
output['name'] = name.replace('_', ' ').capitalize()
180185
output['id'] = name
181-
output['type'] = "File"
182186
output['path-template'] = ""
183187
output[
184188
'optional'] = True # no real way to determine if an output is always produced, regardless of the input values.
@@ -201,7 +205,7 @@ def get_boutiques_output(name, interface, tool_inputs, verbose=False):
201205
if str(input_value) in output_value:
202206
output_value = os.path.basename(
203207
output_value.replace(input_value,
204-
input['command-line-key'])
208+
input['value-key'])
205209
) # FIXME: this only works if output is written in the current directory
206210
output['path-template'] = os.path.basename(output_value)
207211
return output

nipype/utils/tests/test_nipype2boutiques.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def test_generate():
1111
generate_boutiques_descriptor(module='nipype.interfaces.ants.registration',
1212
interface_name='ANTS',
1313
ignored_template_inputs=(),
14-
docker_image=None,
15-
docker_index=None,
14+
container_image=None,
15+
container_index=None,
16+
container_type=None,
1617
verbose=False,
1718
ignore_template_numbers=False)

0 commit comments

Comments
 (0)