@@ -22,8 +22,9 @@ def parse_param_type(param_type):
22
22
Parses the parameter type as one of the required types:
23
23
:: https://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputParameter
24
24
25
-
26
- :param param_type:
25
+ :param param_type: a CWL type that is _validated_
26
+ :type param_type: CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string |
27
+ array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>
27
28
:return: CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string |
28
29
array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>
29
30
"""
@@ -34,12 +35,25 @@ def parse_param_type(param_type):
34
35
if optional :
35
36
_LOGGER .debug ("Detected {param_type} to be optional" .format (param_type = param_type ))
36
37
cwltype = param_type [:- 1 ] if optional else param_type
38
+
39
+ # check for arrays
40
+ if len (cwltype ) > 2 and cwltype [- 2 :] == "[]" :
41
+ array_type = CommandInputArraySchema (items = cwltype [:- 2 ])
42
+ # How to make arrays optional input: https://www.biostars.org/p/233562/#234089
43
+ return [DEF_TYPE , array_type ] if optional else array_type
44
+
37
45
if cwltype not in CWL_TYPE :
38
46
_LOGGER .warning ("The type '{param_type}' is not a valid CWLType, expected one of: {types}"
39
47
.format (param_type = param_type , types = ", " .join (str (x ) for x in CWL_TYPE )))
40
48
_LOGGER .warning ("type is set to {}." .format (DEF_TYPE ))
41
49
return DEF_TYPE
42
50
return param_type
51
+
52
+ elif isinstance (param_type , list ):
53
+ return [parse_param_type (p ) for p in param_type ]
54
+
55
+ elif isinstance (param_type , CommandInputArraySchema ):
56
+ return param_type # validate if required
43
57
else :
44
58
_LOGGER .warning ("Unable to detect type of param '{param_type}" .format (param_type = param_type ))
45
59
return DEF_TYPE
@@ -85,12 +99,54 @@ def get_dict(self):
85
99
:return: dictionnary of the object
86
100
:rtype: DICT
87
101
'''
88
- dict_param = {k : v for k , v in vars (self ).items () if v is not None and v is not False }
89
- if dict_param ['type' ] != 'File' :
90
- # Remove what is only for File
91
- for key in ['format' , 'secondaryFiles' , 'streamable' ]:
92
- try :
93
- del (dict_param [key ])
94
- except KeyError :
95
- pass
102
+ manual = ["type" ]
103
+ dict_param = {k : v for k , v in vars (self ).items () if v is not None and v is not False and k not in manual }
104
+
105
+ should_have_file_related_keys = False
106
+
107
+ if isinstance (self .type , str ):
108
+ dict_param ["type" ] = self .type
109
+ should_have_file_related_keys = self .type == "File"
110
+
111
+ elif isinstance (self .type , CommandInputArraySchema ):
112
+ dict_param ["type" ] = self .type .get_dict ()
113
+ should_have_file_related_keys = self .type .type == "File"
114
+
115
+ keys_to_remove = [k for k in ['format' , 'secondaryFiles' , 'streamable' ] if k in dict_param ]
116
+
117
+ if not should_have_file_related_keys :
118
+ for key in keys_to_remove :
119
+ del (dict_param [key ])
96
120
return dict_param
121
+
122
+
123
+ class CommandInputArraySchema (object ):
124
+ '''
125
+ Based on the parameter set out in the CWL spec:
126
+ https://www.commonwl.org/v1.0/CommandLineTool.html#CommandInputArraySchema
127
+ '''
128
+
129
+ def __init__ (self , items = None , label = None , input_binding = None ):
130
+ '''
131
+ :param items: Defines the type of the array elements.
132
+ :type: `CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string | array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>`
133
+ :param label: A short, human-readable label of this object.
134
+ :type label: STRING
135
+ :param input_binding:
136
+ :type input_binding: CommandLineBinding
137
+ '''
138
+ self .type = "array"
139
+ self .items = parse_param_type (items )
140
+ self .label = label
141
+ self .inputBinding = input_binding
142
+
143
+ def get_dict (self ):
144
+ '''
145
+ Transform the object to a [DICT] to write CWL.
146
+
147
+ :return: dictionnary of the object
148
+ :rtype: DICT
149
+ '''
150
+ dict_binding = {k : v for k , v in vars (self ).items () if v is not None }
151
+ return dict_binding
152
+
0 commit comments