-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test case for python api subworkflow support
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from pathlib import Path | ||
|
||
from wic import plugins | ||
from wic.api import pythonapi | ||
from wic.api.pythonapi import Step, Workflow | ||
|
||
def workflow() -> Workflow: | ||
bbbcdownload = Step(clt_path='cwl_adapters/bbbcdownload.cwl') | ||
# NOTE: object fields monkey patched at runtime from *.cwl file | ||
bbbcdownload.name = 'BBBC001' | ||
bbbcdownload.outDir = Path('bbbcdownload.outDir') | ||
|
||
subdirectory = Step(clt_path='../workflow-inference-compiler/cwl_adapters/subdirectory.cwl') | ||
subdirectory.directory = bbbcdownload.outDir | ||
subdirectory.glob_pattern = 'bbbcdownload.outDir/BBBC/BBBC001/raw/Images/human_ht29_colon_cancer_1_images/' | ||
subdirectory.subdirectory = Path('subdirectory.subdirectory') | ||
|
||
filerenaming = Step(clt_path='cwl_adapters/file-renaming.cwl') | ||
# NOTE: FilePattern {} syntax shadows python f-string {} syntax | ||
filerenaming.filePattern = '.*_{row:c}{col:dd}f{f:dd}d{channel:d}.tif' | ||
filerenaming.inpDir = subdirectory.subdirectory | ||
filerenaming.outDir = Path('file-renaming.outDir') | ||
filerenaming.outFilePattern = 'x{row:dd}_y{col:dd}_p{f:dd}_c{channel:d}.tif' | ||
|
||
# Trivially wrap the subdirectory step in a subworkflow. | ||
# But notice that we are still linking the individual Steps above, | ||
# which defeats the whole purpose of having reusable black boxes. | ||
steps = [bbbcdownload, | ||
Workflow([subdirectory], 'bbbc_sub_sub_py'), | ||
filerenaming] | ||
filename = 'bbbc_sub_py' # .yml | ||
return Workflow(steps, filename) | ||
|
||
|
||
def workflow2() -> Workflow: | ||
bbbcdownload = Step(clt_path='cwl_adapters/bbbcdownload.cwl') | ||
# NOTE: object fields monkey patched at runtime from *.cwl file | ||
bbbcdownload.name = 'BBBC001' | ||
bbbcdownload.outDir = Path('bbbcdownload.outDir') | ||
|
||
subdirectory = Step(clt_path='../workflow-inference-compiler/cwl_adapters/subdirectory.cwl') | ||
subworkflow = Workflow([subdirectory], 'bbbc_sub_sub_py') # fails validation, due to | ||
# https://workflow-inference-compiler.readthedocs.io/en/latest/dev/algorithms.html#deferred-satisfaction | ||
|
||
# First link all inputs within the subworkflow to the explicit inputs: tag. | ||
# i.e. This is the API for the subworkflow. | ||
subworkflow.steps[0].directory = subworkflow.directory | ||
subworkflow.steps[0].glob_pattern = subworkflow.glob_pattern | ||
subworkflow.steps[0].subdirectory = Path('subdirectory.subdirectory') | ||
|
||
# Then apply arguments at the call site. | ||
# Notice how the caller does not need to know about the internal details of the subworkflow | ||
# (For example, that the subdirectory step is index 0) | ||
subworkflow.directory = bbbcdownload.outDir | ||
subworkflow.glob_pattern = 'bbbcdownload.outDir/BBBC/BBBC001/raw/Images/human_ht29_colon_cancer_1_images/' | ||
|
||
filerenaming = Step(clt_path='cwl_adapters/file-renaming.cwl') | ||
# NOTE: FilePattern {} syntax shadows python f-string {} syntax | ||
filerenaming.filePattern = '.*_{row:c}{col:dd}f{f:dd}d{channel:d}.tif' | ||
filerenaming.inpDir = subworkflow.steps[0].subdirectory # TODO: workflow outputs: tag | ||
filerenaming.outDir = Path('file-renaming.outDir') | ||
filerenaming.outFilePattern = 'x{row:dd}_y{col:dd}_p{f:dd}_c{channel:d}.tif' | ||
|
||
steps = [bbbcdownload, | ||
subworkflow, | ||
filerenaming] | ||
filename = 'bbbc_sub_py' # .yml | ||
return Workflow(steps, filename) | ||
|
||
|
||
# viz = workflow() | ||
# viz.compile() # Do NOT .run() here | ||
|
||
if __name__ == '__main__': | ||
pythonapi.global_config = plugins.get_tools_cwl(str(Path().home())) # Use path fallback | ||
|
||
viz = workflow2() | ||
viz.run() # .run() here, inside main |