-
Notifications
You must be signed in to change notification settings - Fork 48
/
build_rmats
executable file
·104 lines (87 loc) · 2.68 KB
/
build_rmats
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
#!/bin/bash
function show_usage() {
echo "$0 [--conda] [--no-paired-model]" 1>&2
echo
echo '--conda: create a conda environment for Python and R dependencies' 1>&2
echo '--no-paired-model: do not install dependencies for the paired model' 1>&2
}
function parse_arguments() {
local CONDA_FLAG='--conda'
local NO_PAIRED_FLAG='--no-paired-model'
USE_CONDA=0
USE_PAIRED=1
if [[ "$#" -eq 1 ]]; then
if [[ "$1" == "${CONDA_FLAG}" ]]; then
USE_CONDA=1
elif [[ "$1" == "${NO_PAIRED_FLAG}" ]]; then
USE_PAIRED=0
else
show_usage
return 1
fi
elif [[ "$#" -eq 2 ]]; then
if [[ ("$1" == "${CONDA_FLAG}" && "$2" == "${NO_PAIRED_FLAG}")\
|| ("$1" == "${NO_PAIRED_FLAG}" && "$2" == "${CONDA_FLAG}") ]]; then
USE_CONDA=1
USE_PAIRED=0
else
show_usage
return 1
fi
elif [[ "$#" -ne 0 ]]; then
show_usage
return 1
fi
}
function set_script_dir() {
local REL_SCRIPT_DIR="$(dirname ${BASH_SOURCE[0]})" || return 1
cd "${REL_SCRIPT_DIR}" || return 1
SCRIPT_DIR="$(pwd)" || return 1
}
function create_and_activate_conda_env() {
local CONDA_ENV_PATH="${SCRIPT_DIR}/conda_envs/rmats"
conda create --prefix "${CONDA_ENV_PATH}" || return 1
conda activate "${CONDA_ENV_PATH}" || return 1
}
function install_conda_dependencies() {
# Combine all requirements into a single file so the dependencies can
# be resolved all at once.
local ALL_REQUIREMENTS="${SCRIPT_DIR}/conda_requirements.txt"
local PYTHON_REQUIREMENTS="${SCRIPT_DIR}/python_conda_requirements.txt"
local R_REQUIREMENTS="${SCRIPT_DIR}/r_conda_requirements.txt"
cp "${PYTHON_REQUIREMENTS}" "${ALL_REQUIREMENTS}" || return 1
if [[ "${USE_PAIRED}" -eq 1 ]]; then
cat "${R_REQUIREMENTS}" >> "${ALL_REQUIREMENTS}" || return 1
fi
conda install -c conda-forge --file "${ALL_REQUIREMENTS}" || return 1
}
function build_rmats() {
GSL_LDFLAGS="$(gsl-config --libs)" || return 1
GSL_CFLAGS="$(gsl-config --cflags)" || return 1
export GSL_LDFLAGS || return 1
export GSL_CFLAGS || return 1
make || return 1
}
function install_pairadise() {
if [[ ! -d PAIRADISE ]]; then
git clone https://github.com/Xinglab/PAIRADISE.git || return 1
fi
Rscript install_r_deps.R || return 1
}
function main() {
set_script_dir || return 1
parse_arguments "$@" || return 1
source "${SCRIPT_DIR}/setup_environment.sh" || return 1
if [[ "${USE_CONDA}" -eq 1 ]]; then
create_and_activate_conda_env || return 1
install_conda_dependencies || return 1
fi
build_rmats || return 1
if [[ "${USE_PAIRED}" -eq 1 ]]; then
install_pairadise || return 1
fi
if [[ "${USE_CONDA}" -eq 1 ]]; then
conda deactivate || return 1
fi
}
main "$@"