8000 modified attributes from class to correspond exactly to names from CW… · phenoflow/python-cwlgen@d89becb · GitHub
[go: up one dir, main page]

Skip to content

Commit d89becb

Browse files
committed
modified attributes from class to correspond exactly to names from CWL CommandLineTool
1 parent cd5198f commit d89becb

File tree

4 files changed

+96
-122
lines changed

4 files changed

+96
-122
lines changed

cwlgen/__init__.py

Lines changed: 54 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
import os
99
import argparse
1010
import sys
11+
import logging
1112

1213
# External libraries
1314
import ruamel.yaml
1415
import six
1516
from .version import __version__
1617

18+
logging.basicConfig(level=logging.INFO)
19+
LOGGER = logging.getLogger(__name__)
20+
1721
########### Constant(s) ###########
1822

1923
CWL_SHEBANG = "#!/usr/bin/env cwl-runner"
20-
DEF_CWL_VERSION = 'v1.0'
24+
CWL_VERSIONS = ['draft-2', 'draft-3.dev1', 'draft-3.dev2', 'draft-3.dev3',
25+
'draft-3.dev4', 'draft-3.dev5', 'draft-3', 'draft-4.dev1',
26+
'draft-4.dev2', 'draft-4.dev3', 'v1.0.dev4', 'v1.0', None]
2127
CWL_TYPE = ['null', 'boolean', 'int', 'long', 'float', 'double', 'string', 'File',
2228
'Directory', None]
2329

@@ -31,7 +37,7 @@ class CommandLineTool(object):
3137
'''
3238

3339
def __init__(self, tool_id=None, base_command=None, label=None, doc=None,\
34-
cwl_version=DEF_CWL_VERSION, stdin=None, stderr=None, stdout=None):
40+
cwl_version=None, stdin=None, stderr=None, stdout=None):
3541
'''
3642
:param tool_id: unique identifier for this tool.
3743
:type tool_id: STRING
@@ -56,35 +62,32 @@ def __init__(self, tool_id=None, base_command=None, label=None, doc=None,\
5662
and requirements (:class:`cwlgen.Requirement` objects)
5763
are stored in lists which are initialized empty.
5864
'''
59-
self.tool_id = tool_id
60-
self.base_command = base_command
65+
self.id = tool_id
66+
self.baseCommand = base_command
6167
self.label = label
6268
self.doc = doc
63-
self.cwl_version = cwl_version
69+
if not cwl_version in CWL_VERSIONS:
70+
LOGGER.warning("CWL version is not recognized as a valid version.")
71+
cwl_version = None
72+
self.cwlVersion = cwl_version
6473
self.stdin = stdin
6574
self.stderr = stderr
6675
self.stdout = stdout
67-
self.inputs = [] # List of [CommandInputParameter] objects
68-
self.outputs = [] # List of [CommandOutputParameter] objects
69-
self.arguments = [] # List of [CommandLineBinding] objects
70-
self.requirements = [] # List of Several object inhereting from [Requirement]
76+
self.inputs = [] # List of [CommandInputParameter] objects
77+
self.outputs = [] # List of [CommandOutputParameter] objects
78+
self.arguments = [] # List of [CommandLineBinding] objects
79+
self.requirements = [] # List of Several object inhereting from [Requirement]
7180
self.hints = []
72-
self.success_codes = []
73-
self.temporary_fail_codes = []
74-
self.permanent_fail_codes = []
81+
self.successCodes = []
82+
self.temporaryFailCodes = []
83+
self.permanentFailCodes = []
7584

7685
def export(self, outfile=None):
7786
'''
7887
Export the tool in CWL either on STDOUT or in outfile
7988
'''
80-
cwl_tool = {}
81-
cwl_tool['cwlVersion'] = self.cwl_version
82-
cwl_tool['id'] = self.tool_id
83-
cwl_tool['label'] = self.label
84-
cwl_tool['baseCommand'] = self.base_command
89+
cwl_tool = {k:v for k,v in vars(self).items() if v is not None and v != []}
8590
cwl_tool['class'] = 'CommandLineTool'
86-
if self.doc is not None:
87-
cwl_tool['doc'] = self.doc
8891
# Add Inputs
8992
if self.inputs:
9093
cwl_tool['inputs'] = {}
@@ -127,11 +130,11 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
127130
param_type: type of data assigned to the parameter [STRING] corresponding to CWLType
128131
'''
129132
if not param_type in CWL_TYPE:
130-
print("The type is incorrect for the parameter")
131-
return 1
133+
LOGGER.warning("The type is incorrect for the parameter")
134+
param_type = None
132135
self.id = param_id
133136
self.label = label
134-
self.secondary_files = secondary_files
137+
self.secondaryFiles = secondary_files
135138
self.format = param_format
136139
self.streamable = streamable
137140
self.doc = doc
@@ -144,20 +147,14 @@ def get_dict(self):
144147
:return: dictionnary of the object
145148
:rtype: DICT
146149
'''
147-
dict_param = {}
148-
if self.type:
149-
dict_param['type'] = self.type
150-
if self.doc:
151-
dict_param['doc'] = self.doc
152-
if self.label:
153-
dict_param['label'] = self.label
154-
if self.type == 'File':
155-
if self.format:
156-
dict_param['format'] = self.format
157-
if self.secondary_files:
158-
dict_param['secondaryFiles'] = self.secondary_files
159-
if self.streamable:
160-
dict_param['streamable'] = self.streamable
150+
dict_param = {k:v for k,v in vars(self).items() if v is not None and v is not False}
151+
if dict_param['type'] != 'File':
152+
# Remove what is only for File
153+
for key in ['format', 'secondaryFiles', 'streamable']:
154+
try:
155+
del(dict_param[key])
156+
except KeyError:
157+
pass
161158
return dict_param
162159

163160

@@ -193,7 +190,7 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
193190
Parameter.__init__(self, param_id=param_id, label=label, \
194191
secondary_files=secondary_files, param_format=param_format,\
195192
streamable=streamable, doc=doc, param_type=param_type)
196-
self.input_binding = input_binding
193+
self.inputBinding = input_binding
197194
self.default = default
198195

199196
def get_dict(self):
@@ -204,10 +201,8 @@ def get_dict(self):
204201
:rtype: DICT
205202
'''
206203
dict_in = Parameter.get_dict(self)
207-
if self.default:
208-
dict_in['default'] = self.default
209-
if self.input_binding:
210-
dict_in['inputBinding'] = self.input_binding.get_dict()
204+
if self.inputBinding:
205+
dict_in['inputBinding'] = self.inputBinding.get_dict()
211206
return dict_in
212207

213208

@@ -240,7 +235,7 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
240235
'''
241236
Parameter.__init__(self, param_id, label, secondary_files, param_format, streamable,\
242237
doc, param_type)
243-
self.output_binding = output_binding
238+
self.outputBinding = output_binding
244239

245240
def get_dict(self):
246241
'''
@@ -250,8 +245,8 @@ def get_dict(self):
250245
:rtype: DICT
251246
'''
252247
dict_out = Parameter.get_dict(self)
253-
if self.output_binding:
254-
dict_out['outputBinding'] = self.output_binding.get_dict()
248+
if self.outputBinding:
249+
dict_out['outputBinding'] = self.outputBinding.get_dict()
255250
return dict_out
256251

257252

@@ -278,13 +273,13 @@ def __init__(self, load_contents=False, position=None, prefix=None, separate=Fal
278273
:param shell_quote:
279274
:type shell_quote: BOOLEAN
280275
'''
281-
self.load_contents = load_contents
276+
self.loadContents = load_contents
282277
self.position = position
283278
self.prefix = prefix
284279
self.separate = separate
285-
self.item_separator = item_separator
286-
self.value_from = value_from
287-
self.shell_quote = shell_quote
280+
self.itemSeparator = item_separator
281+
self.valueFrom = value_from
282+
self.shellQuote = shell_quote
288283

289284
def get_dict(self):
290285
'''
@@ -293,22 +288,7 @@ def get_dict(self):
293288
:return: dictionnary of the object
294289
:rtype: DICT
295290
'''
296-
dict_binding = {}
297-
if self.load_contents:
298-
# Does not take care if type: File for the moment
299-
dict_binding['loadContents'] = self.load_contents
300-
if self.position:
301-
dict_binding['position'] = self.position
302-
if self.prefix:
303-
dict_binding['prefix'] = self.prefix
304-
if self.separate:
305-
dict_binding['separate'] = self.separate
306-
if self.item_separator:
307-
dict_binding['itemSeparator'] = self.item_separator
308-
if self.value_from:
309-
dict_binding['valueFrom'] = self.value_from
310-
if self.shell_quote:
311-
dict_binding['shellQuote'] = self.shell_quote
291+
dict_binding = {k:v for k,v in vars(self).items() if v is not None and v is not False}
312292
return dict_binding
313293

314294

@@ -328,8 +308,8 @@ def __init__(self, glob=False, load_contents=False, output_eval=None):
328308
:type output_eval: STRING
329309
'''
330310
self.glob = glob
331-
self.load_contents = load_contents
332-
self.output_eval = output_eval
311+
self.loadContents = load_contents
312+
self.outputEval = output_eval
333313

334314
def get_dict(self):
335315
'''
@@ -338,13 +318,7 @@ def get_dict(self):
338318
:return: dictionnary of the object
339319
:rtype: DICT
340320
'''
341-
dict_binding = {}
342-
if self.glob:
343-
dict_binding['glob'] = self.glob
344-
if self.load_contents:
345-
dict_binding['loadContents'] = self.load_contents
346-
if self.output_eval:
347-
dict_binding['outputEval'] = self.output_eval
321+
dict_binding = {k:v for k,v in vars(self).items() if v is not None and v is not False}
348322
return dict_binding
349323

350324

@@ -372,7 +346,7 @@ def __init__(self, expression_lib=None):
372346
:type expression_lib: STRING
373347
'''
374348
Requirement.__init__(self, 'InlineJavascriptRequirement')
375-
self.expression_lib = expression_lib
349+
self.expressionLib = expression_lib
376350

377351

378352
class DockerRequirement(Requirement):
@@ -398,9 +372,9 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,\
398372
:type docker_output_dir: STRING
399373
'''
400374
Requirement.__init__(self, 'DockerRequirement')
401-
self.docker_pull = docker_pull
402-
self.docker_load = docker_load
403-
self.docker_file = docker_file
404-
self.docker_import = docker_import
405-
self.docker_image_id = docker_image_id
406-
self.docker_output_dir = docker_output_dir
375+
self.dockerPull = docker_pull
376+
self.dockerLoad = docker_load
377+
self.dockerFile = docker_file
378+
self.dockerImport = docker_import
379+
self.dockerImageId = docker_image_id
380+
self.dockerOutputDir = docker_output_dir

cwlgen/import_cwl.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _load_id(self, tool, id_el):
4444
:param id_el: Content of id
4545
:type id_el: STRING or [STRING]
4646
"""
47-
tool.tool_id = id_el
47+
tool.id = id_el
4848

4949
def _load_baseCommand(self, tool, command_el):
5050
"""
@@ -55,7 +55,7 @@ def _load_baseCommand(self, tool, command_el):
5555
:param command_el: Content of baseCommand
5656
:type command_el: STRING
5757
"""
58-
tool.base_command = command_el
58+
tool.baseCommand = command_el
5959

6060
def _load_label(self, tool, label_el):
6161
"""
@@ -88,7 +88,7 @@ def _load_cwlVersion(self, tool, cwl_version_el):
8888
:param cwl_version_el: Content of cwlVersion
8989
:type cwl_version_el: STRING
9090
"""
91-
tool.cwl_version = cwl_version_el
91+
tool.cwlVersion = cwl_version_el
9292

9393
def _load_stdin(self, tool, stdin_el):
9494
"""
@@ -204,7 +204,7 @@ def _load_secondaryFiles(self, input_obj, secfile_el):
204204
:param secfile_el: Content of secondaryFile
205205
:type secfile_el: STRING
206206
"""
207-
input_obj.secondary_file = secfile_el
207+
input_obj.secondaryFile = secfile_el
208208

209209
def _load_format(self, input_obj, format_el):
210210
"""
@@ -307,7 +307,7 @@ def _load_loadContents(self, inbinding_obj, loadcontents_el):
307307
:param loadcontents_el: Content of loadContents
308308
:loadContents loadcontents_el: BOOLEAN
309309
"""
310-
inbinding_obj.load_contents = loadcontents_el
310+
inbinding_obj.loadContents = loadcontents_el
311311

312312
def _load_position(self, inbinding_obj, position_el):
313313
"""
@@ -351,7 +351,7 @@ def _load_itemSeparator(self, inbinding_obj, itemsep_el):
351351
:param itemsep_el: Content of loadContents
352352
:loadContents itemsep_el: STRING
353353
"""
354-
inbinding_obj.item_separator = itemsep_el
354+
inbinding_obj.itemSeparator = itemsep_el
355355

356356
def _load_valueFrom(self, inbinding_obj, valuefrom_el):
357357
"""
@@ -362,7 +362,7 @@ def _load_valueFrom(self, inbinding_obj, valuefrom_el):
362362
:param valuefrom_el: Content of loadContents
363363
:loadContents valuefrom_el: STRING
364364
"""
365-
inbinding_obj.value_from = valuefrom_el
365+
inbinding_obj.valueFrom = valuefrom_el
366366

367367
def _load_shellQuote(self, inbinding_obj, shellquote_el):
368368
"""
@@ -373,7 +373,7 @@ def _load_shellQuote(self, inbinding_obj, shellquote_el):
373373
:param shellquote_el: Content of loadContents
374374
:loadContents shellquote_el: BOOLEAN
375375
"""
376-
inbinding_obj.shell_quote = shellquote_el
376+
inbinding_obj.shellQuote = shellquote_el
377377

378378
def load_inbinding(self, input_obj, inbinding_el):
379379
"""
@@ -390,7 +390,7 @@ def load_inbinding(self, input_obj, inbinding_el):
390390
getattr(self, '_load_{}'.format(key))(inbinding_obj, value)
391391
except AttributeError:
392392
logger.warning(key + " content for inputBinding is not processed (yet).")
393-
input_obj.input_binding = inbinding_obj
393+
input_obj.inputBinding = inbinding_obj
394394

395395

396396
class OutputsParser(object):
@@ -418,7 +418,7 @@ def _load_secondaryFiles(self, output_obj, secfile_el):
418418
:param secfile_el: Content of secondaryFile
419419
:type secfile_el: STRING
420420
"""
421-
output_obj.secondary_file = secfile_el
421+
output_obj.secondaryFile = secfile_el
422422

423423
def _load_format(self, output_obj, format_el):
424424
"""

0 commit comments

Comments
 (0)
0