Skip to content

Commit 61abb94

Browse files
vjaganat90Vasu Jaganath
andauthored
one step wfb, cwl dict format and uuid (PolusAI#292)
Co-authored-by: Vasu Jaganath <[email protected]>
1 parent 9797013 commit 61abb94

File tree

6 files changed

+240
-48
lines changed

6 files changed

+240
-48
lines changed

src/sophios/api/http/restapi.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22
import argparse
33
import copy
4+
import uuid
45
import yaml
56

67

@@ -13,7 +14,7 @@
1314
from sophios.utils_graphs import get_graph_reps
1415
from sophios.utils_yaml import wic_loader
1516
from sophios import utils_cwl
16-
from sophios.post_compile import cwl_inline_runtag
17+
from sophios.post_compile import cwl_inline_runtag, remove_entrypoints
1718
from sophios.cli import get_args
1819
from sophios.wic_types import CompilerInfo, Json, Tool, Tools, StepId, YamlTree, Cwl, NodeData
1920
from sophios.api.utils import converter
@@ -94,14 +95,15 @@ async def compile_wf(request: Request) -> Json:
9495
print('---------- Compile Workflow! ---------')
9596
# ========= PROCESS REQUEST OBJECT ==========
9697
req: Json = await request.json()
98+
suppliedargs = ['--cwl_inline_runtag', '--generate_cwl_workflow']
9799
# clean up and convert the incoming object
98100
# schema preserving
99101
req = converter.update_payload_missing_inputs_outputs(req)
100102
wfb_payload = converter.raw_wfb_to_lean_wfb(req)
101103
# schema non-preserving
102104
workflow_temp = converter.wfb_to_wic(wfb_payload)
103-
wkflw_name = "generic_workflow"
104-
args = get_args(wkflw_name, ['--cwl_inline_runtag', '--generate_cwl_workflow'])
105+
wkflw_name = "generic_workflow_" + str(uuid.uuid4())
106+
args = get_args(wkflw_name, suppliedargs)
105107

106108
# Build canonical workflow object
107109
workflow_can = utils_cwl.desugar_into_canonical_normal_form(workflow_temp)
@@ -128,29 +130,41 @@ async def compile_wf(request: Request) -> Json:
128130
yaml_tree: YamlTree = YamlTree(StepId(wkflw_name, plugin_ns), workflow_can)
129131

130132
# ========= COMPILE WORKFLOW ================
131-
args.ignore_dir_path = True
133+
if req.get('run_local_env') == 'true':
134+
args.ignore_dir_path = False
135+
else:
136+
args.ignore_dir_path = True
132137
compiler_info: CompilerInfo = compiler.compile_workflow(yaml_tree, args, [], [graph], {}, {}, {}, {},
133138
tools_cwl, True, relative_run_path=True, testing=False)
134139

135140
rose_tree = compiler_info.rose
136141
input_output.write_to_disk(rose_tree, Path('autogenerated/'), True, args.inputs_file)
137142
rose_tree = cwl_inline_runtag(args, rose_tree)
143+
rose_tree = remove_entrypoints(args, rose_tree)
138144
# ======== OUTPUT PROCESSING ================
139145
# ========= PROCESS COMPILED OBJECT =========
140146
sub_node_data: NodeData = rose_tree.data
141147
yaml_stem = sub_node_data.name
142148
cwl_tree = sub_node_data.compiled_cwl
143149
yaml_inputs = sub_node_data.workflow_inputs_file
144-
cwl_tree_no_dd = remove_dot_dollar(cwl_tree)
145-
yaml_inputs_no_dd = remove_dot_dollar(yaml_inputs)
146150

147151
# Convert the compiled yaml file to json for labshare Compute.
148-
cwl_tree_run = copy.deepcopy(cwl_tree_no_dd)
152+
cwl_tree_run = copy.deepcopy(cwl_tree)
153+
cwl_tree_run['steps_dict'] = {}
154+
for step in cwl_tree_run['steps']:
155+
node_name = step['id']
156+
step.pop('id', None)
157+
step = {node_name: step}
158+
step_copy = copy.deepcopy(step)
159+
cwl_tree_run['steps_dict'].update(step_copy)
160+
161+
cwl_tree_run.pop('steps', None)
162+
cwl_tree_run['steps'] = cwl_tree_run.pop('steps_dict', None)
149163

150164
compute_workflow: Json = {}
151165
compute_workflow = {
152166
"name": yaml_stem,
153-
"cwlJobInputs": yaml_inputs_no_dd,
167+
"cwlJobInputs": yaml_inputs,
154168
**cwl_tree_run
155169
}
156170
compute_workflow["retval"] = str(0)

src/sophios/api/pythonapi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""CLT utilities."""
33
import logging
44
from pathlib import Path
5-
import subprocess as sub
65
from typing import Any, ClassVar, Optional, TypeVar, Union
76

87
import cwl_utils.parser as cu_parser

src/sophios/api/utils/ict/ict_spec/tools/cwl_ict.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def requirements(ict_: "ICT", network_access: bool) -> dict:
2020
return reqs
2121

2222

23+
def split_entrypoint_string(enrtypoint: str) -> list[str]:
24+
"""Fix str to list of str for entrypoint/baseCommand"""
25+
list_of_str_entry = enrtypoint.split(' ')
26+
return list_of_str_entry
27+
28+
2329
def clt_dict(ict_: "ICT", network_access: bool) -> dict:
2430
"""Return a dict of a CommandLineTool from an ICT object."""
2531

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"state": {
3+
"nodes": [
4+
{
5+
"id": 1,
6+
"x": 259,
7+
"y": 209,
8+
"z": 1,
9+
"name": "BBBC Download",
10+
"expanded": true,
11+
"pluginId": "polusai/[email protected]",
12+
"height": 50,
13+
"width": 250,
14+
"settings": {
15+
"inputs": {
16+
"name": "BBBC001",
17+
"outDir": "bbbcdownload.outDir"
18+
}
19+
},
20+
"internal": false
21+
}
22+
],
23+
"links": [],
24+
"selection": []
25+
},
26+
"plugins": [
27+
{
28+
"name": "polusai/bbbc-download-plugin:0.1.0-dev1",
29+
"version": "0.1.0-dev1",
30+
"title": "BBBC Download",
31+
"description": "Downloads the datasets on the Broad Bioimage Benchmark Collection website",
32+
"createdBy": "Serebryakov, Artem (NIH/NCATS) [C]",
33+
"updatedBy": "Serebryakov, Artem (NIH/NCATS) [C]",
34+
"author": [
35+
"Hamdah Abbasi"
36+
],
37+
"contact": "[email protected]",
38+
"container": "polusai/bbbc-download-plugin:0.1.0-dev1",
39+
"entrypoint": "",
40+
"inputs": [
41+
{
42+
"description": "The name of the dataset(s) to be downloaded (separate the datasets with a comma. eg BBBC001,BBBC002,BBBC003)",
43+
"format": [
44+
"collection"
45+
],
46+
"name": "name",
47+
"required": true,
48+
"type": "string"
49+
}
50+
],
51+
"outputs": [
52+
{
53+
"description": "Output collection",
54+
"name": "outDir",
55+
"format": [
56+
"directory"
57+
],
58+
"required": true,
59+
"type": "path"
60+
}
61+
],
62+
"repository": "https://github.com/LabShare/polus-plugins",
63+
"specVersion": "1.0.0",
64+
"ui": [
65+
{
66+
"description": "The name of the dataset(s) to be downloaded (separate the datasets with a comma. eg BBBC001,BBBC002,BBBC003)",
67+
"format": [
68+
"collection"
69+
],
70+
"name": "name",
71+
"required": true,
72+
"type": "string"
73+
}
74+
],
75+
"path": "visualization",
76+
"tags": [
77+
"bbbc-download"
78+
],
79+
"createdAt": "2024-10-29T18:59:55.843Z",
80+
"updatedAt": "2024-10-29T20:01:42.463Z",
81+
"id": "672130abad801ccee7f5eaad",
82+
"pid": "polusai/[email protected]"
83+
}
84+
]
85+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"state": {
3+
"nodes": [
4+
{
5+
"id": 1,
6+
"name": "bbbcdownload",
7+
"pluginId": "",
8+
"run": {
9+
"baseCommand": [],
10+
"class": "CommandLineTool",
11+
"cwlVersion": "v1.2",
12+
"inputs": {
13+
"name": {
14+
"label": "The name of the dataset(s) to be downloaded (separate the datasets with a comma. eg BBBC001,BBBC002,BBBC003)",
15+
"doc": "The name of the dataset(s) to be downloaded (separate the datasets with a comma. eg BBBC001,BBBC002,BBBC003)",
16+
"inputBinding": {
17+
"prefix": "--name"
18+
},
19+
"type": "string"
20+
},
21+
"outDir": {
22+
"label": "Output collection",
23+
"doc": "Output collection",
24+
"inputBinding": {
25+
"prefix": "--outDir"
26+
},
27+
"type": "Directory"
28+
}
29+
},
30+
"outputs": {
31+
"outDir": {
32+
"label": "Output collection",
33+
"doc": "Output collection",
34+
"type": "Directory",
35+
"outputBinding": {
36+
"glob": "$(inputs.outDir.basename)"
37+
}
38+
}
39+
},
40+
"stdout": "output",
41+
"requirements": {
42+
"DockerRequirement": {
43+
"dockerPull": "polusai/bbbc-download-plugin:0.1.0-dev1"
44+
},
45+
"InitialWorkDirRequirement": {
46+
"listing": [
47+
{
48+
"entry": "$(inputs.outDir)",
49+
"writable": true
50+
}
51+
]
52+
},
53+
"InlineJavascriptRequirement": {},
54+
"NetworkAccess": {
55+
"networkAccess": true
56+
}
57+
}
58+
},
59+
"settings": {
60+
"inputs": {
61+
"name": "BBBC001",
62+
"outDir": "bbbcdownload.outDir"
63+
},
64+
"outputs": {
65+
"outDir": "bbbcdownload.outDir"
66+
}
67+
},
68+
"internal": false
69+
}
70+
],
71+
"links": []
72+
},
73+
"plugins": []
74+
}

0 commit comments

Comments
 (0)