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

Planemo command to convert format 2 workflows into .ga workflows. #771

Merged
merged 2 commits into from Feb 24, 2018
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
53 changes: 53 additions & 0 deletions planemo/commands/cmd_workflow_convert.py
@@ -0,0 +1,53 @@
"""Module describing the planemo ``workflow_convert`` command."""
import json
import os

import click


from planemo import options
from planemo.cli import command_function
from planemo.config import planemo_option
from planemo.engine import (
engine_context,
is_galaxy_engine,
)
from planemo.io import write_file
from planemo.runnable import (
for_path,
)


@click.command('workflow_convert')
@options.required_workflow_arg()
@options.force_option()
@planemo_option(
"-o", "--output",
default=None,
type=click.Path(
file_okay=True,
dir_okay=False,
readable=True,
resolve_path=True,
)
)
@options.galaxy_serve_options()
@command_function
def cli(ctx, workflow_path, output=None, force=False, **kwds):
"""Convert Format 2 workflow to a native Galaxy workflow.
"""
assert is_galaxy_engine(**kwds)

kwds["no_dependency_resolution"] = True

if output is None:
output = os.path.splitext(workflow_path)[0] + ".ga"

runnable = for_path(workflow_path)
with engine_context(ctx, **kwds) as galaxy_engine:
with galaxy_engine.serve_runnables([runnable]) as config:
workflow_id = config.workflow_id(workflow_path)
output_dict = config.gi.workflows.export_workflow_dict(workflow_id)

output_contents = json.dumps(output_dict)
write_file(output, output_contents, force=force)
2 changes: 1 addition & 1 deletion planemo/engine/factory.py
Expand Up @@ -12,7 +12,7 @@
def is_galaxy_engine(**kwds):
"""Return True iff the engine configured is :class:`GalaxyEngine`."""
engine_type_str = kwds.get("engine", "galaxy")
return engine_type_str == "galaxy"
return engine_type_str in ["galaxy", "docker_galaxy"]


def build_engine(ctx, **kwds):
Expand Down
6 changes: 4 additions & 2 deletions planemo/engine/galaxy.py
Expand Up @@ -24,14 +24,16 @@ class GalaxyEngine(BaseEngine):
def _run(self, runnable, job_path):
"""Run CWL job in Galaxy."""
self._ctx.vlog("Serving artifact [%s] with Galaxy." % (runnable,))
with self._serve([runnable]) as config:
with self.serve_runnables([runnable]) as config:
self._ctx.vlog("Running job path [%s]" % job_path)
run_response = execute(self._ctx, config, runnable, job_path, **self._kwds)

return run_response

@contextlib.contextmanager
def _serve(self, runnables):
def serve_runnables(self, runnables):
# TODO: define an interface for this - not everything in config would make sense for a
# pre-existing Galaxy interface.
with serve_daemon(self._ctx, runnables, **self._serve_kwds()) as config:
yield config

Expand Down
3 changes: 0 additions & 3 deletions planemo/engine/interface.py
Expand Up @@ -16,9 +16,6 @@

class Engine(object):
"""Abstract description of an external process for running tools or workflows.

Currently there are only two engines - Galaxy and cwltool - but ideally
there would be more.
"""

__metaclass__ = abc.ABCMeta
Expand Down
45 changes: 42 additions & 3 deletions planemo/galaxy/config.py
Expand Up @@ -585,11 +585,50 @@ def _config_directory(ctx, **kwds):


@add_metaclass(abc.ABCMeta)
class GalaxyConfig(object):
class GalaxyInterface(object):
"""Abstraction around a Galaxy instance.

This requires more than just an API connection and assumes access to files
etc....
Description of a Galaxy instance and how to interact with it - this could
potentially be a remote, already running instance or an instance Planemo manages
to execute some task(s).
"""

@abc.abstractproperty
def gi(self):
"""Return an admin bioblend Galaxy instance for API interactions."""

@abc.abstractproperty
def user_gi(self):
"""Return a user-backed bioblend Galaxy instance for API interactions."""

@abc.abstractmethod
def install_repo(self, *args, **kwds):
"""Install specified tool shed repository."""

@abc.abstractproperty
def tool_shed_client(self):
"""Return a admin bioblend tool shed client."""

@abc.abstractmethod
def wait_for_all_installed(self):
"""Wait for all queued up repositories installs to complete."""

@abc.abstractmethod
def install_workflows(self):
"""Install all workflows configured with these planemo arguments."""

@abc.abstractmethod
def workflow_id(self, path):
"""Get installed workflow API ID for input path."""


@add_metaclass(abc.ABCMeta)
class GalaxyConfig(GalaxyInterface):
"""Specialization of GalaxyInterface for Galaxy instances Planemo manages itself.

This assumes more than an API connection is available - Planemo needs to be able to
start and stop the Galaxy instance, recover logs, etc... There are currently two
implementations - a locally executed Galaxy and one running inside a Docker containe
"""

@abc.abstractproperty
Expand Down
13 changes: 12 additions & 1 deletion planemo/options.py
Expand Up @@ -534,8 +534,19 @@ def required_tool_arg(allow_uris=False):
return click.argument(name, metavar=metavar, type=arg_type)


def required_workflow_arg():
arg_type = click.Path(
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
resolve_path=False,
)
return click.argument("workflow_path", metavar="WORKFLOW_PATH", type=arg_type)


def required_job_arg():
""" Decorate click method as requiring the path to a single tool.
"""Decorate click method as requiring the path to a single tool.
"""
arg_type = click.Path(
exists=True,
Expand Down