-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_buildKG_pipeline.smk
342 lines (317 loc) · 22 KB
/
run_buildKG_pipeline.smk
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
"""
This file is a SnakeMake Script to automate the MetagenomicKG construction pipeline.
Usage:
snakemake --cores 16 -s run_buildKG_pipeline.smk targets
"""
## Import Config Files
configfile: "./config.yml"
## Import Python standard libraries
import os, sys
import subprocess
## Define Some Global Variables
ROOT_PATH = os.getcwd()
DATA_PATH = os.path.join(ROOT_PATH, 'data')
SCRIPT_PATH = os.path.join(ROOT_PATH, 'build_KG')
GTDB_version = config['BUILD_KG_VARIABLES']['GTDB_VERSION']
GTDB_DOWNLOAD_URL = f'https://data.gtdb.ecogenomic.org/releases/release{GTDB_version}/{GTDB_version}.0/'
if 'UMLS_API_KEY' in os.environ and os.environ['UMLS_API_KEY']:
umls_apikey = os.environ['UMLS_API_KEY']
elif 'UMLS_API_KEY' in config['BUILD_KG_VARIABLES'] and config['BUILD_KG_VARIABLES']['UMLS_API_KEY']:
umls_apikey = config['BUILD_KG_VARIABLES']['UMLS_API_KEY']
else:
raise ValueError("UMLS_API_KEY is not set in the environment or the config file. Please set it in 'config.yaml' file before running the pipeline.")
node_synonymizer_dbname = 'node_synonymizer_v1.0_KG2.8.4.sqlite'
neo4j_dbname = 'MetagenomicsKG'
## Create Required Folders
if not os.path.exists(os.path.join(DATA_PATH, "KEGG_data")):
os.makedirs(os.path.join(DATA_PATH, "KEGG_data"))
if not os.path.exists(os.path.join(DATA_PATH, "GTDB_data")):
os.makedirs(os.path.join(DATA_PATH, "GTDB_data"))
if not os.path.exists(os.path.join(DATA_PATH, "Micobial_hierarchy")):
os.makedirs(os.path.join(DATA_PATH, "Micobial_hierarchy"))
if not os.path.exists(os.path.join(DATA_PATH, "merged_KG")):
os.makedirs(os.path.join(DATA_PATH, "merged_KG"))
if not os.path.exists(os.path.join(DATA_PATH, "neo4j")):
os.makedirs(os.path.join(DATA_PATH, "neo4j"))
## Download GTDB Data
# Call the wget command using subprocess
if not os.path.exists(os.path.join(DATA_PATH, "GTDB_data", f"bac120_taxonomy_r{GTDB_version}.tsv")) or \
not os.path.exists(os.path.join(DATA_PATH, "GTDB_data", f"bac120_metadata_r{GTDB_version}.tar.gz")) or \
not os.path.exists(os.path.join(DATA_PATH, "GTDB_data", f"ar53_taxonomy_r{GTDB_version}.tsv")) or \
not os.path.exists(os.path.join(DATA_PATH, "GTDB_data", f"ar53_metadata_r{GTDB_version}.tar.gz")):
for cur_file in [f'bac120_taxonomy_r{GTDB_version}.tsv', f'bac120_metadata_r{GTDB_version}.tar.gz', f'ar53_taxonomy_r{GTDB_version}.tsv', f'ar53_metadata_r{GTDB_version}.tar.gz',]:
destination_path = os.path.join(DATA_PATH, "GTDB_data", cur_file)
result = subprocess.run(["wget", "-O", destination_path, GTDB_DOWNLOAD_URL + cur_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Check if the download was successful
if result.returncode == 0:
if cur_file.endswith('.tar.gz'):
result = subprocess.run(["tar", "-xvzf", destination_path, '-C', os.path.join(DATA_PATH, "GTDB_data")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {destination_path} downloaded and extracted successfully!")
else:
print(f"Error extracting file {destination_path}.")
else:
print(f"File {destination_path} downloaded successfully!")
print(f"File {destination_path} downloaded successfully!")
else:
print(f"Error downloading file {destination_path}.")
## Download RTX-KG2 data
if not os.path.exists(os.path.join(DATA_PATH, "RTX_KG2", "kg2c-tsv.tar.gz")):
raise ValueError("the kg2c-tsv.tar.gz file is not present in the RTX_KG2 folder. Please contact authors to get access and download it to ./data/RTX_KG2 folder.")
else:
if not os.path.exists(os.path.join(DATA_PATH, "RTX_KG2", "nodes_c_header.tsv")) or \
not os.path.exists(os.path.join(DATA_PATH, "RTX_KG2", "edges_c_header.tsv")) or \
not os.path.exists(os.path.join(DATA_PATH, "RTX_KG2", "nodes_c.tsv")) or \
not os.path.exists(os.path.join(DATA_PATH, "RTX_KG2", "edges_c.tsv")):
result = subprocess.run(["tar", "-xvzf", os.path.join(DATA_PATH, "RTX_KG2", "kg2c-tsv.tar.gz"), '-C', os.path.join(DATA_PATH, "RTX_KG2")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'RTX_KG2', 'kg2c-tsv.tar.gz')} extracted successfully!")
else:
print(f"Error extracting file {os.path.join(DATA_PATH, 'RTX_KG2', 'kg2c-tsv.tar.gz')}.")
## Check required files from Zenodo and download if not present
# Download NodeSynonymizer database
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", node_synonymizer_dbname)):
# add code to download the file from Zenodo
result = subprocess.run(["curl", "--cookie", "zenodo-cookies.txt", "https://zenodo.org/record/10806617/files/node_synonymizer_v1.0_KG2.8.4.sqlite?download=1", "--output", os.path.join(DATA_PATH, "Zenodo_data", node_synonymizer_dbname)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {node_synonymizer_dbname} downloaded successfully!")
else:
print(f"Error downloading file {node_synonymizer_dbname}.")
# Download pathogen database tar file
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", "pathogen_database.tar.gz")):
# add code to download the file from Zenodo
result = subprocess.run(["curl", "--cookie", "zenodo-cookies.txt", "https://zenodo.org/record/10806617/files/pathogen_database.tar.gz?download=1", "--output", os.path.join(DATA_PATH, "Zenodo_data", "pathogen_database.tar.gz")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'pathogen_database.tar.gz')} downloaded successfully!")
else:
print(f"Error downloading file {os.path.join(DATA_PATH, 'Zenodo_data', 'pathogen_database.tar.gz')}.")
else:
if not os.path.exists(os.path.join(DATA_PATH, "pathogen_database")):
result = subprocess.run(["tar", "-xvzf", os.path.join(DATA_PATH, "Zenodo_data", "pathogen_database.tar.gz"), '-C', os.path.join(DATA_PATH, "Zenodo_data")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'pathogen_database.tar.gz')} extracted successfully!")
else:
print(f"Error extracting file for pathogen_database from {os.path.join(DATA_PATH, 'Zenodo_data', 'pathogen_database.tar.gz')}.")
# Download GTDB_tk taxonomy assignment
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk.tar.gz")):
# add code to download the file from Zenodo
result = subprocess.run(["curl", "--cookie", "zenodo-cookies.txt", "https://zenodo.org/record/10806617/files/taxonomy_assignment_by_GTDB_tk.tar.gz?download=1", "--output", os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk.tar.gz")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'taxonomy_assignment_by_GTDB_tk.tar.gz')} downloaded successfully!")
else:
print(f"Error downloading file for {os.path.join(DATA_PATH, 'Zenodo_data', 'taxonomy_assignment_by_GTDB_tk.tar.gz')}.")
else:
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk")):
result = subprocess.run(["tar", "-xvzf", os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk.tar.gz"), '-C', os.path.join(DATA_PATH, "Zenodo_data")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'taxonomy_assignment_by_GTDB_tk.tar.gz')} extracted successfully!")
else:
print(f"Error extracting file for {os.path.join(DATA_PATH, 'Zenodo_data', 'taxonomy_assignment_by_GTDB_tk.tar.gz')}.")
# Download AMRFinderResults
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", "AMRFinderResults.tar.gz")):
# add code to download the file from Zenodo
result = subprocess.run(["curl", "--cookie", "zenodo-cookies.txt", "https://zenodo.org/record/10806617/files/AMRFinderResults.tar.gz?download=1", "--output", os.path.join(DATA_PATH, "Zenodo_data", "AMRFinderResults.tar.gz")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'AMRFinderResults.tar.gz')} downloaded successfully!")
else:
print(f"Error downloading file for {os.path.join(DATA_PATH, 'Zenodo_data', 'AMRFinderResults.tar.gz')}.")
else:
if not os.path.exists(os.path.join(DATA_PATH, "Zenodo_data", "AMRFinderResults")):
result = subprocess.run(["tar", "-xvzf", os.path.join(DATA_PATH, "Zenodo_data", "AMRFinderResults.tar.gz"), '-C', os.path.join(DATA_PATH, "Zenodo_data")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode == 0:
print(f"File {os.path.join(DATA_PATH, 'Zenodo_data', 'AMRFinderResults.tar.gz')} extracted successfully!")
else:
print(f"Error extracting file for {os.path.join(DATA_PATH, 'Zenodo_data', 'AMRFinderResults.tar.gz')}.")
## Build Rules
rule targets:
input:
os.path.join(DATA_PATH, "Micobial_hierarchy", "archaea_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "bacteria_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "fungi_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "viruses_hierarchy.tsv"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_compounds.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_pathways.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_modules.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_glycans.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_reactions.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_enzymes.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_networks.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_koids.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_diseases.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_drugs.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_rclasses.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_dgroups.txt"),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v1.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v1.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v2.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v2.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v3.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v3.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v4.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v4.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v5.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v5.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v6.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v6.tsv'),
os.path.join(DATA_PATH, "neo4j", "input_files", 'nodes.tsv'),
os.path.join(DATA_PATH, "neo4j", "input_files", 'edges.tsv')
# Get Taxonomy hierarchy for Archeaa and Bacteria from GTDB as well as Fungi and Viruses from NCBI Taxonomy
rule step0_get_taxonomy:
input:
script = ancient(os.path.join(SCRIPT_PATH, "get_hierarchy.py")),
bacteria_taxonomy = ancient(os.path.join(DATA_PATH, "GTDB_data", f"bac120_taxonomy_r{GTDB_version}.tsv")),
archaea_taxonomy = ancient(os.path.join(DATA_PATH, "GTDB_data", f"ar53_taxonomy_r{GTDB_version}.tsv")),
bacteria_metadata = ancient(os.path.join(DATA_PATH, "GTDB_data", f"bac120_metadata_r{GTDB_version}.tsv")),
archaea_metadata = ancient(os.path.join(DATA_PATH, "GTDB_data", f"ar53_metadata_r{GTDB_version}.tsv")),
output_dir = ancient(os.path.join(DATA_PATH, "Micobial_hierarchy"))
output:
os.path.join(DATA_PATH, "Micobial_hierarchy", "archaea_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "bacteria_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "fungi_hierarchy.tsv"),
os.path.join(DATA_PATH, "Micobial_hierarchy", "viruses_hierarchy.tsv")
run:
shell("python {input.script} --output_dir {input.output_dir} --bacteria_taxonomy {input.bacteria_taxonomy} --archaea_taxonomy {input.archaea_taxonomy} --bacteria_metadata {input.bacteria_metadata} --archaea_metadata {input.archaea_metadata}")
# Process the KEGG FTP data and download KEGG link info from APIs
rule step1_process_kegg_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "kegg_utils", "extract_KEGG_data.py")),
kegg_data_dir = ancient(config['BUILD_KG_VARIABLES']['KEGG_FTP_DATA_DIR']),
output_dir = ancient(os.path.join(DATA_PATH, "KEGG_data"))
params:
microb_only = True
output:
os.path.join(DATA_PATH, "KEGG_data", "kegg_compounds.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_pathways.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_modules.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_glycans.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_reactions.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_enzymes.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_networks.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_koids.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_diseases.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_drugs.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_rclasses.txt"),
os.path.join(DATA_PATH, "KEGG_data", "kegg_dgroups.txt")
run:
if params.microb_only:
shell("python {input.script} --kegg_data_dir {input.kegg_data_dir} --microb_only --output_dir {input.output_dir}")
else:
shell("python {input.script} --kegg_data_dir {input.kegg_data_dir} --output_dir {input.output_dir}")
# Integrate microbial hierarchy into a KG
rule step2_integrate_microbial_hierarchy:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_microbial_hierarchy.py")),
data_dir = ancient(os.path.join(DATA_PATH, "Micobial_hierarchy")),
bacteria_metadata = ancient(os.path.join(DATA_PATH, "GTDB_data", "bac120_metadata_r214.tsv")),
archaea_metadata = ancient(os.path.join(DATA_PATH, "GTDB_data", "ar53_metadata_r214.tsv")),
archaea_hierarchy_unused = ancient(os.path.join(DATA_PATH, "Micobial_hierarchy", "archaea_hierarchy.tsv")),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v1.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v1.tsv')
run:
shell("python {input.script} --data_dir {input.data_dir} --bacteria_metadata {input.bacteria_metadata} --archaea_metadata {input.archaea_metadata} --output_dir {input.output_dir}")
# Integrate knowledge from KEGG into a KG
rule step3_integrate_kegg_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_KEGG.py")),
kegg_data_dir = ancient(config['BUILD_KG_VARIABLES']['KEGG_FTP_DATA_DIR']),
kegg_processed_data_dir = ancient(os.path.join(DATA_PATH, "KEGG_data")),
gtdb_assignment = ancient(os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk", "merged_KEGG_assignment.tsv")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v1.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v1.tsv')),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG")),
unused_file = ancient(os.path.join(DATA_PATH, "KEGG_data", "kegg_compounds.txt"))
params:
microb_only = True,
ani_threshold = 99.5,
af_threshold = 0.0
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v2.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v2.tsv')
run:
if params.microb_only:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --kegg_data_dir {input.kegg_data_dir} --kegg_processed_data_dir {input.kegg_processed_data_dir} --gtdb_assignment {input.gtdb_assignment} --microb_only --ANI_threshold {params.ani_threshold} --AF_threshold {params.af_threshold} --output_dir {input.output_dir}")
else:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --kegg_data_dir {input.kegg_data_dir} --kegg_processed_data_dir {input.kegg_processed_data_dir} --gtdb_assignment {input.gtdb_assignment} --ANI_threshold {params.ani_threshold} --AF_threshold {params.af_threshold} --output_dir {input.output_dir}")
# Integrate KG2 data into into a KG
rule step4_integrate_kg2_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_KG2.py")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v2.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v2.tsv')),
data_dir = ancient(os.path.join(DATA_PATH, "RTX_KG2")),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v3.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v3.tsv')
run:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --data_dir {input.data_dir} --output_dir {input.output_dir}")
# Integrate BVBRC data into the a KG
rule step5_integrate_bvbrc_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_BVBRC.py")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v3.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v3.tsv')),
data_dir = ancient(os.path.join(DATA_PATH, "Zenodo_data", "pathogen_database", "BV-BRC")),
gtdb_assignment = ancient(os.path.join(DATA_PATH, "Zenodo_data", "taxonomy_assignment_by_GTDB_tk", "merged_BVBRC_assignment.tsv")),
synonymizer_dir = ancient(os.path.join(DATA_PATH, "Zenodo_data")),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
params:
umls_api_key = umls_apikey,
synonymizer_dbname = node_synonymizer_dbname,
ani_threshold = 99.5,
af_threshold = 0.0
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v4.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v4.tsv')
run:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --data_dir {input.data_dir} --gtdb_assignment {input.gtdb_assignment} --synonymizer_dir {input.synonymizer_dir} --synonymizer_dbname {params.synonymizer_dbname} --umls_api_key {params.umls_api_key} --ANI_threshold {params.ani_threshold} --AF_threshold {params.af_threshold} --output_dir {input.output_dir}")
# Integarte MicroPhenoDB data into a KG
rule step5_integrate_micropheno_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_MicroPhenoDB.py")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v4.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v4.tsv')),
data_dir = ancient(os.path.join(DATA_PATH, "Zenodo_data", 'pathogen_database', 'MicroPhenoDB')),
synonymizer_dir = ancient(os.path.join(DATA_PATH, "Zenodo_data")),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
params:
umls_api_key = umls_apikey,
synonymizer_dbname = node_synonymizer_dbname
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v5.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v5.tsv')
run:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --data_dir {input.data_dir} --synonymizer_dir {input.synonymizer_dir} --synonymizer_dbname {params.synonymizer_dbname} --umls_api_key {params.umls_api_key} --output_dir {input.output_dir}")
# Integrate AMR data into a KG
rule step6_integrate_amr_data:
input:
script = ancient(os.path.join(SCRIPT_PATH, "integrate_AMR.py")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v5.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v5.tsv')),
amr_result = ancient(os.path.join(DATA_PATH, "Zenodo_data", 'AMRFinderResults', 'all_AMR_result.tsv')),
amr_metadata = ancient(os.path.join(DATA_PATH, "Zenodo_data", 'AMRFinderResults', 'ReferenceGeneCatalog.txt')),
output_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
params:
coverage_threshold = 80,
identity_threshold = 90
output:
os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v6.tsv'),
os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v6.tsv')
run:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --amr_result {input.amr_result} --amr_metadata {input.amr_metadata} --coverage_threshold {params.coverage_threshold} --identity_threshold {params.identity_threshold} --output_dir {input.output_dir}")
# Prepare neo4j input files
rule step7_prepare_neo4j_inputs:
input:
script = ancient(os.path.join(SCRIPT_PATH, "neo4j_utils", "prepare_neo4j_inputs.py")),
existing_KG_nodes = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_nodes_v6.tsv')),
existing_KG_edges = ancient(os.path.join(DATA_PATH, "merged_KG", 'KG_edges_v6.tsv')),
kg_dir = ancient(os.path.join(DATA_PATH, "merged_KG"))
params:
output_dir = os.path.join(DATA_PATH, "neo4j", "input_files")
output:
os.path.join(DATA_PATH, "neo4j", "input_files", 'nodes.tsv'),
os.path.join(DATA_PATH, "neo4j", "input_files", 'edges.tsv')
run:
shell("python {input.script} --existing_KG_nodes {input.existing_KG_nodes} --existing_KG_edges {input.existing_KG_edges} --kg_dir {input.kg_dir} --output_dir {params.output_dir}")