forked from mskcc/ACCESS-Pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·100 lines (81 loc) · 2.95 KB
/
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
#!/bin/bash
# ----------------------------------------------------------------------------------------------------
# Title: setup.sh
# Description: Setup conda environment for ACCESS pipeline and install all the python and R libraries.
# Dependency: conda>=4.6.14; environment.yaml (in the same directory as this script)
# Usage: ./setup.sh <optional_environment_name>
# ----------------------------------------------------------------------------------------------------
#############
# Functions #
#############
HOSTNAME=$(hostname -s)
function printe () {
# print error message
printf "\n$HOSTNAME::$(date +'%T')::ERROR $@\n"
}
function printi () {
# print info
printf "\n$HOSTNAME::$(date +'%T')::INFO $@\n"
}
function cleanup() {
# Housekeeping function that will run at the end regardless of
# exit status. Upon successful setup, deactivate environment.
# If setup is unsuccessful at any stage, remove the environment.
EXITCODE=$?
if [[ $EXITCODE != 0 ]] && [[ -e ${ACCESS_ENV_PATH} ]]; then
source deactivate
printe "Installation unsuccessful. Removing conda environment: ${ACCESS_ENV}"
conda env remove -n ${ACCESS_ENV}
fi
exit $EXITCODE
}
trap cleanup EXIT
###########################
# Setup Conda Environment #
###########################
# Check for environment name
ACCESS_ENV=$1
[[ ! -z $ACCESS_ENV ]] || {
printi "No preferred environment name given. Conda environment name will be set to 'ACCESS'";
ACCESS_ENV="ACCESS";
}
# set library paths
[[ ! -z "${LIBRARY_PATH}" ]] || {
printi "LIBRARY_PATH not set. Will be default to /usr/lib64";
export LIBRARY_PATH="/usr/lib64";
}
[[ ! -z "${LD_LIBRARY_PATH}" ]] || {
printi "LD_LIBRARY_PATH not set. Will be defaulted to /usr/lib64";
export LD_LIRBARY_PATH="/usr/lib64";
}
# Check for conda installation
type -p conda > /dev/null || {
printe "Conda installation is required! Visit https://www.anaconda.com/distribution/";
exit 1;
}
# Set pythonpath
export PYTHONPATH="" # to avoid conflicts with system python libraries
# TODO:
# Upgrade/Downgrade conda version?
[[ -e "${PWD}/environment.yaml" ]] || {
printe "${PWD}/environment.yaml not found.";
exit 1;
}
# get conda path
CONDA=$(type -p conda | sed "s/conda is //")
[[ -e $CONDA ]] || {
printe "Cannot find conda binary. Make sure conda is added to your PATH variable.";
exit 1;
}
# ensure that no other env with the same name exist
ACCESS_ENV_PATH=$(echo $CONDA | sed "s/bin\/conda/envs\/${ACCESS_ENV}/")
[[ ! -e ${ACCESS_ENV_PATH} ]] || {
printi "${ACCESS_ENV_PATH} already exist.";
exit 0;
}
printi "Creating conda environment: $ACCESS_ENV"
conda env create --name $ACCESS_ENV --file $PWD/environment.yaml
EXITCODE=$?
[[ $EXITCODE == 0 ]] || exit $EXITCODE;
printi "ACCESS environment setup complete! \^.^/"
source deactivate