Skip to content

Commit

Permalink
array outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Apr 2, 2020
1 parent 85aa142 commit 4f64972
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 12 deletions.
22 changes: 15 additions & 7 deletions cwlkernel/CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,21 @@ def _execute_workflow(self, code) -> Optional[Exception]:
logger.debug(f'\texecution results: {run_id}, {results}, {stdout}, {stderr}, {exception}')
output_directory_for_that_run = str(run_id)
for output in results:
logger.info(f'output result: {results}')
results[output]['id'] = output
self._results_manager.append_files(
[results[output]['location']],
output_directory_for_that_run,
metadata=results[output]
)
if isinstance(results[output], list):
for i, output_i in enumerate(results[output]):
results[output][i]['id'] = f'{output}_{i+1}'
self._results_manager.append_files(
[results[output][i]['location']],
output_directory_for_that_run,
metadata=results[output][i]
)
else:
results[output]['id'] = output
self._results_manager.append_files(
[results[output]['location']],
output_directory_for_that_run,
metadata=results[output]
)
self.send_response(
self.iopub_socket,
'display_data',
Expand Down
76 changes: 71 additions & 5 deletions examples/array_outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## [Array Outputs](https://www.commonwl.org/user_guide/10-array-outputs/index.html)\n",
"\n",
"Not supported yet"
"## [Array Outputs](https://www.commonwl.org/user_guide/10-array-outputs/index.html)"
]
},
{
Expand All @@ -38,9 +36,50 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/json": {
"output": [
{
"basename": "baz.txt",
"checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
"class": "File",
"http://commonwl.org/cwltool#generation": 0,
"id": "output_1",
"location": "file:///private/tmp/CWLKERNEL_DATA/runtime_data/baz.txt",
"nameext": ".txt",
"nameroot": "baz",
"size": 0
},
{
"basename": "foo.txt",
"checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
"class": "File",
"http://commonwl.org/cwltool#generation": 0,
"id": "output_2",
"location": "file:///private/tmp/CWLKERNEL_DATA/runtime_data/foo.txt",
"nameext": ".txt",
"nameroot": "foo",
"size": 0
}
]
},
"text/plain": [
"<IPython.core.display.JSON object>"
]
},
"metadata": {
"application/json": {
"expanded": false,
"root": "root"
}
},
"output_type": "display_data"
}
],
"source": [
"#!/usr/bin/env cwl-runner\n",
"\n",
Expand All @@ -62,6 +101,33 @@
" outputBinding:\n",
" glob: \"*.txt\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ul>\n",
"\t<li><a href=\"file:///private/tmp/CWLKERNEL_DATA/results/d79b3512-f8b5-4f59-b3c0-40834c9dc58a/baz.txt\" target=\"_empty\">/private/tmp/CWLKERNEL_DATA/results/d79b3512-f8b5-4f59-b3c0-40834c9dc58a/baz.txt</a></li>\n",
"\t<li><a href=\"file:///private/tmp/CWLKERNEL_DATA/results/d79b3512-f8b5-4f59-b3c0-40834c9dc58a/foo.txt\" target=\"_empty\">/private/tmp/CWLKERNEL_DATA/results/d79b3512-f8b5-4f59-b3c0-40834c9dc58a/foo.txt</a></li>\n",
"</ul>"
]
},
"metadata": {
"application/json": {
"expanded": false,
"root": "root"
}
},
"output_type": "display_data"
}
],
"source": [
"% data"
]
}
],
"metadata": {
Expand Down
19 changes: 19 additions & 0 deletions tests/cwl/array-outputs.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
baseCommand: touch
inputs:
touchfiles:
type:
type: array
items: string
inputBinding:
position: 1
outputs:
output:
type:
type: array
items: File
outputBinding:
glob: "*.txt"
5 changes: 5 additions & 0 deletions tests/input_data/array-outputs-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
touchfiles:
- foo.txt
- bar.dat
- baz.txt

20 changes: 20 additions & 0 deletions tests/test_CWLKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,25 @@ def test_display_json_output_after_execution(self):
responses[1][0]
)


def test_array_output(self):
from cwlkernel.CWLKernel import CWLKernel
kernel = CWLKernel()
# cancel send_response
kernel.send_response = lambda *args, **kwargs: None
with open(os.sep.join([self.data_directory, 'array-outputs-job.yml'])) as f:
data = f.read()
with open(os.sep.join([self.cwl_directory, 'array-outputs.cwl'])) as f:
workflow_str = f.read()
self.assertDictEqual(
{'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}},
kernel.do_execute(data)
)
self.assertDictEqual(
{'status': 'ok', 'execution_count': 0, 'payload': [], 'user_expressions': {}},
kernel.do_execute(workflow_str)
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 4f64972

Please sign in to comment.