Skip to content

Commit ce06815

Browse files
committed
fixed json file formatting, added save parameter, fixed command-line-flag to take argstr from input spec, added requires-inputs and disables-inputs
1 parent 181c481 commit ce06815

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
def generate_boutiques_descriptor(
2828
module, interface_name, ignored_template_inputs, container_image,
29-
container_index, container_type, verbose, ignore_template_numbers):
29+
container_index, container_type, verbose, ignore_template_numbers, save):
3030
'''
3131
Returns a JSON string containing a JSON Boutiques description of a Nipype interface.
3232
Arguments:
@@ -37,6 +37,7 @@ def generate_boutiques_descriptor(
3737
* container_image: name of the container image where the tool is installed
3838
* container_index: optional index where the image is available
3939
* container_type: type of container image (Docker or Singularity)
40+
* save: True if you want to save descriptor to a file
4041
'''
4142

4243
if not module:
@@ -102,8 +103,11 @@ def generate_boutiques_descriptor(
102103
del input['tempvalue']
103104

104105
# Save descriptor to a file
105-
with open(interface_name + '.json', 'w') as outfile:
106-
json.dump(tool_desc, outfile)
106+
if save:
107+
with open(interface_name + '.json', 'w') as outfile:
108+
json.dump(tool_desc, outfile, indent=4, separators=(',', ': '))
109+
if verbose:
110+
print("-> Descriptor saved to file " + outfile.name)
107111

108112
print("NOTE: Descriptors produced by this script may not entirely conform to the Nipype interface "
109113
"specs. Please check that the descriptor is correct before using it.")
@@ -142,7 +146,14 @@ def get_boutiques_input(inputs, interface, input_name, spec,
142146
input['list'] = is_list(spec_info)
143147
input['value-key'] = "[" + input_name.upper(
144148
) + "]" # assumes that input names are unique
145-
input['command-line-flag'] = ("--%s" % input_name + " ").strip()
149+
150+
# Add the command line flag specified by argstr
151+
# If no argstr is provided and input type is Flag, create a flag from the name
152+
if spec.argstr and spec.argstr.split("%")[0]:
153+
input['command-line-flag'] = spec.argstr.split("%")[0].strip()
154+
elif input['type'] == "Flag":
155+
input['command-line-flag'] = ("--%s" % input_name + " ").strip()
156+
146157
input['tempvalue'] = None
147158
input['description'] = get_description_from_spec(inputs, input_name, spec)
148159
if not (hasattr(spec, "mandatory") and spec.mandatory):
@@ -160,6 +171,12 @@ def get_boutiques_input(inputs, interface, input_name, spec,
160171
if value_choices is not None:
161172
input['value-choices'] = value_choices
162173

174+
if spec.requires is not None:
175+
input['requires-inputs'] = spec.requires
176+
177+
if spec.xor is not None:
178+
input['disables-inputs'] = spec.xor
179+
163180
# Create unique, temporary value.
164181
temp_value = must_generate_value(input_name, input['type'],
165182
ignored_template_inputs, spec_info, spec,
@@ -279,7 +296,6 @@ def get_type_from_handler_type(handler):
279296
if the type is an integer.
280297
'''
281298
handler_type = type(handler).__name__
282-
print("TYPE", handler_type)
283299
if handler_type == "File" or handler_type == "Directory":
284300
return "File", False
285301
elif handler_type == "Int" or handler_type == "Float":

0 commit comments

Comments
 (0)