comparison env/lib/python3.9/site-packages/gxformat2/main.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Module containing :func:`convert_and_import_workflow`."""
2 import os
3
4 from .converter import python_to_workflow, yaml_to_workflow
5 from .interface import BioBlendImporterGalaxyInterface
6 from .yaml import ordered_load
7
8
9 def convert_and_import_workflow(has_workflow, **kwds):
10 """Conversion and import Format 2 workflows into a target Galaxy instance."""
11 galaxy_interface = kwds.get("galaxy_interface", None)
12 if galaxy_interface is None:
13 galaxy_interface = BioBlendImporterGalaxyInterface(**kwds)
14
15 source_type = kwds.get("source_type", None)
16 workflow_directory = kwds.get("workflow_directory", None)
17 if source_type == "path":
18 workflow_path = has_workflow
19 if workflow_directory is None:
20 workflow_directory = os.path.dirname(has_workflow)
21 with open(workflow_path, "r") as f:
22 has_workflow = ordered_load(f)
23
24 if workflow_directory is not None:
25 workflow_directory = os.path.abspath(workflow_directory)
26
27 convert = kwds.get("convert", True)
28 raw_yaml = kwds.get("raw_yaml", False)
29 if raw_yaml and convert:
30 raise Exception("Incompatible options selected.")
31 if convert:
32 if isinstance(has_workflow, dict):
33 workflow = python_to_workflow(has_workflow, galaxy_interface, workflow_directory)
34 else:
35 workflow = yaml_to_workflow(has_workflow, galaxy_interface, workflow_directory)
36 else:
37 workflow = has_workflow
38 if not isinstance(workflow, dict) and not raw_yaml:
39 workflow = ordered_load(workflow)
40 else:
41 workflow = {"yaml_content": workflow}
42
43 name = kwds.get("name", None)
44 if name is not None:
45 workflow["name"] = name
46 publish = kwds.get("publish", False)
47 exact_tools = kwds.get("exact_tools", False)
48 fill_defaults = kwds.get("fill_defaults", True)
49 import_kwds = {
50 "fill_defaults": fill_defaults
51 }
52 if publish:
53 import_kwds["publish"] = True
54 if exact_tools:
55 import_kwds["exact_tools"] = True
56 return galaxy_interface.import_workflow(workflow, **import_kwds)
57
58
59 __all__ = (
60 'convert_and_import_workflow',
61 )