-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize.phaster.json.py
executable file
·39 lines (32 loc) · 1.11 KB
/
summarize.phaster.json.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
#!/usr/bin/env python
import json
import os
import sys
from argparse import ArgumentParser
def parseArgs():
parser = ArgumentParser(description='Extracts summary data from a '
'JavaScript Object Notation (JSON) file returned by PHASTER\'s '
'(PHAge Search Tool Enhanced Release) application programming '
'interface (API)', add_help=False)
req = parser.add_argument_group('Required')
req.add_argument('-i', '--infile', required=True, metavar='FILE',
help='input JSON file')
opt = parser.add_argument_group('Optional')
opt.add_argument('-h', '--help', action='help',
help='show this help message and exit')
opt.add_argument('-o', '--outfile', required=False, metavar='FILE',
default=None, help='[stdout]')
return parser.parse_args()
def main():
opt = parseArgs()
ifh = os.path.abspath(os.path.expanduser(opt.infile))
with open(ifh) as json_file:
json_data = json.load(json_file)
if opt.outfile is not None:
ofh = os.path.abspath(os.path.expanduser(opt.outfile))
with open(ofh, 'w') as o:
o.write(json_data[u'summary'])
else:
print(json_data[u'summary'])
if __name__ == '__main__':
main()