8000 add import feature to load existing CWL tool content into the model · illusional/python-cwlgen@82aa905 · GitHub
[go: up one dir, main page]

Sk 8000 ip to content

Commit 82aa905

Browse files
committed
add import feature to load existing CWL tool content into the model
1 parent 161041e commit 82aa905

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

cwlgen/import_cwl.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'''
2+
Library to handle the manipulation and generation of CWL tool
3+
'''
4+
5+
# Import ------------------------------
6+
7+
# General libraries
8+
import os
9+
import argparse
10+
import sys
11+
import logging
12+
13+
# External libraries
14+
import ruamel.yaml as ryaml
15+
import six
16+
import cwlgen
17+
18+
logging.basicConfig(level=logging.INFO)
19+
logger = logging.getLogger(__name__)
20+
21+
# Class(es) ------------------------------
22+
23+
class CWLToolParser(object):
24+
"""
25+
Class to import content from an existing CWL Tool.
26+
"""
27+
28+
def _init_tool(self, cwl_dict):
29+
"""
30+
Init tool from existing CWL tool.
31+
32+
:param cwl_dict: Full content of CWL file
33+
:type cwl_dict: DICT
34+
"""
35+
tool = cwlgen.CommandLineTool(tool_id=cwl_dict.get('id', None),
36+
base_command=cwl_dict.get('baseCommand', None),
37+
label=cwl_dict.get('label', None),
38+
doc=cwl_dict.get('doc', None),
39+
cwl_version=cwl_dict.get('cwlVersion', None),
40+
stdin=cwl_dict.get('stdin', None),
41+
stderr=cwl_dict.get('stderr', None),
42+
stdout=cwl_dict.get('stdout', None))
43+
return tool
44+
45+
def import_cwl(self, cwl_path):
46+
"""
47+
Load content of cwl into the :class:`cwlgen.CommandLineTool` object.
48+
49+
:param cwl_path: Path of the CWL tool to be loaded.
50+
:type cwl_path: STRING
51+
:return: CWL tool content in cwlgen model.
52+
:rtype: :class:`cwlgen.CommandLineTool`
53+
"""
54+
with open(cwl_path) as yaml_file:
55+
cwl_dict = ryaml.load(yaml_file, Loader=ryaml.Loader)
56+
tool = self._init_tool(cwl_dict)
57+
for key in cwl_dict.keys():
58+
try:
59+
getattr(self, '_load_{}'.format(key))(tool, cwl_dict[key])
60+
except:
61+
logger.warning(key + " is not processed.")
62+
return tool

0 commit comments

Comments
 (0)
0