-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Optional | ||
|
||
import yaml | ||
from gxformat2 import ( | ||
from_galaxy_native, | ||
ImporterGalaxyInterface, | ||
ImportOptions, | ||
python_to_workflow, | ||
) | ||
|
||
from galaxy.exceptions import MalformedContents | ||
|
||
|
||
def convert_to_format2(as_dict, json_wrapper: bool): | ||
return from_galaxy_native(as_dict, None, json_wrapper=json_wrapper) | ||
|
||
|
||
def convert_from_format2(as_dict, workflow_directory: Optional[str]): | ||
# Format 2 Galaxy workflow. | ||
galaxy_interface = Format2ConverterGalaxyInterface() | ||
import_options = ImportOptions() | ||
import_options.deduplicate_subworkflows = True | ||
try: | ||
as_dict = python_to_workflow( | ||
as_dict, galaxy_interface, workflow_directory=workflow_directory, import_options=import_options | ||
) | ||
except yaml.scanner.ScannerError as e: | ||
raise MalformedContents(str(e)) | ||
return as_dict | ||
|
||
|
||
class Format2ConverterGalaxyInterface(ImporterGalaxyInterface): | ||
def import_workflow(self, workflow, **kwds): | ||
raise NotImplementedError( | ||
"Direct format 2 import of nested workflows is not yet implemented, use bioblend client." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from galaxy.workflow.format2 import ( | ||
convert_from_format2, | ||
convert_to_format2, | ||
) | ||
|
||
WORKFLOW_WITH_OUTPUTS = """ | ||
class: GalaxyWorkflow | ||
inputs: | ||
input1: data | ||
outputs: | ||
wf_output_1: | ||
outputSource: first_cat/out_file1 | ||
steps: | ||
first_cat: | ||
tool_id: cat1 | ||
in: | ||
input1: input1 | ||
queries_0|input2: input1 | ||
""" | ||
|
||
|
||
def test_convert_from_simple(): | ||
as_dict = {"yaml_content": WORKFLOW_WITH_OUTPUTS} | ||
ga_format = convert_from_format2(as_dict, None) | ||
assert ga_format["a_galaxy_workflow"] == "true" | ||
assert ga_format["format-version"] == "0.1" | ||
|
||
|
||
def test_convert_to_simple(): | ||
as_dict = {"yaml_content": WORKFLOW_WITH_OUTPUTS} | ||
ga_format = convert_from_format2(as_dict, None) | ||
|
||
as_dict = convert_to_format2(ga_format, True) | ||
assert "yaml_content" in as_dict | ||
assert "yaml_content" not in as_dict |