forked from unipept/umgap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
umgap-setup.sh
executable file
·224 lines (200 loc) · 6.43 KB
/
umgap-setup.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
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/sh
set -e
# print stuff to stderr and exits with fault
crash() {
echo "$*" >&2
exit 1
}
# ask a yes/no question.
yesno() {
if [ "$download_all" = "true" ]; then
true
else
question="$1 [y]/n "
read -p "$question" answer
while [ "$answer" != "y" -a "$answer" != "" -a "$answer" != "n" ]; do
echo "$answer is not a valid option."
read -p "$question" answer
done
[ "$answer" != "n" ]
fi
}
# What to do if the XDG standard isn't there...
if [ -z "$XDG_CONFIG_HOME" ]; then
if [ -d "$HOME/Library/Preferences/" ]; then
config_default="$HOME/Library/Preferences/Unipept"
elif [ -d "$HOME/.config" ]; then
# why weren't the XDG variables set then?
config_default="$HOME/.config/unipept"
else
config_default="$HOME/.unipept"
fi
else
config_default="$XDG_CONFIG_HOME/unipept"
fi
if [ -z "$XDG_DATA_HOME" ]; then
if [ -d "$HOME/Library/Application Support" ]; then
data_default="$HOME/Library/Application Support/Unipept"
elif [ -d "$HOME/.local/share" ]; then
data_default="$HOME/.local/share/unipept"
else
data_default="$HOME/.unipept/data"
fi
else
data_default="$XDG_DATA_HOME/unipept"
fi
DATASERVER='https://unipept.ugent.be/system/umgap'
USAGE="
Setup the UMGAP by downloading the database and finding dependencies.
Usage: $0 [options]
Options:
-c dir The configuration directory. Defaults to '$config_default'.
-f dir Directory containing the FragGeneScan++ binary (FGSpp) and
training data.
-d dir The data directory. The database files will be downloaded here.
Defaults to '$data_default'.
-y Download all files of the latest version without asking.
"
while getopts c:f:d:y f; do
case "$f" in
c) configdir="$OPTARG" ;;
f) fgsppdir="$OPTARG" ;;
d) datadir="$OPTARG" ;;
y) download_all="true" ;;
\?) crash "$USAGE" ;;
esac
done
# If no config directory is provided, use the default. Create it.
if [ -z "$configdir" ]; then
configdir="$config_default"
if [ -d "$configdir" ]; then
echo "Using existing '$configdir' as config directory."
else
if ! yesno "Use '$configdir' as configuration directory?"; then
crash "Please set a configuration directory with '-c'."
fi
fi
fi
if [ ! -d "$configdir" ]; then
if mkdir -p "$configdir"; then
echo "Created directory ${configdir}."
else
crash 'Could not create the configuration directory.'
fi
fi
# If FGSpp is found and works, link it in the config directory.
if [ -z "$fgsppdir" ]; then
if ! yesno 'FragGeneScan++ (-f) was not provided, only pipelines not using it will be available.'; then
crash 'Pass the location of FragGeneScan++ with -f.'
fi
else
cd "$fgsppdir"
if ! printf '>a\nA' | ./FGSpp -s stdin -o stdout -w 0 -t illumina_10 -c 240 > /dev/null; then
crash 'Invoking FGSpp failed, follow installation instructions at https://github.com/unipept/FragGeneScanPlusPlus.'
fi
fgsppdir="$(pwd -P)" # make path absolute
cd - > /dev/null
if ln -f -s "$fgsppdir" "$configdir/FGSpp"; then
echo 'Found, tested and remembered the FragGeneScan++ location.'
else
crash 'Could not link the FragGeneScan++ location.'
fi
fi
# If no data directory is provided, use the default. Create it.
if [ -z "$datadir" ]; then
datadir="$data_default"
if [ -d "$datadir" ]; then
echo "Using existing '$datadir' as data directory."
else
if ! yesno "Use '$datadir' as data directory?"; then
crash "Please set a data directory with '-d'."
fi
fi
fi
if [ ! -d "$datadir" ]; then
if mkdir -p "$datadir"; then
echo "Created directory ${datadir}."
else
crash "Could not create the data directory."
fi
fi
cd "$datadir"
datadir="$(pwd -P)" # make path absolute
cd - > /dev/null
# How can we download stuff
human() {
if numfmt --version > /dev/null; then
numfmt --to=iec-i --suffix=B
return
fi
number="$(cat -)"
for unit in "B" "KiB" "MiB" "GiB"; do
if [ "$number" -lt 9999 ]; then
printf '%d%s' "$number" "$unit"
return
fi
number="$(( number / 1024 ))"
done
printf '%d%s' "$number" "$unit"
}
if wget -V > /dev/null 2>&1; then
get() { wget -q -O - "$1"; }
size() { wget --spider --server-response "$1" 2>&1 | sed -n 's/ *[Cc]ontent-[Ll]ength: \([0-9]*\)\r*/\1/p' | human; }
download() { wget -O "$2" "$1"; }
elif curl -V > /dev/null 2>&1; then
get() { curl -s "$1"; }
size() { curl -s -I "$1" | sed -n 's/ *[Cc]ontent-[Ll]ength: \([0-9]*\)\r*/\1/p' | human; }
download() { curl -o "$2" "$1"; }
else
crash 'Neither curl nor wget is available to download data.'
fi
# Retrieving the latest version from unipept
echo 'Checking the latest version on the server.'
version="$(get "$DATASERVER/latest")"
if [ "$?" != 0 ]; then
crash 'Could not retrieve version from server.'
fi
echo "Latest version is ${version}."
echo
echo 'For any type of analysis, you need a taxonomony. For mapping tryptic or'
echo '9-mer peptides to it, you need the respective index file of the same'
echo 'version.'
echo
# Checking the files for this version.
taxons="$DATASERVER/$version/taxons.tsv"
if [ -h "$configdir/$version/taxons.tsv" ]; then
echo "Taxonomy is available at the latest version."
elif yesno "Would you like to download the taxonomy from ${version} ($(size "$taxons"))?"; then
download_taxons="true"
fi
tryptic="$DATASERVER/$version/tryptic.fst"
if [ -h "$configdir/$version/tryptic.fst" ]; then
echo "Tryptic index is available at the latest version."
elif yesno "Would you like to download the tryptic index from ${version} ($(size "$tryptic"))?"; then
download_tryptic="true"
fi
ninemer="$DATASERVER/$version/ninemer.fst"
if [ -h "$configdir/$version/ninemer.fst" ]; then
echo "9-mer index is available at the latest version."
elif yesno "Would you like to download the 9-mer index from ${version} ($(size "$ninemer"))?"; then
download_ninemer="true"
fi
if [ "$download_taxons" = "true" -o "$download_ninemer" = "true" -o "$download_ninemer" = "true" ]; then
mkdir -p "$datadir/$version"
mkdir -p "$configdir/$version"
fi
if [ "$download_taxons" = "true" ]; then
download "$taxons" "$datadir/$version/taxons.tsv"
chmod 644 "$datadir/$version/taxons.tsv"
ln -f -s "$datadir/$version/taxons.tsv" "$configdir/$version/taxons.tsv"
fi
if [ "$download_tryptic" = "true" ]; then
download "$tryptic" "$datadir/$version/tryptic.fst"
chmod 644 "$datadir/$version/tryptic.fst"
ln -f -s "$datadir/$version/tryptic.fst" "$configdir/$version/tryptic.fst"
fi
if [ "$download_ninemer" = "true" ]; then
download "$ninemer" "$datadir/$version/ninemer.fst"
chmod 644 "$datadir/$version/ninemer.fst"
ln -f -s "$datadir/$version/ninemer.fst" "$configdir/$version/ninemer.fst"
fi