|
15 | 15 |
|
16 | 16 | from pprint import pprint |
17 | 17 |
|
18 | | -VERSION='1.0.0' |
| 18 | +VERSION='1.1.0' |
19 | 19 |
|
20 | 20 | BOLD = '\033[1m' |
21 | 21 | CLEAR = '\033[0m' |
|
31 | 31 | # The directory where the workflow invocation data will be saved. |
32 | 32 | INVOCATIONS_DIR = 'invocations' |
33 | 33 |
|
| 34 | +class Keys: |
| 35 | + NAME = 'name' |
| 36 | + RUNS = 'runs' |
| 37 | + INPUTS = 'inputs' |
| 38 | + REFERENCE_DATA = 'reference_data' |
| 39 | + WORKFLOW_ID = 'workflow_id' |
| 40 | + DATASET_ID = 'dataset_id' |
| 41 | + HISTORY_BASE_NAME = 'output_history_base_name' |
| 42 | + HISTORY_NAME = 'history_name' |
| 43 | + |
34 | 44 |
|
35 | 45 | def workflows(): |
36 | 46 | """ |
@@ -81,33 +91,51 @@ def run(args): |
81 | 91 | with open(name, 'r') as stream: |
82 | 92 | try: |
83 | 93 | config = yaml.safe_load(stream) |
| 94 | + print(f"Loaded {name}") |
84 | 95 | except yaml.YAMLError as exc: |
85 | 96 | print(exc) |
86 | 97 |
|
87 | 98 | gi = bioblend.galaxy.GalaxyInstance(url=GALAXY_SERVER, key=API_KEY) |
88 | 99 | print(f"Connected to {GALAXY_SERVER}") |
89 | 100 |
|
90 | | - workflow = config['workflow_id'] |
91 | | - inputs = {} |
92 | | - for spec in config['inputs']: |
93 | | - input = gi.workflows.get_workflow_inputs(workflow, spec['name']) |
94 | | - if input is None or len(input) == 0: |
95 | | - print('ERROR: Invalid input specification') |
96 | | - sys.exit(1) |
97 | | - inputs[input[0]] = {'id': spec['dataset_id'], 'src': 'hda'} |
98 | | - |
99 | | - if 'output_history_name' in config: |
100 | | - print(f"Saving output to a history named {config['output_history_name']}") |
101 | | - invocation = gi.workflows.invoke_workflow(workflow, inputs=inputs, history_name=config['output_history_name']) |
102 | | - else: |
103 | | - invocation = gi.workflows.invoke_workflow(workflow, inputs=inputs) |
104 | | - |
105 | | - pprint(invocation) |
106 | | - |
107 | | - output_path = os.path.join(INVOCATIONS_DIR, invocation['id'] + '.json') |
108 | | - with open(output_path, 'w') as f: |
109 | | - json.dump(invocation, f, indent=4) |
110 | | - print(f"Wrote {output_path}") |
| 101 | + print(f"Found {len(config)} workflow definitions") |
| 102 | + for workflow in config: |
| 103 | + wfid = workflow['workflow_id'] |
| 104 | + inputs = {} |
| 105 | + history_base_name = wfid |
| 106 | + if Keys.HISTORY_BASE_NAME in workflow: |
| 107 | + history_base_name = workflow[Keys.HISTORY_BASE_NAME] |
| 108 | + |
| 109 | + if Keys.REFERENCE_DATA in workflow: |
| 110 | + for spec in workflow[Keys.REFERENCE_DATA]: |
| 111 | + input = gi.workflows.get_workflow_inputs(wfid, spec[Keys.NAME]) |
| 112 | + if input is None or len(input) == 0: |
| 113 | + print(f'ERROR: Invalid input specification for {spec[Keys.NAME]}') |
| 114 | + sys.exit(1) |
| 115 | + inputs[input[0]] = { 'id': spec[Keys.DATASET_ID], 'src':'hda'} |
| 116 | + |
| 117 | + count = 0 |
| 118 | + for run in workflow[Keys.RUNS]: |
| 119 | + count += 1 |
| 120 | + if Keys.HISTORY_NAME in run: |
| 121 | + output_history_name = f"{history_base_name} {run[Keys.HISTORY_NAME]}" |
| 122 | + else: |
| 123 | + output_history_name = f"{history_base_name} run {count}" |
| 124 | + for spec in run[Keys.INPUTS]: |
| 125 | + input = gi.workflows.get_workflow_inputs(wfid, spec[Keys.NAME]) |
| 126 | + if input is None or len(input) == 0: |
| 127 | + print(f'ERROR: Invalid input specification for {spec[Keys.NAME]}') |
| 128 | + sys.exit(1) |
| 129 | + |
| 130 | + inputs[input[0]] = {'id': spec[Keys.DATASET_ID], 'src' : 'hda' } |
| 131 | + |
| 132 | + invocation = gi.workflows.invoke_workflow(wfid, inputs=inputs, history_name=output_history_name) |
| 133 | + pprint(invocation) |
| 134 | + # output_path = os.path.join(INVOCATIONS_DIR, invocation['id'] + '.json') |
| 135 | + output_path = os.path.join(INVOCATIONS_DIR, output_history_name.replace(' ', '_') + '.json') |
| 136 | + with open(output_path, 'w') as f: |
| 137 | + json.dump(invocation, f, indent=4) |
| 138 | + print(f"Wrote {output_path}") |
111 | 139 |
|
112 | 140 |
|
113 | 141 | def histories(args): |
|
0 commit comments