-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
executable file
·82 lines (71 loc) · 2.55 KB
/
config.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Creates an updated config file for the pipeline
"""
import json
import argparse
def make_config(data):
"""
Prints JSON config to stdout
"""
print(json.dumps(data, indent=4))
def update_config(updateFile, data, add = False):
"""
Update the values of a JSON config file for non-null values in the provided data
"""
f = open(updateFile)
old_data = json.load(f)
f.close()
for key, value in data.items():
if not add:
if key in old_data:
if value is not None:
old_data[key] = value
else:
if value is not None:
old_data[key] = value
f = open(updateFile, "w")
json.dump(old_data, f, indent = 4)
f.close()
def main(**kwargs):
"""
Main control function for the script
"""
runID = kwargs.pop('runID', None)
runDir = kwargs.pop('runDir', None)
demuxDir = kwargs.pop('demuxDir', None)
samplesheet = kwargs.pop('samplesheet', None)
system = kwargs.pop('system', None)
seqType = kwargs.pop('seqType', None)
updateFile = kwargs.pop('updateFile', False)
add = kwargs.pop('add', False)
data = {
'runID': runID,
'runDir': runDir,
'demuxDir': demuxDir,
'samplesheet': samplesheet,
'system': system,
'seqType': seqType
}
if updateFile is False:
make_config(data)
else:
update_config(updateFile, data, add = add)
def parse():
"""
Parses script args
"""
parser = argparse.ArgumentParser(description='Creates an updated config file for the pipeline')
parser.add_argument("--runID", default = None, dest = 'runID', help="Run ID")
parser.add_argument("--runDir", default = None, dest = 'runDir', help="Run directory")
parser.add_argument("--demuxDir", default = None, dest = 'demuxDir', help="Run directory")
parser.add_argument("--samplesheet", default = None, dest = 'samplesheet', help="Samplesheet file")
parser.add_argument("--system", default = None, dest = 'system', help="Hostname of the server being used")
parser.add_argument("--seqType", default = None, dest = 'seqType', help="Identifier for the type of sequencing, e.g. Archer, NGS580, etc.")
parser.add_argument("-u", "--update", default = False, dest = 'updateFile', help="JSON file to update")
parser.add_argument('--add', action='store_true', dest = "add", help="forces the addition of missing keys to JSON config output")
args = parser.parse_args()
main(**vars(args))
if __name__ == '__main__':
parse()