-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpubmed.sh
193 lines (131 loc) · 4.62 KB
/
pubmed.sh
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
#!/bin/bash
TASK=$1
# Get Text from PubMed ID & PMC ID
if [ "$TASK" = "pmids" ]; then
echo "Get text from PubMed ID and PMC ID list"
PM_TYPE=$TASK
MY_DATA=$2
PMIDS="data/$MY_DATA/pmid.txt"
TEXT_DIR="data/$MY_DATA/text/"
python pubmed/pubmed2text.py $PM_TYPE $PMIDS $TEXT_DIR
# Get Text from PubMed ID
elif [ "$TASK" = "pmid" ]; then
echo "Get text from PubMed ID"
PMID=$2
TEXT_DIR="data/my-pubmed/text/"
python pubmed/pubmed2text.py $TASK $PMID $TEXT_DIR
# Get Text from PMC ID
elif [ "$TASK" = "pmcid" ]; then
echo "Get text from PMC ID"
PMCID=$2
TEXT_DIR="data/my-pubmed/text/"
python pubmed/pubmed2text.py $TASK $PMCID $TEXT_DIR
# Preprocess
elif [ "$TASK" = "preprocess" ]; then
echo "Preprocess pubmed text"
MY_DATA=$2
IN_DIR="data/$MY_DATA"
OUT_DIR="data/tmp/"
python scripts/preprocess.py --indir $IN_DIR --outdir $OUT_DIR
mv "$OUT_DIR" "$IN_DIR/processed-text"
# Generate config
elif [ "$TASK" = "config" ]; then
echo "Generate pubmed config"
MY_DATA=$2
MODEL_NAME=$3
GPU=$4
EXP_DIR="experiments/"
python scripts/generate_configs.py $EXP_DIR $MY_DATA $MODEL_NAME $GPU
# predict
elif [ "$TASK" = "predict" ]; then
echo "Predict: "
MY_DATA=$2
EXP_DIR="experiments/$MY_DATA"
# predict
python predict.py --yaml $EXP_DIR/configs/$TASK-$MY_DATA.yaml
# retrieve offset
elif [ "$TASK" = "offset" ]; then
echo "Retrieve original offsets: "
MY_DATA=$2
# paths
REFDIR="data/$MY_DATA/processed-text/text" # reference gold data
PREDDIR="experiments/$MY_DATA/results/ev-last/ev-tok-ann/"
OUTDIR="experiments/$MY_DATA/results/ev-last/" # retrieve the original offsets
python scripts/postprocess.py $REFDIR $PREDDIR $OUTDIR $MY_DATA
# prepare data for brat
elif [ "$TASK" = "brat" ]; then
echo "Prepare data for brat"
MY_DATA=$2
MODEL_NAME=$3
PRED_DIR="experiments/$MY_DATA/results/ev-last/$MY_DATA-brat/"
BRAT_DIR="brat/brat-v1.3_Crunchy_Frog/data/"
# annotation file
CONFIG="configs/brat/$MODEL_NAME"
if [ -d $CONFIG ]; then
cp $CONFIG/* $PRED_DIR
fi
# brat
cp -r $PRED_DIR $BRAT_DIR
elif [ "$TASK" = "e2e" ]; then
echo "End-to-end event extraction"
echo "--------------------------------"
echo "1. Prepare input raw text"
PM_TYPE=$2
MY_DATA=$3 # a single PMID (e.g 1370299) or data name (e.g my-pubmed)
# Get Text from a single PubMed ID
if [[ "$PM_TYPE" = "pmid" || "$PM_TYPE" = "pmcid" ]] ; then
echo "Get text from PubMed ID"
PMID=$MY_DATA
TEXT_DIR="data/$PMID/text/"
python pubmed/pubmed2text.py $PM_TYPE $PMID $TEXT_DIR
# list of pmid
elif [ "$PM_TYPE" = "pmids" ]; then
echo "Get text from PubMed ID and PMC ID list"
PMIDS="data/$MY_DATA/pmid.txt"
TEXT_DIR="data/$MY_DATA/text/"
python pubmed/pubmed2text.py $PM_TYPE $PMIDS $TEXT_DIR
# already have raw text
elif [ "$PM_TYPE" = "rawtext" ]; then
TEXT_DIR="data/$MY_DATA/text/"
echo "Process the raw text:" $TEXT_DIR
fi
echo "--------------------------------"
echo "2. Preprocess pubmed text"
IN_DIR="data/$MY_DATA"
OUT_DIR="data/tmp/"
python scripts/preprocess.py --indir $IN_DIR --outdir $OUT_DIR
mv "$OUT_DIR" "$IN_DIR/processed-text"
echo "--------------------------------"
echo "3. Generate pubmed config"
MODEL_NAME=$4
GPU=$5
EXP_DIR="experiments/"
python scripts/generate_configs.py $EXP_DIR $MY_DATA $MODEL_NAME $GPU
echo "--------------------------------"
echo "4. Predict: "
EXP_DIR="experiments/$MY_DATA"
# predict
python predict.py --yaml $EXP_DIR/configs/predict-$MY_DATA.yaml
echo "--------------------------------"
echo "5. Retrieve original offsets: "
# paths
REFDIR="data/$MY_DATA/processed-text/text" # reference gold data
PREDDIR="experiments/$MY_DATA/results/ev-last/ev-tok-ann/"
OUTDIR="experiments/$MY_DATA/results/ev-last/" # retrieve the original offsets
python scripts/postprocess.py $REFDIR $PREDDIR $OUTDIR $MY_DATA
echo "--------------------------------"
echo "6. Prepare data for brat"
PRED_DIR="experiments/$MY_DATA/results/ev-last/$MY_DATA-brat/"
BRAT_DIR="brat/brat-v1.3_Crunchy_Frog/data/"
# annotation file
CONFIG="configs/brat/$MODEL_NAME"
if [ -d $CONFIG ]; then
cp $CONFIG/* $PRED_DIR
fi
# brat
cp -r $PRED_DIR $BRAT_DIR
echo "Done end-to-end prediction for: " $PMID
echo "Check the prediction at: " $PRED_DIR
echo "Data for brat visualization at: " "$BRAT_DIR$MY_DATA-brat"
fi
echo "Done!"