Mercurial > repos > pjbriggs > amplicon_analysis_pipeline
comparison install_amplicon_analysis-1.3.6.sh @ 4:86a12d75ebe4 draft default tip
planemo upload for repository https://github.com/pjbriggs/Amplicon_analysis-galaxy commit 7be61b7ed35ca3deaad68d2eae384c8cd365bcb8
author | pjbriggs |
---|---|
date | Fri, 20 Dec 2019 06:59:49 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:3ab198df8f3f | 4:86a12d75ebe4 |
---|---|
1 #!/bin/sh -e | |
2 # | |
3 # Prototype script to setup a conda environment with the | |
4 # dependencies needed for the Amplicon_analysis_pipeline | |
5 # script | |
6 # | |
7 # Handle command line | |
8 usage() | |
9 { | |
10 echo "Usage: $(basename $0) [DIR]" | |
11 echo "" | |
12 echo "Installs the Amplicon_analysis_pipeline package plus" | |
13 echo "dependencies in directory DIR (or current directory " | |
14 echo "if DIR not supplied)" | |
15 } | |
16 if [ ! -z "$1" ] ; then | |
17 # Check if help was requested | |
18 case "$1" in | |
19 --help|-h) | |
20 usage | |
21 exit 0 | |
22 ;; | |
23 esac | |
24 # Assume it's the installation directory | |
25 cd $1 | |
26 fi | |
27 # Versions | |
28 PIPELINE_VERSION=1.3.6 | |
29 CONDA_REQUIRED_VERSION=4.6.14 | |
30 RDP_CLASSIFIER_VERSION=2.2 | |
31 # Directories | |
32 TOP_DIR=$(pwd)/Amplicon_analysis-${PIPELINE_VERSION} | |
33 BIN_DIR=${TOP_DIR}/bin | |
34 CONDA_DIR=${TOP_DIR}/conda | |
35 CONDA_BIN=${CONDA_DIR}/bin | |
36 CONDA_LIB=${CONDA_DIR}/lib | |
37 CONDA=${CONDA_BIN}/conda | |
38 ENV_NAME="amplicon_analysis_pipeline@${PIPELINE_VERSION}" | |
39 ENV_DIR=${CONDA_DIR}/envs/$ENV_NAME | |
40 # | |
41 # Functions | |
42 # | |
43 # Report failure and terminate script | |
44 fail() | |
45 { | |
46 echo "" | |
47 echo ERROR $@ >&2 | |
48 echo "" | |
49 echo "$(basename $0): installation failed" | |
50 exit 1 | |
51 } | |
52 # | |
53 # Rewrite the shebangs in the installed conda scripts | |
54 # to remove the full path to conda 'bin' directory | |
55 rewrite_conda_shebangs() | |
56 { | |
57 pattern="s,^#!${CONDA_BIN}/,#!/usr/bin/env ,g" | |
58 find ${CONDA_BIN} -type f -exec sed -i "$pattern" {} \; | |
59 } | |
60 # | |
61 # Reset conda version if required | |
62 reset_conda_version() | |
63 { | |
64 CONDA_VERSION="$(${CONDA_BIN}/conda -V 2>&1 | head -n 1 | cut -d' ' -f2)" | |
65 echo conda version: ${CONDA_VERSION} | |
66 if [ "${CONDA_VERSION}" != "${CONDA_REQUIRED_VERSION}" ] ; then | |
67 echo "Resetting conda to last known working version $CONDA_REQUIRED_VERSION" | |
68 ${CONDA_BIN}/conda config --set allow_conda_downgrades true | |
69 ${CONDA_BIN}/conda install -y conda=${CONDA_REQUIRED_VERSION} | |
70 else | |
71 echo "conda version ok" | |
72 fi | |
73 } | |
74 # | |
75 # Install conda | |
76 install_conda() | |
77 { | |
78 echo "++++++++++++++++" | |
79 echo "Installing conda" | |
80 echo "++++++++++++++++" | |
81 if [ -e ${CONDA_DIR} ] ; then | |
82 echo "*** $CONDA_DIR already exists ***" >&2 | |
83 return | |
84 fi | |
85 local cwd=$(pwd) | |
86 local wd=$(mktemp -d) | |
87 cd $wd | |
88 wget -q https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh | |
89 bash ./Miniconda2-latest-Linux-x86_64.sh -b -p ${CONDA_DIR} | |
90 echo Installed conda in ${CONDA_DIR} | |
91 echo -n "Adding conda bin to PATH..." | |
92 export PATH=${CONDA_BIN}:$PATH | |
93 echo "ok" | |
94 # Reset the conda version to a known working version | |
95 # (to avoid problems observed with e.g. conda 4.7.10) | |
96 echo "" | |
97 reset_conda_version | |
98 # Update the installation files | |
99 # This is to avoid problems when the length the installation | |
100 # directory path exceeds the limit for the shebang statement | |
101 # in the conda files | |
102 echo "" | |
103 echo -n "Rewriting conda shebangs..." | |
104 rewrite_conda_shebangs | |
105 echo "ok" | |
106 cd $cwd | |
107 rm -rf $wd/* | |
108 rmdir $wd | |
109 } | |
110 # | |
111 # Create conda environment | |
112 install_conda_packages() | |
113 { | |
114 echo "+++++++++++++++++++++++++" | |
115 echo "Installing conda packages" | |
116 echo "+++++++++++++++++++++++++" | |
117 local cwd=$(pwd) | |
118 local wd=$(mktemp -d) | |
119 cd $wd | |
120 cat >environment.yml <<EOF | |
121 name: ${ENV_NAME} | |
122 channels: | |
123 - defaults | |
124 - conda-forge | |
125 - bioconda | |
126 dependencies: | |
127 - python=2.7 | |
128 - cutadapt=1.8 | |
129 - sickle-trim=1.33 | |
130 - bioawk=1.0 | |
131 - pandaseq=2.8.1 | |
132 - spades=3.10.1 | |
133 - fastqc=0.11.3 | |
134 - qiime=1.9.1 | |
135 - blast-legacy=2.2.26 | |
136 - fasta-splitter=0.2.6 | |
137 - rdp_classifier=$RDP_CLASSIFIER_VERSION | |
138 - vsearch=2.10.4 | |
139 - r=3.5.1 | |
140 - r-tidyverse=1.2.1 | |
141 - bioconductor-dada2=1.8 | |
142 - bioconductor-biomformat=1.8.0 | |
143 EOF | |
144 ${CONDA} env create --name "${ENV_NAME}" -f environment.yml | |
145 if [ $? -ne 0 ] ; then | |
146 fail "Non-zero exit status from 'conda env create'" | |
147 elif [ ! -e "${ENV_DIR}" ] ; then | |
148 fail "Failed to create conda environment: ${ENV_DIR} not found" | |
149 fi | |
150 echo Created conda environment in ${ENV_DIR} | |
151 cd $cwd | |
152 rm -rf $wd/* | |
153 rmdir $wd | |
154 # | |
155 # Patch qiime 1.9.1 tools to switch deprecated 'axisbg' | |
156 # matplotlib property to 'facecolor': | |
157 # https://matplotlib.org/api/prev_api_changes/api_changes_2.0.0.html | |
158 echo "" | |
159 for exe in make_2d_plots.py plot_taxa_summary.py ; do | |
160 echo -n "Patching ${exe}..." | |
161 find ${CONDA_DIR} -type f -name "$exe" -exec sed -i 's/axisbg=/facecolor=/g' {} \; | |
162 echo "done" | |
163 done | |
164 # | |
165 # Patch qiime 1.9.1 tools to switch deprecated 'set_axis_bgcolor' | |
166 # method call to 'set_facecolor': | |
167 # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_axis_bgcolor.html | |
168 for exe in make_rarefaction_plots.py ; do | |
169 echo -n "Patching ${exe}..." | |
170 find ${CONDA_DIR} -type f -name "$exe" -exec sed -i 's/set_axis_bgcolor/set_facecolor/g' {} \; | |
171 echo "done" | |
172 done | |
173 } | |
174 # | |
175 # Install all the non-conda dependencies in a single | |
176 # function (invokes separate functions for each package) | |
177 install_non_conda_packages() | |
178 { | |
179 echo "+++++++++++++++++++++++++++++" | |
180 echo "Installing non-conda packages" | |
181 echo "+++++++++++++++++++++++++++++" | |
182 # Temporary working directory | |
183 local wd=$(mktemp -d) | |
184 local cwd=$(pwd) | |
185 local wd=$(mktemp -d) | |
186 cd $wd | |
187 # Amplicon analysis pipeline | |
188 echo -n "Installing Amplicon_analysis_pipeline..." | |
189 if [ -e ${BIN_DIR}/Amplicon_analysis_pipeline.sh ] ; then | |
190 echo "already installed" | |
191 else | |
192 install_amplicon_analysis_pipeline | |
193 echo "ok" | |
194 fi | |
195 # ChimeraSlayer | |
196 echo -n "Installing ChimeraSlayer..." | |
197 if [ -e ${BIN_DIR}/ChimeraSlayer.pl ] ; then | |
198 echo "already installed" | |
199 else | |
200 install_chimeraslayer | |
201 echo "ok" | |
202 fi | |
203 # Uclust | |
204 # This no longer seems to be available for download from | |
205 # drive5.com so don't download | |
206 echo "WARNING uclust not available: skipping installation" | |
207 } | |
208 # | |
209 # Amplicon analyis pipeline | |
210 install_amplicon_analysis_pipeline() | |
211 { | |
212 local wd=$(mktemp -d) | |
213 local cwd=$(pwd) | |
214 local wd=$(mktemp -d) | |
215 cd $wd | |
216 wget -q https://github.com/MTutino/Amplicon_analysis/archive/${PIPELINE_VERSION}.tar.gz | |
217 tar zxf ${PIPELINE_VERSION}.tar.gz | |
218 cd Amplicon_analysis-${PIPELINE_VERSION} | |
219 INSTALL_DIR=${TOP_DIR}/share/amplicon_analysis_pipeline-${PIPELINE_VERSION} | |
220 mkdir -p $INSTALL_DIR | |
221 ln -s $INSTALL_DIR ${TOP_DIR}/share/amplicon_analysis_pipeline | |
222 for f in *.sh *.R ; do | |
223 /bin/cp $f $INSTALL_DIR | |
224 done | |
225 /bin/cp -r uc2otutab $INSTALL_DIR | |
226 mkdir -p ${BIN_DIR} | |
227 cat >${BIN_DIR}/Amplicon_analysis_pipeline.sh <<EOF | |
228 #!/usr/bin/env bash | |
229 # | |
230 # Point to Qiime config | |
231 export QIIME_CONFIG_FP=${TOP_DIR}/qiime/qiime_config | |
232 # Set up the RDP jar file | |
233 export RDP_JAR_PATH=${TOP_DIR}/share/rdp_classifier/rdp_classifier-${RDP_CLASSIFIER_VERSION}.jar | |
234 # Set the Matplotlib backend | |
235 export MPLBACKEND="agg" | |
236 # Put the scripts onto the PATH | |
237 export PATH=${BIN_DIR}:${INSTALL_DIR}:\$PATH | |
238 # Activate the conda environment | |
239 export PATH=${CONDA_BIN}:\$PATH | |
240 source ${CONDA_BIN}/activate ${ENV_NAME} | |
241 # Execute the driver script with the supplied arguments | |
242 $INSTALL_DIR/Amplicon_analysis_pipeline.sh \$@ | |
243 exit \$? | |
244 EOF | |
245 chmod 0755 ${BIN_DIR}/Amplicon_analysis_pipeline.sh | |
246 cat >${BIN_DIR}/install_reference_data.sh <<EOF | |
247 #!/usr/bin/env bash -e | |
248 # | |
249 function usage() { | |
250 echo "Usage: \$(basename \$0) DIR" | |
251 } | |
252 if [ -z "\$1" ] ; then | |
253 usage | |
254 exit 0 | |
255 elif [ "\$1" == "--help" ] || [ "\$1" == "-h" ] ; then | |
256 usage | |
257 echo "" | |
258 echo "Install reference data into DIR" | |
259 exit 0 | |
260 fi | |
261 echo "==========================================" | |
262 echo "Installing Amplicon analysis pipeline data" | |
263 echo "==========================================" | |
264 if [ ! -e "\$1" ] ; then | |
265 echo "Making directory \$1" | |
266 mkdir -p \$1 | |
267 fi | |
268 cd \$1 | |
269 DATA_DIR=\$(pwd) | |
270 echo "Installing reference data under \$DATA_DIR" | |
271 $INSTALL_DIR/References.sh | |
272 echo "" | |
273 echo "Use '-r \$DATA_DIR' when running Amplicon_analysis_pipeline.sh" | |
274 echo "to use the reference data from this directory" | |
275 echo "" | |
276 echo "\$(basename \$0): finished" | |
277 EOF | |
278 chmod 0755 ${BIN_DIR}/install_reference_data.sh | |
279 cd $cwd | |
280 rm -rf $wd/* | |
281 rmdir $wd | |
282 } | |
283 # | |
284 # ChimeraSlayer | |
285 install_chimeraslayer() | |
286 { | |
287 local cwd=$(pwd) | |
288 local wd=$(mktemp -d) | |
289 cd $wd | |
290 wget -q https://sourceforge.net/projects/microbiomeutil/files/__OLD_VERSIONS/microbiomeutil_2010-04-29.tar.gz | |
291 tar zxf microbiomeutil_2010-04-29.tar.gz | |
292 cd microbiomeutil_2010-04-29 | |
293 INSTALL_DIR=${TOP_DIR}/share/microbiome_chimeraslayer-2010-04-29 | |
294 mkdir -p $INSTALL_DIR | |
295 ln -s $INSTALL_DIR ${TOP_DIR}/share/microbiome_chimeraslayer | |
296 /bin/cp -r ChimeraSlayer $INSTALL_DIR | |
297 cat >${BIN_DIR}/ChimeraSlayer.pl <<EOF | |
298 #!/usr/bin/env bash | |
299 export PATH=$INSTALL_DIR:\$PATH | |
300 $INSTALL_DIR/ChimeraSlayer/ChimeraSlayer.pl $@ | |
301 EOF | |
302 chmod 0755 ${INSTALL_DIR}/ChimeraSlayer/ChimeraSlayer.pl | |
303 chmod 0755 ${BIN_DIR}/ChimeraSlayer.pl | |
304 cd $cwd | |
305 rm -rf $wd/* | |
306 rmdir $wd | |
307 } | |
308 # | |
309 # uclust required for QIIME/pyNAST | |
310 # License only allows this version to be used with those two packages | |
311 # See: http://drive5.com/uclust/downloads1_2_22q.html | |
312 install_uclust() | |
313 { | |
314 local cwd=$(pwd) | |
315 local wd=$(mktemp -d) | |
316 cd $wd | |
317 wget -q http://drive5.com/uclust/uclustq1.2.22_i86linux64 | |
318 INSTALL_DIR=${TOP_DIR}/share/uclust-1.2.22 | |
319 mkdir -p $INSTALL_DIR | |
320 ln -s $INSTALL_DIR ${TOP_DIR}/share/uclust | |
321 /bin/mv uclustq1.2.22_i86linux64 ${INSTALL_DIR}/uclust | |
322 chmod 0755 ${INSTALL_DIR}/uclust | |
323 ln -s ${INSTALL_DIR}/uclust ${BIN_DIR} | |
324 cd $cwd | |
325 rm -rf $wd/* | |
326 rmdir $wd | |
327 } | |
328 setup_pipeline_environment() | |
329 { | |
330 echo "+++++++++++++++++++++++++++++++" | |
331 echo "Setting up pipeline environment" | |
332 echo "+++++++++++++++++++++++++++++++" | |
333 # fasta_splitter.pl | |
334 echo -n "Setting up fasta_splitter.pl..." | |
335 if [ -e ${BIN_DIR}/fasta-splitter.pl ] ; then | |
336 echo "already exists" | |
337 elif [ ! -e ${ENV_DIR}/share/fasta-splitter/fasta-splitter.pl ] ; then | |
338 echo "failed" | |
339 fail "fasta-splitter.pl not found" | |
340 else | |
341 ln -s ${ENV_DIR}/share/fasta-splitter/fasta-splitter.pl ${BIN_DIR}/fasta-splitter.pl | |
342 echo "ok" | |
343 fi | |
344 # rdp_classifier.jar | |
345 local rdp_classifier_jar=rdp_classifier-${RDP_CLASSIFIER_VERSION}.jar | |
346 echo -n "Setting up rdp_classifier.jar..." | |
347 if [ -e ${TOP_DIR}/share/rdp_classifier/${rdp_classifier_jar} ] ; then | |
348 echo "already exists" | |
349 elif [ ! -e ${ENV_DIR}/share/rdp_classifier/rdp_classifier.jar ] ; then | |
350 echo "failed" | |
351 fail "rdp_classifier.jar not found" | |
352 else | |
353 mkdir -p ${TOP_DIR}/share/rdp_classifier | |
354 ln -s ${ENV_DIR}/share/rdp_classifier/rdp_classifier.jar ${TOP_DIR}/share/rdp_classifier/${rdp_classifier_jar} | |
355 echo "ok" | |
356 fi | |
357 # qiime_config | |
358 echo -n "Setting up qiime_config..." | |
359 if [ -e ${TOP_DIR}/qiime/qiime_config ] ; then | |
360 echo "already exists" | |
361 else | |
362 mkdir -p ${TOP_DIR}/qiime | |
363 cat >${TOP_DIR}/qiime/qiime_config <<EOF-qiime-config | |
364 qiime_scripts_dir ${ENV_DIR}/bin | |
365 EOF-qiime-config | |
366 echo "ok" | |
367 fi | |
368 } | |
369 # | |
370 # Top level script does the installation | |
371 echo "=======================================" | |
372 echo "Amplicon_analysis_pipeline installation" | |
373 echo "=======================================" | |
374 echo "Installing into ${TOP_DIR}" | |
375 if [ -e ${TOP_DIR} ] ; then | |
376 fail "Directory already exists" | |
377 fi | |
378 mkdir -p ${TOP_DIR} | |
379 install_conda | |
380 install_conda_packages | |
381 install_non_conda_packages | |
382 setup_pipeline_environment | |
383 echo "====================================" | |
384 echo "Amplicon_analysis_pipeline installed" | |
385 echo "====================================" | |
386 echo "" | |
387 echo "Install reference data using:" | |
388 echo "" | |
389 echo "\$ ${BIN_DIR}/install_reference_data.sh DIR" | |
390 echo "" | |
391 echo "Run pipeline scripts using:" | |
392 echo "" | |
393 echo "\$ ${BIN_DIR}/Amplicon_analysis_pipeline.sh ..." | |
394 echo "" | |
395 echo "(or add ${BIN_DIR} to your PATH)" | |
396 echo "" | |
397 echo "$(basename $0): finished" | |
398 ## | |
399 # |