-
Notifications
You must be signed in to change notification settings - Fork 9
/
execute.py
136 lines (112 loc) · 3.86 KB
/
execute.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
import argparse
from pathlib import Path
import json
import wget
from scripts.download_full_text import download_full_text, merge_full_text
from scripts.extract_tags import extract_annotations
from scripts.hetnet_id_extractor import filter_tags
from scripts.map_ids import map_ids
from scripts.pubtator_to_xml import convert_pubtator
parser = argparse.ArgumentParser(
description='Runs Pubtator/Pubtator Central Parser Pipeline'
)
parser.add_argument(
"--config", help="The config file for the extractor.",
default="config_files/pubtator_central_config.json"
)
args = parser.parse_args()
configuration = json.load(open(args.config, "r"))
if (
"repository_download" in configuration and
not configuration["repository_download"]["skip"]
):
print("Executing repository_download...")
wget.download(
configuration["repository_download"]['url'],
out=configuration["repository_download"]['download_folder']
)
del configuration["repository_download"]
if (
"pubtator_to_xml" in configuration and
not configuration["pubtator_to_xml"]["skip"]
):
print("Executing pubtator_to_xml...")
convert_pubtator(
configuration["pubtator_to_xml"]['documents'],
configuration["pubtator_to_xml"]['output']
)
del configuration["pubtator_to_xml"]
if (
"extract_tags" in configuration and
not configuration["extract_tags"]["skip"]
):
print("Executing extract_tags...")
extract_annotations(
configuration["extract_tags"]["input"],
configuration["extract_tags"]["output"]
)
del configuration["extract_tags"]
if (
"hetnet_id_extractor" in configuration and
not configuration["hetnet_id_extractor"]["skip"]
):
print("Executing hetnet_id_extractor...")
filter_tags(
configuration["hetnet_id_extractor"]["input"],
configuration["hetnet_id_extractor"]["output"]
)
del configuration["hetnet_id_extractor"]
if (
"map_pmids_to_pmcids" in configuration and
not configuration["map_pmids_to_pmcids"]["skip"]
):
print("Executing map_pmids_to_pmcids...")
map_ids(
configuration["map_pmids_to_pmcids"]["input"],
configuration["map_pmids_to_pmcids"]["output"],
configuration["map_pmids_to_pmcids"]["debug"]
)
del configuration["map_pmids_to_pmcids"]
if (
"download_full_text" in configuration and
not configuration["download_full_text"]["skip"]
):
print("Executing download_full_text...")
download_full_text(
configuration["download_full_text"]["input"],
configuration["download_full_text"]["document_batch"],
configuration["download_full_text"]["temp_dir"],
configuration["download_full_text"]["log_file"]
)
merge_full_text(
configuration["download_full_text"]["temp_dir"],
configuration["download_full_text"]["output"]
)
del configuration["download_full_text"]
if (
"extract_full_text_tags" in configuration and
not configuration["extract_full_text_tags"]["skip"]
):
print("Executing extract_full_text_tags...")
extract_annotations(
configuration["extract_full_text_tags"]["input"],
configuration["extract_full_text_tags"]["output"]
)
del configuration["extract_full_text_tags"]
if (
"hetnet_id_extractor_full_text" in configuration and
not configuration["hetnet_id_extractor_full_text"]["skip"]
):
print("Executing hetnet_id_extractor_full_text...")
filter_tags(
configuration["hetnet_id_extractor_full_text"]["input"],
configuration["hetnet_id_extractor_full_text"]["output"]
)
del configuration["hetnet_id_extractor_full_text"]
if len(configuration) > 0:
not_executed_commands = '\n'.join(configuration.keys())
print(
"\n"
"Commands not executed:\n"
f"{not_executed_commands}"
)