-
Notifications
You must be signed in to change notification settings - Fork 0
/
VRE_RUNNER.py
executable file
·118 lines (94 loc) · 4.31 KB
/
VRE_RUNNER.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2020-2022 Barcelona Supercomputing Center (BSC), Spain
# Copyright 2020-2022 Heidelberg University Hospital (UKL-HD), Germany
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import sys
from utils import logger
from apps.jsonapp import JSONApp
from tool.VRE_Tool import progenyTool
class Wrapper:
"""
Functions for wrapping the tool set up and execution.
"""
configuration = {}
output = {}
def __init__(self, configuration=None):
"""
Initialise the tool with its configuration.
:param configuration: A dictionary containing parameters that define how the operation should be carried out,
which are specific to PROGENy tool.
:type configuration: dict
"""
if configuration is None:
configuration = {}
self.configuration.update(configuration)
def run(self, input_files, input_metadata, output_files, output_metadata):
"""
Main run function for running PROGENy tool.
:param input_files: Dictionary of input files locations.
:type input_files: dict
:param input_metadata: Dictionary of input files metadata.
:type input_metadata: dict
:param output_files: Dictionary of output files locations expected to be generated.
:type output_files: dict
:param output_metadata: List of output files metadata expected to be generated.
:type output_metadata: list
:return: Generated output files and their metadata.
:rtype: dict, dict
"""
try:
tt_handle = progenyTool(self.configuration)
tt_files, tt_meta = tt_handle.run(input_files, input_metadata, output_files, output_metadata)
return tt_files, tt_meta
except Exception as error:
errstr = "PROGENy tool wasn't executed successfully. ERROR: {}.".format(error)
logger.error(errstr)
raise Exception(errstr)
def main_wrapper(config_path, in_metadata_path, out_metadata_path):
"""
Main function.
This function launches the tool using configuration written in two json files: config.json and in_metadata.json.
:param config_path: Path to a valid VRE JSON file containing information on how the tool should be executed.
:type config_path: str
:param in_metadata_path: Path to a valid VRE JSON file containing information on tool inputs.
:type in_metadata_path: str
:param out_metadata_path: Path to write the VRE JSON file containing information on tool outputs.
:type out_metadata_path: str
:return: If result is True, execution finished successfully. False, otherwise.
:rtype: bool
"""
try:
app = JSONApp()
result = app.launch(Wrapper, config_path, in_metadata_path, out_metadata_path)
logger.progress("PROGENy tool successfully executed; see {}".format(out_metadata_path))
return result
except Exception as error:
errstr = "PROGENy tool wasn't successfully executed. ERROR: {}.".format(error)
logger.error(errstr)
raise Exception(errstr)
if __name__ == "__main__":
PARSER = argparse.ArgumentParser(description="VRE PROGENy Tool")
PARSER.add_argument("--config", help="Location of configuration file", required=True)
PARSER.add_argument("--in_metadata", help="Location of input metadata file", required=True)
PARSER.add_argument("--out_metadata", help="Location of output metadata file", required=True)
PARSER.add_argument("--log_file", help="Location of the log file", required=False)
ARGS = PARSER.parse_args()
CONFIG = ARGS.config
IN_METADATA = ARGS.in_metadata
OUT_METADATA = ARGS.out_metadata
if ARGS.log_file:
sys.stderr = sys.stdout = open(ARGS.log_file, "w")
RESULTS = main_wrapper(CONFIG, IN_METADATA, OUT_METADATA)