Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes and refactorings #55

Merged
merged 4 commits into from May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions gxformat2/converter.py
Expand Up @@ -520,10 +520,10 @@ def __init__(self):

def step_id(self, label_or_id):
if label_or_id in self.labels:
id = self.labels[label_or_id]
id_ = self.labels[label_or_id]
else:
id = label_or_id
return int(id)
id_ = label_or_id
return int(id_)

def step_output(self, value):
value_parts = str(value).split("/")
Expand Down
66 changes: 31 additions & 35 deletions gxformat2/export.py
Expand Up @@ -14,33 +14,31 @@


def _copy_common_properties(from_native_step, to_format2_step):
annotation = from_native_step.get("annotation", "")
annotation = from_native_step.get("annotation")
if annotation:
to_format2_step["doc"] = annotation
position = from_native_step.get("position", None)
if position:
to_format2_step["position"] = position
when_exp = from_native_step.get("when", None)
if when_exp is not None:
to_format2_step["when"] = when_exp
for prop in ("position", "when"):
value = from_native_step.get(prop)
if value:
to_format2_step[prop] = value


def from_galaxy_native(format2_dict, tool_interface=None, json_wrapper=False):
def from_galaxy_native(native_workflow_dict, tool_interface=None, json_wrapper=False):
"""Convert native .ga workflow definition to a format2 workflow.

This is highly experimental and currently broken.
"""
data = OrderedDict()
data['class'] = 'GalaxyWorkflow'
_copy_common_properties(format2_dict, data)
if "name" in format2_dict:
data["label"] = format2_dict.pop("name")
_copy_common_properties(native_workflow_dict, data)
if "name" in native_workflow_dict:
data["label"] = native_workflow_dict.pop("name")
for top_level_key in ['tags', 'uuid', 'report']:
value = format2_dict.get(top_level_key)
value = native_workflow_dict.get(top_level_key)
if value:
data[top_level_key] = value

native_steps = format2_dict.get("steps")
native_steps = native_workflow_dict.get("steps")

label_map = {}
all_labeled = True
Expand Down Expand Up @@ -79,19 +77,17 @@ def from_galaxy_native(format2_dict, tool_interface=None, json_wrapper=False):
inputs[step_id] = input_dict["type"]
else:
inputs[step_id] = input_dict
continue

if module_type == "pause":
elif module_type == "pause":
step_dict = OrderedDict()
optional_props = ['label']
_copy_common_properties(step, step_dict)
_copy_properties(step, step_dict, optional_props=optional_props)
_convert_input_connections(step, step_dict, label_map)
step_dict["type"] = "pause"
steps.append(step_dict)
continue

if module_type == 'subworkflow':
elif module_type == 'subworkflow':
step_dict = OrderedDict()
optional_props = ['label']
_copy_common_properties(step, step_dict)
Expand All @@ -102,25 +98,25 @@ def from_galaxy_native(format2_dict, tool_interface=None, json_wrapper=False):
subworkflow = from_galaxy_native(subworkflow_native_dict, tool_interface=tool_interface, json_wrapper=False)
step_dict["run"] = subworkflow
steps.append(step_dict)
continue

if module_type != 'tool':
raise NotImplementedError("Unhandled module type %s" % module_type)
elif module_type == 'tool':
step_dict = OrderedDict()
optional_props = ['label', 'tool_shed_repository']
required_props = ['tool_id', 'tool_version']
_copy_properties(step, step_dict, optional_props, required_props)
_copy_common_properties(step, step_dict)

step_dict = OrderedDict()
optional_props = ['label', 'tool_shed_repository']
required_props = ['tool_id', 'tool_version']
_copy_properties(step, step_dict, optional_props, required_props)
_copy_common_properties(step, step_dict)
tool_state = _tool_state(step)
tool_state.pop("__page__", None)
tool_state.pop("__rerun_remap_job_id__", None)
step_dict['tool_state'] = tool_state

tool_state = _tool_state(step)
tool_state.pop("__page__", None)
tool_state.pop("__rerun_remap_job_id__", None)
step_dict['tool_state'] = tool_state
_convert_input_connections(step, step_dict, label_map)
_convert_post_job_actions(step, step_dict)
steps.append(step_dict)

_convert_input_connections(step, step_dict, label_map)
_convert_post_job_actions(step, step_dict)
steps.append(step_dict)
else:
raise NotImplementedError(f"Unhandled module type {module_type}")

data['inputs'] = inputs
data['outputs'] = outputs
Expand All @@ -147,12 +143,12 @@ def _tool_state(step):
return tool_state


def _copy_properties(from_native_step, to_format2_step, optional_props=[], required_props=[]):
for prop in optional_props:
def _copy_properties(from_native_step, to_format2_step, optional_props=None, required_props=None):
for prop in optional_props or []:
value = from_native_step.get(prop)
if value:
to_format2_step[prop] = value
for prop in required_props:
for prop in required_props or []:
value = from_native_step.get(prop)
to_format2_step[prop] = value

Expand Down