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

Addition of metadata generation for planemo run #1434

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/commands/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Planemo command for running tools and jobs.
Where to store outputs of a 'run' task.
--output_json FILE Where to store JSON dictionary describing
outputs of a 'run' task.
--output_metadata FILE Where to store JSON dictionary describing
the metadata of a 'run' task.
--download_outputs / --no_download_outputs
After tool or workflow runs are complete,
download the output files to the location
Expand Down
1 change: 1 addition & 0 deletions planemo/commands/cmd_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@options.run_history_tags_option()
@options.run_output_directory_option()
@options.run_output_json_option()
@options.run_output_metadata_option()
@options.run_download_outputs_option()
@options.engine_options()
@options.test_options()
Expand Down
11 changes: 11 additions & 0 deletions planemo/galaxy/activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module provides generic interface to running Galaxy tools and workflows."""

import json
import os
import sys
import tempfile
Expand Down Expand Up @@ -216,6 +217,16 @@ def _execute( # noqa C901
start_datetime=start_datetime,
log=log_contents_str(config),
)
if kwds["engine"] == "galaxy" or kwds["engine"] == "external_galaxy":
output_metadata = kwds.get("output_metadata", None)
if output_metadata:
run_infos = {
"history_id": history_id,
"invocation_id": invocation["id"],
"workflow_id": workflow_id,
}
with open(output_metadata, "w") as f:
json.dump(run_infos, f)

else:
raise NotImplementedError()
Expand Down
14 changes: 14 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ def run_output_directory_option():
)


def run_output_metadata_option():
return planemo_option(
"output_metadata",
"--output_metadata",
type=click.Path(
file_okay=True,
dir_okay=False,
resolve_path=True,
),
default=None,
help=("Where to store JSON dictionary describing the metadata of " "a workflow 'run' task."),
)


def run_output_json_option():
return planemo_option(
"output_json",
Expand Down
100 changes: 100 additions & 0 deletions tests/data/first_lines.ga
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"a_galaxy_workflow": "true",
"annotation": "",
"comments": [],
"format-version": "0.1",
"name": "Testing",
"report": {
"markdown": "\n# Workflow Execution Report\n\n## Workflow Inputs\n```galaxy\ninvocation_inputs()\n```\n\n## Workflow Outputs\n```galaxy\ninvocation_outputs()\n```\n\r\n```galaxy\nhistory_dataset_peek(output=\"Truncated file\")\n```\r\n\n\n## Workflow\n```galaxy\nworkflow_display()\n```\n"
},
"steps": {
"0": {
"annotation": "",
"content_id": null,
"errors": null,
"id": 0,
"input_connections": {},
"inputs": [
{
"description": "",
"name": "File to head"
}
],
"label": "File to head",
"name": "Input dataset",
"outputs": [],
"position": {
"left": 0,
"top": 0
},
"tool_id": null,
"tool_state": "{\"optional\": false, \"tag\": null}",
"tool_version": null,
"type": "data_input",
"uuid": "6cada1bd-e96e-43d2-a41b-2f396c9ad2ca",
"when": null,
"workflow_outputs": []
},
"1": {
"annotation": "",
"content_id": "toolshed.g2.bx.psu.edu/repos/bgruening/text_processing/tp_head_tool/1.1.0",
"errors": null,
"id": 1,
"input_connections": {
"infile": {
"id": 0,
"output_name": "output"
}
},
"inputs": [
{
"description": "runtime parameter for tool Select first",
"name": "infile"
}
],
"label": null,
"name": "Select first",
"outputs": [
{
"name": "outfile",
"type": "input"
}
],
"position": {
"left": 296.265625,
"top": 57.5703125
},
"post_job_actions": {
"RenameDatasetActionoutfile": {
"action_arguments": {
"newname": "Truncated_file"
},
"action_type": "RenameDatasetAction",
"output_name": "outfile"
}
},
"tool_id": "toolshed.g2.bx.psu.edu/repos/bgruening/text_processing/tp_head_tool/1.1.0",
"tool_shed_repository": {
"changeset_revision": "ddf54b12c295",
"name": "text_processing",
"owner": "bgruening",
"tool_shed": "toolshed.g2.bx.psu.edu"
},
"tool_state": "{\"complement\": \"\", \"count\": \"3\", \"infile\": {\"__class__\": \"ConnectedValue\"}, \"__page__\": null, \"__rerun_remap_job_id__\": null}",
"tool_version": "1.1.0",
"type": "tool",
"uuid": "97a55f13-2d30-4ecd-a3fb-d8d433d3b3bb",
"when": null,
"workflow_outputs": [
{
"label": "Truncated file",
"output_name": "outfile",
"uuid": "61afcb1c-d26e-4a98-988f-a73fbb074d0c"
}
]
}
},
"tags": [],
"uuid": "1649a361-0381-444c-bdb6-b099609f7f62",
"version": 4
}
3 changes: 3 additions & 0 deletions tests/data/first_lines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
File to head:
class: File
path: hello.txt
23 changes: 23 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,26 @@ def test_run_output_directory(self):
assert os.path.exists(output_path)
with open(output_path) as fh:
assert fh.read().startswith(" 16 198 1111")

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_run_metadata(self):
with self._isolate() as f:
workflow_path = os.path.join(TEST_DATA_DIR, "first_lines.ga")
job_path = os.path.join(TEST_DATA_DIR, "first_lines.yml")
info_path = os.path.join(f, "run_info.json")
test_cmd = [
"--verbose",
"run",
workflow_path,
job_path,
"--no_dependency_resolution",
"--galaxy_branch",
target_galaxy_branch(),
"--no_wait",
"--output_metadata",
info_path,
"--test_data",
TEST_DATA_DIR,
]
self._check_exit_code(test_cmd)
assert os.path.exists(os.path.join(f, "run_info.json"))
Loading