-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkg_generator_with_delta.py
275 lines (203 loc) · 8.58 KB
/
kg_generator_with_delta.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import os
from neo4j import GraphDatabase
driver = GraphDatabase.driver(
uri="bolt://localhost:7687", auth=("neo4j", "biomedical_kg"))
session = driver.session()
q00 = """Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value"""
results = session.run(q00)
dest = results.data()[0]['value']
print(dest)
def del_dir(dest=dest):
print(dest)
os.system(f"rm -R '{dest}'")
def del_file(filepath, dest=dest):
try:
os.remove(dest + "/" + os.path.basename(filepath))
os.remove(filepath)
except:
pass
def copy(src, dest=dest):
# if folder doesn't exist, create it
try:
if not os.path.exists(dest):
os.makedirs(dest)
os.system(f"cp '{src}' '{dest}'")
except:
print("Version not copied for ", src)
def del_kg():
q0 = """MATCH(n)
DETACH DELETE n"""
results = session.run(q0)
data = results.data()
print("KG Cleared")
def string_rel():
# Load csv without null values in cypher
try:
q1 = """LOAD CSV WITH HEADERS FROM 'file:///string_interacts-with_relationship.tsv' as row FIELDTERMINATOR '\t'
WITH row
WHERE row.combined_score is NOT NULL
MERGE (k:protein {Name: row.Protein1})
MERGE (j:protein {Name: row.Protein2})
MERGE (k) -[:interacts_with {combined_score:row.combined_score, neighborhood:row.neighborhood, fusion:row.fusion, cooccurence:row.cooccurence, coexpression:row.coexpression, database:row.database, textmining:row.textmining}] -> (j)"""
results = session.run(q1)
data = results.data()
print("Added STRING")
except:
print("STRING already added")
def string_prop():
try:
q2 = """LOAD CSV WITH HEADERS FROM 'file:///string_protein_node.tsv' as csvLine FIELDTERMINATOR '\t'
MATCH (k {Name: csvLine.Ensembl_ID})
SET k.Preferred_name = csvLine.Preferred_name, k.Ensembl_HGNC = csvLine.Ensembl_HGNC, k.Ensembl_gene = csvLine.Ensembl_gene, k.Ensembl_UniProt_AC = csvLine.Ensembl_UniProt_AC"""
results = session.run(q2)
data = results.data()
print("Added STRING properties")
except:
print("STRING properties already added")
def geo_down_rel():
try:
q3 = """LOAD CSV WITH HEADERS FROM 'file:///geo_downregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MERGE (x:disease {Name: row.Disease})
MERGE (y:gene {Name: row.Gene})
MERGE (x) -[:downregulates {metap:row.metap, metafc:row.metafc}] -> (y)
"""
results = session.run(q3)
data = results.data()
print("Added GEO Downregulation relationships")
except:
print("GEO Downregulation relationships already added")
def geo_up_rel():
try:
q4 = """LOAD CSV WITH HEADERS FROM 'file:///geo_upregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MERGE (x:disease {Name: row.Disease})
MERGE (z:gene {Name: row.Gene})
MERGE (x) -[:upregulates {metap:row.metap, metafc:row.metafc}] -> (z)
"""
results = session.run(q4)
data = results.data()
print("Added GEO Upregulation relationships")
except:
print("GEO Upregulation relationships already added")
def lincs_up_rel():
try:
q5 = """LOAD CSV WITH HEADERS FROM 'file:///lincs_upregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MERGE (x:drug {Name: row.drug})
MERGE (y:gene {Name: row.gene})
MERGE (x) -[:upregulates {zvalue:row.zvalue, pvalue:row.pvalue}] -> (y)
"""
results = session.run(q5)
data = results.data()
print("Added Lincs Upregulation relationships")
except:
print("Lincs Upregulation relationships already added")
def lincs_down_rel():
try:
q6 = """LOAD CSV WITH HEADERS FROM 'file:///lincs_downregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MERGE (x:drug {Name: row.drug})
MERGE (y:gene {Name: row.gene})
MERGE (x) -[:downregulates {zvalue:row.zvalue, pvalue:row.pvalue}] -> (y)
"""
results = session.run(q6)
data = results.data()
print("Added Lincs Downregulation relationships")
except:
print("Lincs Downregulation relationships already added")
def disgenet_association_relationships():
try:
q7 = """LOAD CSV WITH HEADERS FROM 'file:///disgenet_association_relationship.tsv' as row FIELDTERMINATOR '\t'
MERGE (x:disease {Name: row.disease})
MERGE (y:gene {Name: row.gene})
MERGE (x) -[:associated_with {score:row.score, ei:row.EI, year_initial:row.year_initial, year_final:row.year_final}] -> (y)"""
results = session.run(q7)
data = results.data()
print("Added Disgenet Relationships")
except:
print("Disgenet Relationships already added")
def disgenet_disease_prop():
try:
q8 = """LOAD CSV WITH HEADERS FROM 'file:///disgenet_disease_node.tsv' as csvLine FIELDTERMINATOR '\t'
MATCH (k {Name: csvLine.disease})
SET k.diseaseID = csvLine.diseaseID, k.disease_class = csvLine.disease_class, k.disease_class_name = csvLine.disease_class_name, k.disease_semantic_type = csvLine.disease_semantic_type"""
results = session.run(q8)
data = results.data()
print("Added Disgenet Disease properties")
except:
print("Disgenet Disease properties already added")
def disgenet_gene_prop():
try:
q9 = """LOAD CSV WITH HEADERS FROM 'file:///disgenet_gene_node.tsv' as csvLine FIELDTERMINATOR '\t'
MATCH (k {Name: csvLine.gene})
SET k.geneID = csvLine.geneID, k.Protein_Class = csvLine.Protein_Class, k.UniProtID = csvLine.UniProtID, k.DPI = csvLine.DPI, k.DSI = csvLine.DSI"""
results = session.run(q9)
data = results.data()
print("Added Disgenet Gene properties")
except:
print("Disgenet Gene properties already added")
def del_lincs_down_rel():
try:
q9 = """LOAD CSV WITH HEADERS FROM 'file:///lincs_downregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:drug {Name: row.drug})
MATCH (k:gene {Name: row.gene})
DETACH DELETE k"""
results = session.run(q9)
data = results.data()
print("Delete Lincs Downregulation relationships")
except:
print("Lincs Downregulation relationships already deleted")
def del_lincs_up_rel():
try:
q10 = """LOAD CSV WITH HEADERS FROM 'file:///lincs_upregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:drug {Name: row.drug})
MATCH (k:gene {Name: row.gene})
DETACH DELETE k"""
results = session.run(q10)
data = results.data()
print("Delete Lincs Upregulation relationships")
except:
print("Lincs Upregulation relationships already deleted")
def del_geo_down_rel():
try:
q11 = """LOAD CSV WITH HEADERS FROM 'file:///geo_downregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:disease {Name: row.Disease})
MATCH (k:gene {Name: row.Gene})
DETACH DELETE k"""
results = session.run(q11)
data = results.data()
print("Delete GEO Downregulation relationships")
except:
print("GEO Downregulation relationships already deleted")
def del_geo_up_rel():
try:
q12 = """LOAD CSV WITH HEADERS FROM 'file:///geo_upregulates_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:disease {Name: row.Disease})
MATCH (k:gene {Name: row.Gene})
DETACH DELETE k"""
results = session.run(q12)
data = results.data()
print("Delete GEO Upregulation relationships")
except:
print("GEO Upregulation relationships already deleted")
def del_disgenet_association_relationships():
try:
q13 = """LOAD CSV WITH HEADERS FROM 'file:///disgenet_association_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:disease {Name: row.disease})
MATCH (k:gene {Name: row.gene})
DETACH DELETE k"""
results = session.run(q13)
data = results.data()
print("Delete Disgenet Relationships")
except:
print("Disgenet Relationships already deleted")
def del_string_rel():
try:
q14 = """LOAD CSV WITH HEADERS FROM 'file:///string_interacts-with_relationship.tsv' as row FIELDTERMINATOR '\t'
MATCH (n:protein {Name: row.Protein1})
MATCH (k:protein {Name: row.Protein2})
DETACH DELETE n, k"""
results = session.run(q14)
data = results.data()
print("Delete STR relationships")
except:
print("STR relationships already deleted")