forked from StochSS/stochss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.mac-embedded-python.sh
executable file
·529 lines (460 loc) · 16.8 KB
/
run.mac-embedded-python.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#!/usr/bin/env bash
osname=$(uname)
if [ "$osname" != 'Darwin' ]; then
echo "Error: $0 runs on Mac OSX! This is $osname"
exit
fi
# use Virtual Env
source ../local/bin/activate
# Attempt to install StochKit 2.0.10, StochOptim, and PyURDME
#
# Install it in the user's home folder by default
#
#
MY_PATH="`pwd`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
STOCHSS_HOME=$MY_PATH
STOCHSS_HOME="`( cd \"$STOCHSS_HOME\" && pwd )`"
STOCHKIT_VERSION=StochKit2.0.11
STOCHKIT_PREFIX=$STOCHSS_HOME
export STOCHKIT_HOME="$STOCHKIT_PREFIX/$STOCHKIT_VERSION"
ODE_VERSION="ode-1.0.2"
export STOCHKIT_ODE="$STOCHSS_HOME/$ODE_VERSION"
STOCHOPTIM_VERSION="stochoptim-0.5-1"
export STOCHOPTIM="$STOCHSS_HOME/$STOCHOPTIM_VERSION"
export R_LIBS="$STOCHOPTIM/library"
export MYPYTHON="$STOCHSS_HOME/../local/bin/python"
export MYPIP="$STOCHSS_HOME/../local/bin/pip"
echo "<html>"
echo "<body>"
if [ "$(echo $STOCHSS_HOME | grep " ")" != "" ]; then
echo "<font color=\"red\"><h2>Cannot install StochSS under any directory that contains spaces (which \"$STOCHSS_HOME\" has). This is an known issue</h2></font>"
exit -1
fi
echo "<h2>Checking StochSS configuration</h2><br />"
echo -n "Testing if Xcode & Command Line Tools installed... "
if ! which gcc > /dev/null; then
echo "No<br />"
echo "<font color=\"red\">"
echo "Gcc not found. Xcode or Command Line Tools not installed -- refer to documentation"
echo "</font>"
exit -1
fi
echo "Yes<br />"
#################
# Check to see if the 'dolfin' python module is installed and active in this terminal.
function check_dolfin_sub {
RET=`$MYPYTHON -c "import dolfin" 2>/dev/null`
RC=$?
if [[ $RC == 0 ]];then
return 0 #True
fi
return 1 #False
}
function check_dolfin {
if check_dolfin_sub; then
return 0 #True
else
FENICS_MAC_APP_CONF="$STOCHSS_HOME/../fenics/share/fenics/fenics.conf"
if [ -e $FENICS_MAC_APP_CONF ];then
echo "FEniCS.app found, sourcing $FENICS_MAC_APP_CONF.<br />"
FENICS_CONF_SILENT=1
source $FENICS_MAC_APP_CONF
if check_dolfin_sub;then
return 0 #True
fi
fi
fi
return 1 #False
}
function check_pyurdme_sub {
RET=`$MYPYTHON -c "import pyurdme" 2>/dev/null`
RC=$?
if [[ $RC == 0 ]];then
return 0 #True
fi
return 1 #False
}
function check_pyurdme {
PYURDME_CONF="$STOCHSS_HOME/app/lib/pyurdme-stochss/pyurdme_init"
if [ -e $PYURDME_CONF ];then
echo "PyURDME local install found, sourcing $PYURDME_CONF.<br />"
source $PYURDME_CONF
if check_pyurdme_sub;then
return 0 #True
fi
fi
return 1 #False
}
function download_pyurdme {
DIRECTORY="$STOCHSS_HOME/app/lib/pyurdme-stochss"
if [ -d "$DIRECTORY" ]; then
echo "$DIRECTORY found, pyurdme already downloaded locally (remove directory to re-download)"
return 0 #True
else
ZIP_URL="https://github.com/pyurdme/pyurdme/archive/stochss.zip"
TMPDIR=$(mktemp -d /tmp/tmp.XXXXXX)
ZIP_FILE="$TMPDIR/pyurdme.zip"
CMD="curl -o $ZIP_FILE -L $ZIP_URL"
echo $CMD
eval $CMD
if [[ -e "$ZIP_FILE" ]];then
wd=`pwd`
cd "$STOCHSS_HOME/app/lib" || return 1
pwd
CMD="unzip $ZIP_FILE > /dev/null"
echo $CMD
eval $CMD
if [[ $? != 0 ]];then
rm $ZIP_FILE
cd $wd
return 1 #False
fi
rm $ZIP_FILE
cd $wd
return 0 #True
else
return 1 #False
fi
fi
}
function check_for_lib {
if [ -z "$1" ];then
return 1 #False
fi
if [ "$1" = "mysql-connector-python" ]; then
RET=`$MYPYTHON -c "import mysql.connector" 2>/dev/null`
RC=$?
else
RET=`$MYPYTHON -c "import $1" 2>/dev/null`
RC=$?
fi
if [[ $RC != 0 ]];then
return 1 #False
fi
return 0 #True
}
function install_lib {
if [ -z "$1" ];then
return 1 #False
fi
if check_pip;then
echo ""
else
install_pip
fi
echo "We need to install the python package: $1 from the python pip package manager."
read -p "Do you want me to try to use sudo to install required package [you may be prompted for the admin password] (y/n): " answer
if [ $? != 0 ]; then
exit -1
fi
if [ "$answer" == 'y' ] || [ "$answer" == 'yes' ]; then
export ARCHFLAGS='-Wno-error=unused-command-line-argument-hard-error-in-future'
if [ "$1" = "h5py" ]; then
pkg="$1"
elif [ "$1" = "libsbml" ]; then
pkg="python-libsbml"
else
pkg="$1"
fi
CMD="sudo $MYPYTHON $MYPIP install $pkg"
echo $CMD
eval $CMD
else
exit -1
fi
}
function check_and_install_dependencies {
deps=("numpy" "scipy" "matplotlib" "h5py" "libsbml" "mysql-connector-python")
for dep in "${deps[@]}"
do
echo "Checking for $dep<br />"
if check_for_lib "$dep";then
echo "$dep detected successfully.<br />"
else
install_lib "$dep"
if check_for_lib "$dep";then
echo "$dep installed successfully.<br />"
else
echo "$dep install failed.<br />"
return 1 #False
fi
fi
done
return 0 #True
}
function check_spatial_dependencies {
deps=("numpy" "scipy" "matplotlib" "h5py" "libsbml" "mysql-connector-python")
for dep in "${deps[@]}"
do
echo "Checking for $dep<br />"
if check_for_lib "$dep";then
echo "$dep detected successfully.<br />"
else
return 1 #False
fi
done
return 0 #True
}
function check_pip {
if which pip > /dev/null;then
echo "pip is installed on your system, using it<br />"
return 0 #True
else
echo "pip is not installed on your system<br />"
return 1 #False
fi
}
function install_pip {
echo "We need to install python pip from https://bootstrap.pypa.io/get-pip.py"
read -p "Do you want me to try to use sudo to install required packages [you may be prompted for the admin password] (y/n): " answer
if [ $? != 0 ]; then
exit -1
fi
if [ "$answer" == 'y' ] || [ "$answer" == 'yes' ]; then
CMD="curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py"
echo $CMD
eval $CMD
CMD="sudo $MYPYTHON get-pip.py"
echo $CMD
eval $CMD
else
exit -1
fi
}
function install_dependencies_via_applescript {
echo "Installing missing dependencies with Applescript. This will take a few minutes.<br />"
/usr/bin/env osascript run_mac_install-embedded-python.scpt
}
function check_spatial_installation {
if check_spatial_dependencies; then
echo "All spatial dependencies detected.<br />"
else
install_dependencies_via_applescript
if check_spatial_dependencies; then
echo "All spatial dependencies detected.<br />"
else
echo "Error: dependencies not installed, exiting.<br />"
return 1 #False
fi
fi
if check_dolfin; then
echo "FEniCS/Dolfin detected successfully.<br />"
else
echo "FEniCS/Dolfin not installed, please check installation instructions.<br />"
echo "You can download FEniCS from http://fenicsproject.org/<br />"
return 1 #False
fi
echo "Running 'instant-clean'"
"$STOCHSS_HOME/../fenics/bin/instant-clean"
if check_pyurdme; then
echo "PyURDME detected successfully.<br />"
else
echo "PyURDME not installed, attempting local install.<br />"
download_pyurdme
if check_pyurdme; then
echo "PyURDME detected successfully.<br />"
else
echo "PyURDME not installed, Failing (check if all required python modules are installed).<br />"
return 1 #False
fi
fi
return 0 #True
}
#####################
echo "Check if spatial libraries are installed.<br />"
if check_spatial_installation;then
echo "Spatial libraries installed correctly.<br />"
else
echo "Error checking the spatial libraries.<br />"
exit 1
fi
#################
function retry_command {
if [ -z "$1" ];then
return 1 #False
fi
for i in `seq 1 3`;
do
echo "$1"
eval "$1"
RET=$?
if [[ $RET != 0 ]] ;then
echo "Failed to execute: \"$1\""
else
return 0 # True
fi
done
echo "Failed to execute: \"$1\", Exiting"
exit -1
}
echo -n "Testing if StochKit2 built... "
rundir=$(mktemp -d /tmp/tmp.XXXXXX)
rm -r "$rundir" >& /dev/null
if "$STOCHKIT_HOME/ssa" -m "$STOCHKIT_HOME/models/examples/dimer_decay.xml" -r 1 -t 1 -i 1 --out-dir "$rundir" >& /dev/null; then
echo "Yes <br />"
echo "$STOCHKIT_VERSION found in $STOCHKIT_HOME<br />"
else
echo "No<br />"
echo "Installing in $STOCHSS_HOME/$STOCHKIT_VERSION<br />"
echo "Cleaning up anything already there...<br />"
rm -rf "$STOCHKIT_PREFIX/$STOCHKIT_VERSION" >& /dev/null
if [ ! -e "$STOCHKIT_PREFIX/$STOCHKIT_VERSION.tgz" ]; then
echo "Downloading $STOCHKIT_VERSION..."
#curl -o "$STOCHKIT_PREFIX/$STOCHKIT_VERSION.tgz" -L "http://sourceforge.net/projects/stochkit/files/StochKit2/$STOCHKIT_VERSION/$STOCHKIT_VERSION.tgz"
curl -o "$STOCHKIT_PREFIX/$STOCHKIT_VERSION.tgz" -L "http://sourceforge.net/projects/stochkit/files/StochKit2/StochKit2.0.11/StochKit2.0.11.tgz/download"
fi
echo "Building StochKit<br />"
wd=`pwd`
cd "$STOCHKIT_PREFIX"
retry_command "tar -xzf \"$STOCHKIT_VERSION.tgz\""
tmpdir=$(mktemp -d /tmp/tmp.XXXXXX)
mv "$STOCHKIT_HOME" "$tmpdir/"
cd "$tmpdir/$STOCHKIT_VERSION"
echo " Stdout available at $STOCHSS_HOME/stdout.log and <br />"
echo " Stderr available at $STOCHSS_HOME/stderr.log<br />"
echo "<font color=\"blue\"><h3>This process will take at least 5 minutes to complete. Please be patient.</h3></font>"
STOCHKIT_HOME_R=$STOCHKIT_HOME
export STOCHKIT_HOME="$(pwd -P)"
./install.sh 1>"$STOCHSS_HOME/stdout.log" 2>"$STOCHSS_HOME/stderr.log"
export STOCHKIT_HOME=$STOCHKIT_HOME_R
cd $wd
mv "$tmpdir/$STOCHKIT_VERSION" "$STOCHKIT_HOME"
rm -r "$rundir" >& /dev/null
# Test that StochKit was installed successfully by running it on a sample model
if "$STOCHKIT_HOME/ssa" -m "$STOCHKIT_HOME/models/examples/dimer_decay.xml" -r 1 -t 1 -i 1 --out-dir "$rundir" >& /dev/null; then
echo "Success!<br \>"
else
echo "<font color=red>"
echo "Failed<br \>"
echo "$STOCHKIT_VERSION failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_HOME<br \></font>"
exit -1
fi
fi
echo -n "Testing if Stochoptim built... "
rm -r "$rundir" >& /dev/null
function check_if_StochOptim_Installed {
export R_LIBS="$STOCHOPTIM/library"
CMD="Rscript --vanilla \"$STOCHOPTIM/exec/mcem2.r\" --model \"$STOCHOPTIM/inst/extdata/birth_death_MAmodel.R\" --data \"$STOCHOPTIM/birth_death_MAdata.txt\" --steps \"\" --seed 1 --cores 1 --K.ce 1000 --K.em 100 --K.lik 10000 --K.cov 10000 --rho 0.01 --perturb 0.25 --alpha 0.25 --beta 0.25 --gamma 0.25 --k 3 --pcutoff 0.05 --qcutoff 0.005 --numIter 10 --numConverge 1 --command 'bash' >& /dev/null"
#echo $CMD
eval $CMD
RET=$?
return "$RET"
}
if check_if_StochOptim_Installed; then
echo "Yes <br />"
echo "$STOCHOPTIM_VERSION found in $STOCHOPTIM <br />"
else
echo "No <br />"
echo "Installing in $STOCHSS_HOME/$STOCHOPTIM_VERSION <br />"
echo "Cleaning up anything already there... <br />"
rm -rf "$STOCHOPTIM" >& /dev/null
echo "Building StochOptim <br />"
echo " Logging stdout in $STOCHSS_HOME/stdout.log and <br />"
echo " stderr in $STOCHSS_HOME/stderr.log <br />"
echo " <font color=\"blue\"><h3>This process will take at least 5 minutes to complete. Please be patient</h3></font>"
retry_command "tar -xzf \"$STOCHOPTIM.tgz\""
mkdir "$STOCHOPTIM/library"
RET=$?
if [[ $RET != 0 ]] ;then
echo "Failed to: mkdir \"$STOCHOPTIM/library\", exiting"
exit -1
fi
wd=`pwd`
echo install.packages\(\"optparse\", \""$STOCHOPTIM/library"\", \"http://cran.us.r-project.org\", INSTALL_opts = \"--no-multiarch\"\) > "$STOCHOPTIM/install_packages.R"
echo install.packages\(\""$STOCHOPTIM"\", \""$STOCHOPTIM/library"\", NULL, type = \"source\", INSTALL_opts = \"--no-multiarch\"\) >> "$STOCHOPTIM/install_packages.R"
Rscript "$STOCHOPTIM/install_packages.R" 1> "$STOCHSS_HOME/stdout.log" 2>"$STOCHSS_HOME/stderr.log"
export R_LIBS="$STOCHOPTIM/library"
# Test that StochKit was installed successfully by running it on a sample model
if check_if_StochOptim_Installed; then
echo "Success!<br />"
else
echo "Failed<br />"
echo "$STOCHOPTIM failed to install. Consult logs above for errors<br />"
exit -1
fi
fi
echo -n "Testing if StochKit2 ODE built... "
rm -r "$rundir" >& /dev/null
if "$STOCHKIT_ODE/ode" -m "$STOCHKIT_HOME/models/examples/dimer_decay.xml" -t 1 -i 1 --out-dir "$rundir" >& /dev/null; then
echo "Yes <br />"
echo "ode found in $STOCHKIT_ODE <br />"
else
echo "No <br />"
echo "Installing in $STOCHSS_HOME/$ODE_VERSION <br />"
echo "Cleaning up anything already there...<br />"
rm -rf "$STOCHSS_HOME/ode" >& /dev/null
stdout="$STOCHSS_HOME/stdout.log"
stderr="$STOCHSS_HOME/stderr.log"
echo "Building StochKit ODE<br />"
echo " Logging stdout in $STOCHSS_HOME/stdout.log and <br />"
echo " stderr in $STOCHSS_HOME/stderr.log <br />"
echo "<font color=\"blue\"><h3>This process should take about a minute to complete. Please be patient</h3></font><br />"
wd=`pwd`
tmpdir=$(mktemp -d /tmp/tmp.XXXXXX)
retry_command "tar -xzf \"$STOCHKIT_ODE.tgz\""
mv "$STOCHKIT_ODE" "$tmpdir"
cd "$tmpdir/$ODE_VERSION/cvodes"
retry_command "tar -xzf \"cvodes-2.7.0.tar.gz\""
cd "cvodes-2.7.0"
./configure --prefix="$PWD/cvodes" 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "<font color=red>"
echo "Failed<br />"
echo "StochKit ODE failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_ODE<br />"
echo "</font>"
exit -1
fi
make 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "<font color=red>"
echo "Failed<br />"
echo "StochKit ODE failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_ODE<br />"
echo "</font>"
exit -1
fi
make install 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "<font color=red>"
echo "Failed<br />"
echo "StochKit ODE failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_ODE<br />"
echo "</font>"
exit -1
fi
cd ../../
STOCHKIT_ODE_R=$STOCHKIT_ODE
export STOCHKIT_ODE="$(pwd -P)"
make 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "<font color=red>"
echo "Failed<br />"
echo "StochKit ODE failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_ODE<br />"
echo "</font>"
exit -1
fi
export STOCHKIT_ODE="$STOCHKIT_ODE_R"
cd ../
cd $wd
mv "$tmpdir/$ODE_VERSION" "$STOCHKIT_ODE"
# Test that StochKit was installed successfully by running it on a sample model
if "$STOCHKIT_ODE/ode" -m "$STOCHKIT_HOME/models/examples/dimer_decay.xml" -t 1 -i 1 --out-dir "$rundir" >& /dev/null; then
echo "Success!"
else
echo "<font color=red>"
echo "Failed<br />"
echo "StochKit ODE failed to install. Consult logs above for errors, and the StochKit documentation for help on building StochKit for your platform. Rename successful build folder to $STOCHKIT_ODE</font><br />"
exit -1
fi
fi
rm -r "$rundir" >& /dev/null
echo "Configuring the app to use $STOCHKIT_HOME for StochKit... <br />"
echo "Configuring the app to use $STOCHKIT_ODE for StochKit ODE... <br />"
echo "Configuring the app to use $STOCHOPTIM for Stochoptim... <br />"
ln -s "$STOCHKIT_ODE" ode >& /dev/null
ln -s "$STOCHKIT_HOME" StochKit >& /dev/null
ln -s "$STOCHOPTIM" stochoptim >& /dev/null
# Write STOCHKIT_HOME to the appropriate config file
echo "$STOCHKIT_HOME" > "$STOCHSS_HOME/conf/config"
echo -n "$STOCHKIT_ODE" >> "$STOCHSS_HOME/conf/config"
echo "Done!"
exec $MYPYTHON "$STOCHSS_HOME/launchapp.py" mac $0 $1