-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathINSTALL.sh
executable file
·279 lines (251 loc) · 7.37 KB
/
INSTALL.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
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
#!/bin/bash
set -eo pipefail
# EukMS pipelines to generate
PIPELINES=(run report refine)
# CLI arguments
THREADS="1"
SOURCE_SCRIPT=~/.bashrc
UNINSTALL=false
UPGRADE=false
# Installation location
CWD="$(pwd)"
# Conda location information
CONDA="$(which conda)"
CONDA_DIRNAME="$(dirname "$CONDA")"
MINICONDA="$(dirname "$CONDA_DIRNAME")"
SOURCE="$MINICONDA/etc/profile.d/conda.sh"
# Installation directories
BIN=bin
DATA=data
function usage() {
echo ""
echo "EukMetaSanity v1.1.0 Installation"
echo "Usage: ./INSTALL.sh [-h] | [[-t <threads>] [-b /source/script]] | [--upgrade [-t <threads>]] | [--uninstall]"
echo ""
echo ""
echo "-h|--help Display this help message"
echo "-t|--threads <threads> Number of threads to use in building indices"
echo "-b|--bash-source-script <path> Script to add PATH updates, default is ~/.bashrc"
echo "--uninstall Uninstall EukMetaSanity"
echo "--upgrade Upgrade EukMetaSanity"
echo ""
echo ""
echo "Examples"
echo "--------"
echo "Basic Installation"
echo "./INSTALL.sh -t 8"
echo "Place EukMetaSanity PATH updated in non-default location (i.e., not ~/.bashrc)"
echo "./INSTALL.sh -t 8 -b ~/.scripts"
echo "Upgrade installation"
echo "./INSTALL.sh -t 6 --upgrade"
echo "Uninstall EukMetaSanity"
echo "./INSTALL.sh --uninstall"
echo ""
}
# Check if conda environment exists
function is_installed() {
[ "$(conda info --envs | grep -c "$1")" -eq 1 ]
}
# Check if conda environment doesn't exist
function not_installed() {
[ "$(conda info --envs | grep -c "$1")" -eq 0 ]
}
# Uninstall all EukMetaSanity conda environments. Delete bin and data directories
function uninstall() {
# Remove conda environments
for f in "${PIPELINES[@]}"; do
if is_installed "EukMS_$f"; then
conda remove --name "EukMS_$f" --all -y
fi
done
# Remove installer, if not already done so
if is_installed yapim_installer; then
conda remove --name yapim_installer --all -y
fi
rm -rf "$BIN"
rm -rf "$DATA"
}
# Generate EukMetaSanity bin pipeline directories
function create_binary_directory() {
local DO_INSTALL=false
for f in "${PIPELINES[@]}"; do
if "$UPGRADE" || [ ! -d "$BIN/$f-pipeline" ]; then
DO_INSTALL=true
break
fi
done
if "$DO_INSTALL"; then
# Create and activate installer environment
if not_installed yapim_installer; then
mamba env create -f EukMetaSanity/src/installer-environment.yml
fi
source "$SOURCE"
conda activate yapim_installer
pip install .
# Generate binary directories using the YAPIM `create` function
for f in "${PIPELINES[@]}"; do
echo n | yapim create -t "EukMetaSanity/src/$f" -d EukMetaSanity/src/dependencies -o "$BIN/$f-pipeline"
done
# Deactivate and delete installer environment
conda deactivate
conda remove --name yapim_installer --all -y
fi
}
# Install mamba if not already present
function install_mamba() {
if [ "$(conda list | grep -c mamba)" -lt 1 ]; then
conda install mamba -n base -c conda-forge -y
fi
}
# Install EukMS package to environment
function pip_install_env() {
source "$SOURCE"
conda activate "EukMS_$1"
python -m pip install .
conda deactivate
}
# Usage: install_env <env-name>
function install_env() {
local ENV_FILE="$BIN/$1-pipeline/$1/environment.yml"
if not_installed "EukMS_$1"; then
mamba env create -f "$ENV_FILE"
pip_install_env "$1"
elif "$UPGRADE"; then
mamba env update -f "$ENV_FILE"
pip_install_env "$1"
fi
}
# Add EukMS definitions to source script (default is ~/.bashrc)
function update_source_script() {
if [ "$(grep -c "EukMS_run=$2" "$SOURCE_SCRIPT")" -lt 1 ]; then
echo "# Environment variables are part of EukMetaSanity installation." >> "$1"
echo "# Remove on program deletion" >> "$1"
echo export PATH="$(pwd)/$BIN/":'$PATH' >> "$1"
echo export EukMS_run="$2" >> "$1"
echo export EukMS_report="$(pwd)/$BIN/report-pipeline" >> "$1"
echo export EukMS_refine="$(pwd)/$BIN/refine-pipeline" >> "$1"
echo "# # # # # #" >> "$1"
fi
}
# Create repeats.txt installation instructions with download path
# Usage: modify_rm_location <install-path>
function modify_rm_location() {
# Install RepeatMasker updated libraries and configure
cd "$MINICONDA/envs/EukMS_run/share/RepeatMasker/Libraries/"
# Download data if $UPGRADE is set or if file 'installation-complete' is not present
if "$UPGRADE" || [ ! -f ../installation-complete ]; then
source "$SOURCE"
conda activate EukMS_run
rm -f Dfam.h5 Dfam.h5.gz
wget https://www.dfam.org/releases/Dfam_3.2/families/Dfam.h5.gz
gunzip Dfam.h5.gz
# Move up to RepeatMasker top-level
cd ..
sed "s,INSTALLATION_LOCATION,$1," "$CWD/install/repeats.default.txt" > "$CWD/install/repeats.txt"
# Configure installation. If download is skipped, uses smaller, less-complete repeat database
perl ./configure < "$CWD/install/repeats.txt"
rm "$CWD/install/repeats.txt"
cp util/rmOutToGFF3.pl ./
conda deactivate
touch installation-complete
fi
cd "$CWD"
}
# Update conda versions of augustus for proper id parsing
function update_augustus() {
cd "$MINICONDA/envs/EukMS_run/bin"
sed -i 's/transcript_id \"(\.\*)\"/transcript_id \"(\\S\+)"/' filterGenesIn_mRNAname.pl
cd "$MINICONDA/envs/EukMS_refine/bin"
sed -i 's/transcript_id \"(\.\*)\"/transcript_id \"(\\S\+)"/' filterGenesIn_mRNAname.pl
cd "$CWD"
}
# Create run environment and install repeat modeler updates
function install_eukms_run() {
install_env run
modify_rm_location "$MINICONDA/envs/EukMS_run/bin/"
}
# # # # # Begin # # # # #
# Validate top-level working directory
if [ "$(dirname "$0")" != . ]; then
>&2 echo "Run installation script from EukMetaSanity top-level directory"
usage
exit 1
fi
# Validate conda source path
if [ ! -f "$SOURCE" ]; then
>&2 echo "There was an error locating your conda installation"
exit 1
fi
# Parse command-line arguments
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-t|--threads)
THREADS="$2"
shift
shift
;;
-h|--help)
usage
exit 0
;;
-b|--bash-source-script)
SOURCE_SCRIPT="$2"
shift
shift
;;
--uninstall)
UNINSTALL=true
shift
;;
--upgrade)
UPGRADE=true
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
# Confirm correctly parsed
if [ ${#POSITIONAL[@]} -gt 0 ]; then
usage
exit 1
fi
# Confirm valid upgrade/uninstall setting
if "$UPGRADE" && "$UNINSTALL"; then
>&2 echo "Provide either --upgrade OR --uninstall flag"
exit 1
fi
# # # Uninstall EukMetaSanity # # #
if "$UNINSTALL"; then
uninstall
echo "EukMetaSanity was successfully uninstalled"
exit 0
fi
# # # Install EukMetaSanity # # #
# Installer
install_mamba
# Generate installation directory
create_binary_directory
# Create run environment
install_eukms_run
# Create report environment
install_env report
# Create refine environment
install_env refine
# Configure augustus version
update_augustus
# Update .bashrc with proper locations
EukMS_run="$CWD/$BIN/run-pipeline"
update_source_script "$SOURCE_SCRIPT" "$EukMS_run"
# Download updated databases
if "$UPGRADE" || [ ! -d "$DATA" ]; then
source "$SOURCE"
conda activate EukMS_run
download-data -t "$THREADS" --eukms-run-bin "$EukMS_run"
conda deactivate
fi
echo "Your installation is complete!"