26
26
27
27
def generate_boutiques_descriptor (
28
28
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 ):
30
30
'''
31
31
Returns a JSON string containing a JSON Boutiques description of a Nipype interface.
32
32
Arguments:
@@ -37,6 +37,7 @@ def generate_boutiques_descriptor(
37
37
* container_image: name of the container image where the tool is installed
38
38
* container_index: optional index where the image is available
39
39
* container_type: type of container image (Docker or Singularity)
40
+ * save: True if you want to save descriptor to a file
40
41
'''
41
42
42
43
if not module :
@@ -102,8 +103,11 @@ def generate_boutiques_descriptor(
102
103
del input ['tempvalue' ]
103
104
104
105
# 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 )
107
111
108
112
print ("NOTE: Descriptors produced by this script may not entirely conform to the Nipype interface "
109
113
"specs. Please check that the descriptor is correct before using it." )
@@ -142,7 +146,14 @@ def get_boutiques_input(inputs, interface, input_name, spec,
142
146
input ['list' ] = is_list (spec_info )
143
147
input ['value-key' ] = "[" + input_name .upper (
144
148
) + "]" # 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
+
146
157
input ['tempvalue' ] = None
147
158
input ['description' ] = get_description_from_spec (inputs , input_name , spec )
148
159
if not (hasattr (spec , "mandatory" ) and spec .mandatory ):
@@ -160,6 +171,12 @@ def get_boutiques_input(inputs, interface, input_name, spec,
160
171
if value_choices is not None :
161
172
input ['value-choices' ] = value_choices
162
173
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
+
163
180
# Create unique, temporary value.
164
181
temp_value = must_generate_value (input_name , input ['type' ],
165
182
ignored_template_inputs , spec_info , spec ,
@@ -279,7 +296,6 @@ def get_type_from_handler_type(handler):
279
296
if the type is an integer.
280
297
'''
281
298
handler_type = type (handler ).__name__
282
- print ("TYPE" , handler_type )
283
299
if handler_type == "File" or handler_type == "Directory" :
284
300
return "File" , False
285
301
elif handler_type == "Int" or handler_type == "Float" :
0 commit comments