-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun_favites.py
More file actions
executable file
·79 lines (69 loc) · 3.42 KB
/
Copy pathrun_favites.py
File metadata and controls
executable file
·79 lines (69 loc) · 3.42 KB
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
#! /usr/bin/env python3
'''
FAVITES: FrAmework for VIral Transmission and Evolution Simulation
'''
from modules import FAVITES_ModuleFactory as MF
from modules import FAVITES_GlobalContext as GC
import argparse
from sys import argv,stdout,stdin
from warnings import warn
from os import environ,getcwd
from os.path import abspath,expanduser,isdir
# for parsing booleans in JSON
true = True
false = False
def parseArgs():
'''
Parse user arguments. As a developer, if you create any of your own module
implementations, you should modify the corresponding module argument parser
and "import ____ module" section of this function accordingly.
'''
global ORIG_CONFIG
# if running in Docker image, hardcode config and output directory
if 'FAVITES_DOCKER' in environ:
ORIG_CONFIG = open('/FAVITES_MOUNT/USER_CONFIG.JSON').read()
config = eval(ORIG_CONFIG)
assert 'out_dir' in config, "Parameter 'out_dir' is not in the configuration file!"
environ['out_dir_print'] = config['out_dir']
config['out_dir'] = '/FAVITES_MOUNT/OUTPUT_DIR'
if 'verbose' not in config: # Add "verbose":True to config for verbosity
config['verbose'] = False
# use argparse to parse user arguments
else:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-c', '--config', required=True, type=argparse.FileType('r'), help="Configuration file")
parser.add_argument('-o', '--out_dir', required=False, type=str, help="Output directory")
parser.add_argument('-s', '--random_number_seed', required=False, type=int, help="Random number seed")
parser.add_argument('-v', '--verbose', action="store_true", help="Print verbose messages to stderr")
args = parser.parse_args()
ORIG_CONFIG = args.config.read()
try:
config = eval(ORIG_CONFIG)
except:
raise SyntaxError("Malformed FAVITES configuration file. Must be valid JSON")
if args.out_dir is not None:
if 'out_dir' in config:
warn("Output directory specified in command line (%s) and config file (%s). Command line will take precedence" % (args.out_dir, config['out_dir']))
config['out_dir'] = args.out_dir
assert 'out_dir' in config, "Parameter 'out_dir' is not in the configuration file!"
environ['out_dir_print'] = config['out_dir']
config['verbose'] = args.verbose
if args.random_number_seed is not None:
if "random_number_seed" in config:
warn("Random number seed specified in command line (%d) and config file (%s). Command line will take precedence" % (args.random_number_seed, config['random_number_seed']))
config["random_number_seed"] = args.random_number_seed
# import modules and store in global access variables
if "random_number_seed" not in config:
config["random_number_seed"] = ""
# update config string based on (potential) updates
ORIG_CONFIG = str(config)
# set verbosity
MF.read_config(config, config['verbose'])
GC.VERBOSE = config['verbose']
if __name__ == "__main__":
# initialize global access variables
MF.init('/'.join(argv[0].split('/')[:-1]) + '/modules')
# parse user arguments
parseArgs()
# run Driver
MF.modules['Driver'].run('/'.join(expanduser(abspath(argv[0])).split('/')[:-1]), ORIG_CONFIG)