-
Notifications
You must be signed in to change notification settings - Fork 23
/
genenetwork2
executable file
·227 lines (207 loc) · 7.59 KB
/
genenetwork2
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
#! /bin/bash
#
# This is the startup script for GN2. It sets the environment variables to pick
# up a Guix profile and allows for overriding parameters.
#
# Typical usage
#
# env GN2_PROFILE=~/opt/genenetwork2-phewas ./bin/genenetwork2 ~/my_settings.py
#
# Where GN2_PROFILE points to the GNU Guix profile used for deployment.
#
# This will run the GN2 server (with default settings if none
# supplied). Typically you need a GNU Guix profile which is set with
# an environment variable (this profile is dictated by the
# installation path of genenetwork). Say your profile is in
# ~/opt/gn-latest-guix
#
# env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2
#
# You can pass in your own settings file, e.g.
#
# env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2 ~/my_settings.py
#
# To run a maintenance python script with settings (instead of the
# webserver) run from the base-dir with settings file and add that
# script with a -c switch, e.g.
#
# env GN2_PROFILE=/usr/local/guix-profiles/gn-latest-20190905 TMPDIR=/export/local/home/zas1024/gn2-zach/tmp WEBSERVER_MODE=DEBUG LOG_LEVEL=DEBUG SERVER_PORT=5002 GENENETWORK_FILES=/export/local/home/zas1024/gn2-zach/genotype_files SQL_URI=mysql://webqtlout:webqtlout@lily.uthsc.edu/db_webqtl ./bin/genenetwork2 ./gn2/default_settings.py -c ./maintenance/gen_select_dataset.py
#
# To run any script in the environment
#
# env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2 ./gn2/default_settings.py -cli echo "HELLO WORLD"
#
# To get a python REPL(!)
#
# env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2 ./gn2/default_settings.py -cli python
#
# For development you may want to run
#
# env GN2_PROFILE=~/opt/gn-latest WEBSERVER_MODE=DEBUG LOG_LEVEL=DEBUG ./bin/genenetwork2
#
# For staging and production we use gunicorn. Run with something like
# (note you have to provide the server port). Provide a settings file!
#
# env GN2_PROFILE=~/opt/gn-latest-guix SERVER_PORT=5003 ./bin/genenetwork2 ./gn2/default_settings.py -gunicorn-prod
#
# For development use
#
# env GN2_PROFILE=~/opt/gn-latest-guix SERVER_PORT=5003 ./bin/genenetwork2 ./gn2/default_settings.py -gunicorn-dev
#
# For extra flexibility you can also provide gunicorn parameters yourself with something like
#
# env GN2_PROFILE=~/opt/gn-latest-guix ./bin/genenetwork2 ./gn2/default_settings.py -gunicorn "--bind 0.0.0.0:5003 --workers=1 wsgi"
SCRIPT=$(realpath "$0")
echo SCRIPT="${SCRIPT}"
echo GN2_PROFILE="${GN2_PROFILE}"
GN2_BASE_DIR=$(dirname "$(dirname "${SCRIPT}")")
GN2_ID=$(cat /etc/hostname):$(basename "${GN2_BASE_DIR}")
echo GN2_BASE_DIR="${GN2_BASE_DIR}"
GUIX_SITE=$GN2_BASE_DIR/lib/python3.8/site-packages
if [ -d "${GUIX_SITE}" ]; then
echo INFO: GN2 is running from GNU Guix
GN2_BASE_DIR=$GUIX_SITE
else
echo INFO: GN2 is running from a source tree
GIT_HASH=$(git rev-parse HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi
if [ "$1" = "-c" -o "$1" = "-gunicorn" ]; then
echo "Can not use $1 switch without default settings file"
exit 1
fi
settings=$1
if [ -z "${settings}" ]; then
settings=$GN2_BASE_DIR/gn2/default_settings.py
else
shift
fi
settings=$(realpath "${settings}")
# ext="${settings##*.}"
# if [ "$ext" = "json" -o "$ext" = "JSON" ]; then
# overrides=$settings
# else
# echo $settings
# fi
if [ ! -e "${settings}" ]; then
echo "ERROR: can not locate settings file - pass it in the command line"
exit 1
fi
# If $GN2_SETTINGS is set, use that, otherwise use default provided at invocation
export GN2_SETTINGS=${GN2_SETTINGS:-$settings}
echo GN2_SETTINGS="${settings}"
if [ -z "${GN2_PROFILE}" ] ; then
echo "WARNING: GN2_PROFILE has not been set - you need the environment, so I hope you know what you are doing!"
GN2_PROFILE=$(dirname $(dirname $(which genenetwork2)))
export GN2_PROFILE
if [ -d "${GN2_PROFILE}" ]; then
echo "Best guess is $GN2_PROFILE"
fi
echo "ERROR: always set GN2_PROFILE"
exit 1
fi
if [ -z "${GN2_PROFILE}" ]; then
read -p "PRESS [ENTER] TO CONTINUE..."
else
export PATH=$GN2_PROFILE/bin:$PATH
export PYTHONPATH="$GN2_PROFILE/lib/python3.10/site-packages" # never inject another PYTHONPATH!!
export R_LIBS_SITE=$GN2_PROFILE/site-library
export JS_GUIX_PATH=$GN2_PROFILE/share/genenetwork2/javascript
export GUIX_GTK3_PATH="$GN2_PROFILE/lib/gtk-3.0"
export GI_TYPELIB_PATH="$GN2_PROFILE/lib/girepository-1.0"
export XDG_DATA_DIRS="$GN2_PROFILE/share"
export GIO_EXTRA_MODULES="$GN2_PROFILE/lib/gio/modules"
export LC_ALL=C # FIXME
export GUIX_GENENETWORK_FILES="$GN2_PROFILE/share/genenetwork2"
export PLINK_COMMAND="$GN2_PROFILE/bin/plink2"
export GEMMA_COMMAND="$GN2_PROFILE/bin/gemma"
if [ -z "${GEMMA_WRAPPER_COMMAND}" ]; then
export GEMMA_WRAPPER_COMMAND="$GN2_PROFILE/bin/gemma-wrapper"
fi
while IFS=":" read -ra PPATH; do
for PPART in "${PPATH[@]}"; do
if [ ! -d "${PPART}" ] ; then echo "$PPART in PYTHONPATH not valid $PYTHONPATH" ; exit 1 ; fi
done
done <<< "$PYTHONPATH"
if [ ! -d "${R_LIBS_SITE}" ] ; then echo "R_LIBS_SITE not valid ${R_LIBS_SITE}" ; exit 1 ; fi
fi
if [ -z "${PYTHONPATH}" ] ; then
echo "ERROR PYTHONPATH has not been set - use GN2_PROFILE!"
exit 1
fi
if [ ! -d "${R_LIBS_SITE}" ] ; then
echo "ERROR R_LIBS_SITE has not been set correctly (we only allow one path) - use GN2_PROFILE!"
echo "Paste into your shell the output of (for example)"
echo "guix package -p \$GN2_PROFILE --search-paths"
exit 1
fi
# We may change this one:
export PYTHONPATH="${PYTHON_GN_PATH:+$PYTHON_GN_PATH:}$GN2_BASE_DIR/wqflask:${GN3_PYTHONPATH:+$GN3_PYTHONPATH:}$PYTHONPATH"
# Our UNIX TMPDIR defaults to /tmp - change this on a shared server
if [ -z "${TMPDIR}" ]; then
TMPDIR="/tmp"
fi
# Show environment settings
set|grep guix
set|grep GN2_PROFILE
set|grep TMPDIR
# Now handle command parameter -c which runs python
if [ "$1" = '-c' ] ; then
echo PYTHONPATH="${PYTHONPATH}"
shift
echo "RUNNING COMMAND python ${*}"
python $*
exit $?
fi
# Now handle command parameter -cli which runs in bash
if [ "$1" = "-cli" ] ; then
cmd=$2
echo PYTHONPATH="${PYTHONPATH}"
shift ; shift
echo "RUNNING COMMAND ${cmd} ${*}"
$cmd $*
exit $?
fi
if [ "$1" = '-gunicorn' ] ; then
cmd=$2
echo PYTHONPATH="${PYTHONPATH}"
echo "RUNNING gunicorn ${cmd}"
gunicorn $cmd
exit $?
fi
if [ "$1" = '-gunicorn-dev' ] ; then
echo PYTHONPATH="${PYTHONPATH}"
if [ -z "${SERVER_PORT}" ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi
cmd="--bind 0.0.0.0:$SERVER_PORT --workers=1 --timeout 180 --reload gn2.run_gunicorn:app"
echo "RUNNING gunicorn ${cmd}"
gunicorn $cmd
exit $?
fi
if [ "$1" = '-gunicorn-prod' ] ; then
echo PYTHONPATH="${PYTHONPATH}"
if [ -z "${SERVER_PORT}" ]; then echo "ERROR: Provide a SERVER_PORT" ; exit 1 ; fi
PID=$TMPDIR/gunicorn.$USER.pid
cmd="--bind 0.0.0.0:$SERVER_PORT --pid $PID --workers 20 --keep-alive 6000 --max-requests 100 --max-requests-jitter 30 --timeout 1200 gn2.wsgi"
echo "RUNNING gunicorn ${cmd}"
gunicorn $cmd
exit $?
fi
if [ -z "$NO_REDIS" ] ; then
echo "Starting the redis server:"
echo -n "dir $TMPDIR
dbfilename gn2.rdb
" | redis-server - &
fi
# Overrides for packages that are not yet public (currently r-auwerx)
# export R_LIBS_SITE=$R_LIBS_SITE:$HOME/.Rlibs/das1i1pm54dj6lbdcsw5w0sdwhccyj1a-r-3.3.2/lib/R/lib
if [ "$1" = "--with-pdb" ] ; then
cmd=$2
echo PYTHONPATH="${PYTHONPATH}"
shift ; shift
echo "RUNNING COMMAND python3 -m gn2.runserver.py"
python3 -m pdb runserver.py
exit $?
fi
# Start the flask server running GN2
echo "Starting with $settings"
python -m gn2.runserver