forked from MOZI-AI/knowledge-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.py
executable file
·48 lines (44 loc) · 1.68 KB
/
metadata.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
import json
import datetime
import os
from collections import OrderedDict
def update_meta(version, source, script, genes=None, rna=None, ncrna=None, prot=None, chebi=None, pathways=None, goterms=None,interactions=None):
meta_data = OrderedDict()
dataset_name = version.split(':')[0]
meta_data.update({"Version": version.split(':')[1]})
meta_data.update({"Source": source})
if genes:
meta_data.update({"Number of Genes ": genes})
if rna:
meta_data.update({"Number of coding RNA's ": rna})
if ncrna:
meta_data.update({"Number of Non-coding RNA's ": ncrna})
if prot:
meta_data.update({"Number of Proteins ": prot})
if chebi:
meta_data.update({"Number of Small Molecules ": chebi})
if interactions:
meta_data.update({"Number of interactions ": interactions})
if pathways:
for p in pathways.keys():
meta_data.update({"Number of "+ p: pathways[p]})
if goterms:
for namespace in goterms.keys():
meta_data.update({"Number of "+ namespace: goterms[namespace]})
meta_data.update({"Import script": script })
meta_data.update({"Import Date ": str(datetime.datetime.now().date())})
dataset_meta = {dataset_name: [meta_data]}
fname = "dataset/meta.json"
if not os.path.exists(os.path.join(os.getcwd(), 'dataset')):
os.makedirs('dataset')
if not os.path.isfile(fname):
a = []
a.append(dataset_meta)
with open(fname, mode='w') as f:
json.dump(a,f, indent=2)
else:
with open(fname) as feedsjson:
feeds = json.load(feedsjson, object_pairs_hook=OrderedDict)
feeds[0][dataset_name] = [meta_data]
with open(fname, mode='w') as f:
json.dump(feeds, f, indent=2)