forked from rentzi/directedGraphRewiring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
103 lines (80 loc) · 2.19 KB
/
main.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
import os
import sys
import yaml
# get project's path
# write project config.
from src.codebase.nodes import utils
proj_path = os.getcwd()
utils.write_project_config(proj_path)
from src.codebase.pipelines import (
figure2,
figure3,
figure4,
figure5,
figure6,
figureS3,
figureS4,
)
def check_run_args(run_args):
"""Check that run arguments passed to python -m main are correct"""
# check that argument 1 exists
try:
flag = run_args[1]
if flag in ["--run", "--load"]:
try:
pipeline_name = sys.argv[2]
except:
SyntaxError("Specify pipeline name. It is missing.")
else:
print(
"""
Specify pipeline with either:
--run followed with a pipeline name
--load followed with a pipeline name
"""
)
except:
SyntaxError(
"""
Specify pipeline with either:
--run followed with a pipeline name
--load followed with a pipeline name
"""
)
return 0
def run_pipeline(pipeline: str):
"""Run pipeline to create specified figure
Args:
pipeline (str): [description]
"""
# set parameter file
params_file = f"conf/{pipeline}/parameters.yml"
# load parameters
with open(params_file, "r") as file:
params = yaml.safe_load(file)
# get pipeline
pipe = eval(pipeline)
# run pipeline
output = pipe.create(params)
# save intermediate data
pipe.save_data(output)
def load(pipeline=str):
"""Load a pipeline's stored intermediate data for a quick plot
Args:
pipeline (str, optional): e.g., "figure2"
"""
# load intermediate data
data = eval(pipeline).load_data()
# plot
eval(pipeline).plot_figure(data)
if __name__ == "__main__":
"""Entry point"""
# check run arguments
check_run_args(sys.argv)
# run pipeline
if sys.argv[1] == "--run":
run_pipeline(pipeline=sys.argv[2])
elif sys.argv[1] == "--load":
load(pipeline=sys.argv[2])
# status
print("(main) - Run completed")