-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparse_meme_json.py
More file actions
executable file
·41 lines (33 loc) · 1.07 KB
/
parse_meme_json.py
File metadata and controls
executable file
·41 lines (33 loc) · 1.07 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
#!/usr/bin/env python3
#
import argparse
import json
__author__ = "Ekaterina Osipova, 2020."
def main():
## Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('-j', '--jsonmeme', type=str, help='file with json output of MEME')
parser.add_argument('-a', '--attribute', type=str, default='p-value', help='attribute of MLE-content you want to extract; \
ltr/p-value/nbranches/lbranch; default: p-value')
args = parser.parse_args()
## Read MEME output into json object
with open(args.jsonmeme, 'r') as inf:
data = json.load(inf)
## Get requested attribute
attribute = args.attribute
content = data['MLE']['content']['0']
if attribute == 'ltr':
index = 5
elif attribute == 'p-value':
index = 6
elif attribute == 'nbranches':
index = 7
elif attribute == 'lbranch':
index = 8
## Output requested attribute for each site
i = 1
for site in content:
print('{}\t{}'.format(i, site[index]))
i += 1
if __name__ == "__main__":
main()