-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
78 lines (76 loc) · 3.15 KB
/
parser.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
#!/usr/bin/env python3
import json
import re
import oyaml as yaml
with open('new_ref.yaml') as f:
data = f.read()
datajson = json.loads(data)
# if yaml_level is indices,
yaml_level = datajson.get('level')
yaml_commands = datajson.get('Commands').rstrip()
commands = re.split('\n|, ', yaml_commands)
if 'src' in datajson:
yaml_dict = {
datajson.get('name'):
{'metadata':
{'name': datajson.get('name'),
'common_name': datajson.get('common'),
'custom': datajson.get('custom'),
'description': datajson.get('description'),
'downloader': 'joselynn wallace',
'ncbi_taxon_id': datajson.get('taxon_id'),
'ensembl_release_number': datajson.get('ensembl_rel'),
'accession':
{'genbank': datajson.get('genbank'),
'refseq': datajson.get('refseq')},
'organism': datajson.get('organism'),
'organization': datajson.get('organization'),
'category': datajson.get('category')
},
'levels':
{yaml_level:
[
{
'component': datajson.get('component'),
'complete':
{'status': 'false'},
'src': datajson.get('src'),
'commands': commands
}
]
}
}
}
else:
yaml_dict = {
datajson.get('name'):
{'metadata':
{'name': datajson.get('name'),
'common_name': datajson.get('common'),
'custom': datajson.get('custom'),
'description': datajson.get('description'),
'downloader': 'joselynn wallace',
'ncbi_taxon_id': datajson.get('taxon_id'),
'ensembl_release_number': datajson.get('ensembl_rel'),
'accession':
{'genbank': datajson.get('genbank'),
'refseq': datajson.get('refseq')},
'organism': datajson.get('organism'),
'organization': datajson.get('organization'),
'category': datajson.get('category')
},
'levels':
{yaml_level:
[
{
'component': datajson.get('component'),
'complete':
{'status': 'false'},
'commands': commands
}
]
}
}
}
out = open('new_parsed.yaml', 'w+')
yaml.dump(yaml_dict, out, allow_unicode=True, width=100000)