forked from repotrial/nedrexdb_v2d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·208 lines (169 loc) · 5.81 KB
/
build.py
File metadata and controls
executable file
·208 lines (169 loc) · 5.81 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
import click
import os
import nedrexdb
from nedrexdb import config, downloaders
from nedrexdb.control.docker import NeDRexDevInstance, NeDRexLiveInstance
from nedrexdb.db import MongoInstance, mongo_to_neo, collection_stats
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.downloaders import get_versions, update_versions
from nedrexdb.post_integration import (trim_uberon, drop_empty_collections,create_vector_indices)
@click.group()
def cli():
pass
@click.option("--conf", required=True, type=click.Path(exists=True))
@click.option("--download", is_flag=True, default=False)
@click.option("--version_update", is_flag=False, default="")
@click.option("--create_embeddings", is_flag=True, default=False)
@cli.command()
def update(conf, download, version_update, create_embeddings):
print(f"Config file: {conf}")
print(f"Download updates: {download}")
print(f"Update DB versions: {version_update}")
print(f"Create embeddings: {create_embeddings}")
nedrexdb.parse_config(conf)
version = config["db.version"]
if version not in ["open", "licensed"]:
raise Exception(f"invalid version {version!r}")
version_update_skip = set()
dev_instance = NeDRexDevInstance()
dev_instance.remove()
dev_instance.set_up(use_existing_volume=False, neo4j_mode="import")
MongoInstance.connect("dev")
MongoInstance.set_indexes()
if os.environ.get("TEST_MINIMUM", 0) == '1':
parse_dev(version=version, download=download, version_update=version_update)
else:
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()
version_update_skip.add("omim")
sider.parse()
uniprot.parse_idmap()
from nedrexdb.analyses import molecule_similarity
molecule_similarity.run()
# Post-processing
trim_uberon.trim_uberon()
if download:
update_versions(version_update_skip)
if version_update:
get_versions(version_update)
# clean up for export
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)
collection_stats.verify_collections_after_profiling(MongoInstance.DB)
# remove dev instance and set up live instance
dev_instance.remove(neo4j_mode="import")
if create_embeddings:
dev_instance = NeDRexDevInstance()
dev_instance.set_up(use_existing_volume=True, neo4j_mode="db-write")
# create embeddings
try:
create_vector_indices.create_vector_indices()
except Exception as e:
print(e)
print("Failed to create vector indices")
dev_instance.remove()
live_instance = NeDRexLiveInstance()
live_instance.remove()
live_instance.set_up(use_existing_volume=True, neo4j_mode="db")
def parse_dev(version, download, version_update):
# control source downloads
ignored_sources = {"chembl",
"biogrid",
"go",
"uberon",
"clinvar",
"hpo",
"hpa",
"uniprot",
"reactome",
"bioontology",
"drug_central",
"unichem",
"repotrial",
"iid",
"intact",
"omim",
"sider"}
if download:
downloaders.download_all(ignored_sources=ignored_sources)
mondo.parse_mondo_json()
ncbi.parse_gene_info()
if version == "licensed":
drugbank._parse_drugbank()
elif version == "open":
drugbank.parse_drugbank()
ctd.parse()
disgenet.parse_gene_disease_associations()
if download:
update_versions(ignored_sources=ignored_sources)
if version_update:
get_versions(version_update)
@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()