forked from StochSS/stochss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.generic.sh
More file actions
executable file
·274 lines (228 loc) · 9.46 KB
/
run.generic.sh
File metadata and controls
executable file
·274 lines (228 loc) · 9.46 KB
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
#!/bin/bash
# Attempt to install StochKit 2.0.11
#
# Install it in the user's home folder by default, to override
#
#
#read -p "Select a directory to use as StochSS home (leave blank to use current directory): " MY_PATH
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
STOCHSS_HOME=$MY_PATH
STOCHSS_HOME="`( cd \"$STOCHSS_HOME\" && pwd )`"
echo "Installing in $STOCHSS_HOME"
if [ "$(echo $STOCHSS_HOME | grep " ")" != "" ]; then
echo "Cannot execute StochSS under any directory that contains spaces (which the filename listed above has). This is an known issue"
exit -1
fi
function check_pyurdme {
RET=`python -c "import pyurdme" 2>/dev/null`
RC=$?
if [[ $RC == 0 ]];then
return 0 #True
fi
return 1 #False
}
function check_spatial_installation {
if check_pyurdme; then
echo "PyURDME detected successfully"
else
echo "PyURDME not installed, Failing (check if all required python modules are installed)."
return 1 #False
fi
return 0 #True
}
#####################
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
}
if check_spatial_installation;then
echo "Spatial libraries installed correctly"
else
echo "Error checking the spatial libraries"
exit 1
fi
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"
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"
echo "$STOCHKIT_VERSION found in $STOCHKIT_HOME"
else
echo "No"
echo "Installing in $STOCHSS_HOME/$STOCHKIT_VERSION"
echo "Cleaning up anything already there..."
rm -rf "$STOCHKIT_PREFIX/$STOCHKIT_VERSION"
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"
echo " Logging stdout in $STOCHSS_HOME/stdout.log and "
echo " stderr in $STOCHSS_HOME/stderr.log "
echo " * This process will take at least 5 minutes to complete. Please be patient *"
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"
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 "$tmpdir" >& /dev/null
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!"
else
echo "Failed"
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"
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"
echo "$STOCHOPTIM_VERSION found in $STOCHOPTIM"
else
echo "No"
echo "Installing in $STOCHSS_HOME/$STOCHOPTIM_VERSION"
echo "Cleaning up anything already there..."
rm -rf "$STOCHOPTIM" >& /dev/null
echo "Building StochOptim"
echo " Logging stdout in $STOCHSS_HOME/stdout.log and "
echo " stderr in $STOCHSS_HOME/stderr.log "
echo " * This process will take at least 5 minutes to complete. Please be patient *"
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 StochOptim was installed successfully by running it on a sample model
if check_if_StochOptim_Installed; then
echo "Success!"
else
echo "Failed"
echo "$STOCHOPTIM failed to install. Consult logs above for errors"
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"
echo "ode found in $STOCHKIT_ODE"
else
echo "No"
echo "Installing in $STOCHSS_HOME/$ODE_VERSION"
echo "Cleaning up anything already there..."
rm -rf "$STOCHSS_HOME/ode" >& /dev/null
stdout="$STOCHSS_HOME/stdout.log"
stderr="$STOCHSS_HOME/stderr.log"
echo "Building StochKit ODE"
echo " Logging stdout in $STOCHSS_HOME/stdout.log and "
echo " stderr in $STOCHSS_HOME/stderr.log "
echo " * This process should take about a minute to complete. Please be patient *"
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 "Failed"
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"
exit -1
fi
make 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "Failed"
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"
exit -1
fi
make install 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "Failed"
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"
exit -1
fi
cd ../../
STOCHKIT_ODE_R=$STOCHKIT_ODE
export STOCHKIT_ODE="$(pwd -P)"
make 1>"$stdout" 2>"$stderr"
if [ $? != 0 ]; then
echo "Failed"
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"
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 "Failed"
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"
exit -1
fi
fi
rm -r "$rundir" >& /dev/null
echo "Configuring the app to use $STOCHKIT_HOME for StochKit... "
echo "Configuring the app to use $STOCHKIT_ODE for StochKit ODE... "
echo "Configuring the app to use $STOCHOPTIM for Stochoptim... "
ln -s "$STOCHOPTIM" stochoptim >& /dev/null
ln -s "$STOCHKIT_ODE" ode >& /dev/null
ln -s "$STOCHKIT_HOME" StochKit >& /dev/null
# Write STOCHKIT_HOME to the appropriate config file
echo "$STOCHKIT_HOME" > "$STOCHSS_HOME/conf/config"
echo "$STOCHKIT_ODE" >> "$STOCHSS_HOME/conf/config"
echo -n "$STOCHOPTIM" >> "$STOCHSS_HOME/conf/config"
echo "Done!"
exec python "$STOCHSS_HOME/launchapp.py" $0