File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 4848python docker_extract.py --singularity DIRECTORY path_to_my_workflow.cwl
4949```
5050
51+ ### Using the CWL Parsers
52+
53+ ``` python
54+ # Imports
55+ from pathlib import Path
56+ from ruamel import yaml
57+ import sys
58+
59+ # File Input - This is the only thing you will need to adjust or take in as an input to your function:
60+ cwl_file = Path(" /path/to/wf.cwl" )
61+
62+ # Read in the cwl file from a yaml
63+ with open (cwl_file, " r" ) as cwl_h:
64+ yaml_obj = yaml.main.round_trip_load(cwl_h, preserve_quotes = True )
65+
66+ # Check CWLVersion
67+ if ' cwlVersion' not in list (yaml_obj.keys()):
68+ print (" Error - could not get the cwlVersion" )
69+ sys.exit(1 )
70+
71+ # Import parser based on CWL Version
72+ if yaml_obj[' cwlVersion' ] == ' v1.0' :
73+ from cwl_utils import parser_v1_0 as parser
74+ elif yaml_obj[' cwlVersion' ] == ' v1.1' :
75+ from cwl_utils import parser_v1_1 as parser
76+ elif yaml_obj[' cwlVersion' ] == ' v1.2' :
77+ from cwl_utils import parser_v1_2 as parser
78+ else :
79+ print (" Version error. Did not recognise {} as a CWL version" .format(yaml_obj[" CWLVersion" ]))
80+ sys.exit(1 )
81+
82+ # Import CWL Object
83+ cwl_obj = parser.load_document_by_yaml(yaml_obj, cwl_file.as_uri())
84+
85+ # View CWL Object
86+ print (" List of object attributes:\n {} " .format(" \n " .join(map (str , dir (cwl_obj)))))
87+ ```
88+
5189## Development
5290
5391### Regenerate parsers
You can’t perform that action at this time.
0 commit comments