forked from repotrial/nedrexdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·143 lines (112 loc) · 3.49 KB
/
build.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
import time
import click
import nedrexdb
from nedrexdb import config, downloaders
from nedrexdb.control.docker import NeDRexDevInstance, NeDRexLiveInstance
from nedrexdb.db import MongoInstance, mongo_to_neo, collection_stats, update_db_version
from nedrexdb.db.parsers import (
biogrid,
disgenet,
ctd,
drugbank,
drug_central,
hpo,
hpa,
iid,
intact,
uniprot,
uniprot_signatures,
ncbi,
mondo,
omim,
reactome,
go,
clinvar,
chembl,
unichem,
bioontology,
sider,
uberon,
repotrial,
)
from nedrexdb.post_integration import trim_uberon, drop_empty_collections
@click.group()
def cli():
pass
@click.option("--conf", required=True, type=click.Path(exists=True))
@click.option("--download", is_flag=True, default=False)
@cli.command()
def update(conf, download):
print(f"Config file: {conf}")
print(f"Download updates: {download}")
nedrexdb.parse_config(conf)
version = config["db.version"]
if version not in ["open", "licensed"]:
raise Exception(f"invalid version {version!r}")
dev_instance = NeDRexDevInstance()
dev_instance.remove()
dev_instance.set_up(use_existing_volume=False, neo4j_mode="import")
MongoInstance.connect("dev")
MongoInstance.set_indexes()
if download:
downloaders.download_all()
# Parse sources contributing only nodes (and edges amongst those nodes)
go.parse_go()
mondo.parse_mondo_json()
ncbi.parse_gene_info()
uberon.parse()
uniprot.parse_proteins()
# Sources that add node type but require existing nodes, too
clinvar.parse()
if version == "licensed":
drugbank._parse_drugbank() # requires proteins to be parsed first
elif version == "open":
drugbank.parse_drugbank()
chembl.parse_chembl()
uniprot_signatures.parse() # requires proteins to be parsed first
hpo.parse() # requires disorders to be parsed first
reactome.parse() # requires protein to be parsed first
bioontology.parse() # requires phenotype to be parsed
# Sources that add data to existing nodes
drug_central.parse_drug_central()
unichem.parse()
repotrial.parse()
# Sources adding edges.
biogrid.parse_ppis()
ctd.parse()
disgenet.parse_gene_disease_associations()
go.parse_goa()
hpa.parse_hpa()
iid.parse_ppis()
intact.parse()
if version == "licensed":
omim.parse_gene_disease_associations()
sider.parse()
uniprot.parse_idmap()
from nedrexdb.analyses import molecule_similarity
molecule_similarity.run()
# Post-processing
trim_uberon.trim_uberon()
drop_empty_collections.drop_empty_collections()
# export to Neo4j
mongo_to_neo.mongo_to_neo(dev_instance, MongoInstance.DB)
# Profile the collections
collection_stats.profile_collections(MongoInstance.DB)
update_db_version.update_db_version(default_version="2.0.0")
time.sleep(60)
# remove dev instance and set up live instance
dev_instance.remove()
live_instance = NeDRexLiveInstance()
live_instance.remove()
live_instance.set_up(use_existing_volume=True, neo4j_mode="db")
@click.option("--conf", required=True, type=click.Path(exists=True))
@cli.command()
def restart_live(conf):
print(f"Config file: {conf}")
nedrexdb.parse_config(conf)
live_instance = NeDRexLiveInstance()
live_instance.remove()
live_instance.set_up(use_existing_volume=True, neo4j_mode="db")
if __name__ == "__main__":
cli()