-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.sh
executable file
·212 lines (181 loc) · 4.69 KB
/
pipeline.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
function usage { cat << EOF
USAGE
bash pipeline.sh
DESCRIPTION
Create the new version of the GATEWAy database
OPTIONS
--clean does EVERYTHING
defaults to: no
--verbose | -v adds verbose output
defaults to: no
EOF
}
clean=no
verbose=no
for arg in "$@"
do
case "$arg" in
-\?|--help)
usage
exit
;;
--clean)
clean=yes
shift
;;
-v|--verbose)
verbose=yes
shift
;;
--)
shift
break
;;
-*)
echo "unrecognized option: $1" >&2
exit 1
;;
*)
break
;;
esac
done
if [[ $verbose == yes ]]
then
cat << EOF
clean=$clean
EOF
fi
bold=$(tput bold)
normal=$(tput sgr0)
echo ""
echo " ${bold}========== GATEWAy v.2.0 ==========${normal} "
# --------------------------------------
# unzip v.1.0
# --------------------------------------
if [[ ! -e data/283_2_FoodWebDataBase_2018_12_10.csv ]]
then
echo " - Unzipping v.1.0"
cd data
unzip v.1.0.zip
cd ..
else
echo " - Already unzipped"
fi
# --------------------------------------
# string manipulations of v.1.0
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.cleaned" ]]
then
echo " - Cleaning strings"
cd data
bash ../scripts/clean-gateway.sh 283_2_FoodWebDataBase_2018_12_10.csv gateway-cleaned.csv &&
touch ../steps/.cleaned
cd ..
else
echo " - Already cleaned"
fi
# --------------------------------------
# process new data
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.newdata" ]]
then
echo " - Process new data"
Rscript --vanilla scripts/mulder.R &&
Rscript --vanilla scripts/tagus.R &&
touch steps/.newdata
else
echo " - New data already processed"
fi
if [[ $clean == yes ]] || [[ ! -e "steps/.names" ]]
then
echo " - Extracting species names"
Rscript --vanilla scripts/extract-species-names.R &&
touch steps/.names
else
echo " - Names already extracted"
fi
# --------------------------------------
# query against GBIF
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.gbif" ]]
then
echo " - Querying GBIF"
Rscript --vanilla scripts/taxonomic-backbone.R data &&
touch steps/.gbif
cp data/taxonomy.csv data/v.2.0/taxonomy.csv
else
echo " - GBIF already queried"
fi
# --------------------------------------
# add new data
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.combined" ]]
then
echo " - Add new data"
Rscript --vanilla scripts/combine.R data/gateway-cleaned.csv &&
touch steps/.combined
else
echo " - New data already added"
fi
# --------------------------------------
# harmonize taxonomy
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.harmonized" ]]
then
echo " - Harmonize taxonomy"
Rscript --vanilla scripts/harmonize-taxonomy.R \
data/gateway-combined.csv data/taxonomy.csv &&
touch steps/.harmonized
else
echo " - Taxonomy already harmonized"
fi
# --------------------------------------
# rename as v.2.0
# --------------------------------------
cp data/gateway-harmonized.csv data/v.2.0/GATEWAy-v.2.0.csv
echo " - New dataset is: ${bold}data/v.2.0/GATEWAy-v.2.0.csv${normal}"
# --------------------------------------
# rename and split tables for website
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.renamed" ]]
then
echo " - Rename fields and split tables"
Rscript --vanilla scripts/relational.R data/gateway-v.2.0.csv &&
touch steps/.renamed
else
echo " - Fields already renamed and tables split"
fi
# --------------------------------------
# restructure database for website
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.restructured" ]]
then
echo " - Restructure database for SQL"
Rscript --vanilla scripts/restructure-relational.R data &&
touch steps/.restructured
else
echo " - Tables already restructures"
fi
# --------------------------------------
# shapefiles for website
# --------------------------------------
if [[ $clean == yes ]] || [[ ! -e "steps/.shapefiled" ]]
then
echo " - Create shapefile"
Rscript --vanilla scripts/shapefiles.R data &&
touch steps/.shapefiled
else
echo " - Shapefiles already created"
fi
# --------------------------------------
# summary
# --------------------------------------
echo " - Summary:"
fw=$(wc -l data/v.2.0/foodwebs.csv | cut -d ' ' -f 1)
n=$(wc -l data/v.2.0/interactions.csv | cut -d ' ' -f 1)
echo " -- $fw unique food webs"
echo " -- $n unique interactions"
echo " ================================================== "
echo ""