-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux.sh
496 lines (475 loc) · 11 KB
/
linux.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
#!/bin/bash
clear
# Prints the header.
echo -e "/** ***************************************************** **/"
echo -e "/** ** Finding the Most Representative Graph ** **/"
echo -e "/** ** Model for Neuronal Interactions ** **/"
echo -e "/** ** via Markov Chain Monte Carlo ** **/"
echo -e "/** **/"
echo -e "/** Author: Pedro Brandimarte Mendonca **/"
echo -e "/** **/"
echo -e "/** ***************************************************** **/"
echo -e "/** For info about the code check the 'README' file **/"
echo -e "/** ***************************************************** **/"
# Checks if data path directory exists and is readable.
check=path
echo -e "\nChecking data path.\n"
if [ -r ${check} ]
then
check=`ls path/ | wc -l`
# Checks if the directory contains 12 files.
if [ "${check}" != "12" ]
then
echo -n "Organizing the data... "
cd scripts
./rotula.sh
cd ../
echo -e "done\n"
fi
else
echo -n "Organizing the data... "
mkdir path
cd scripts
./rotula.sh
cd ../
echo -e "done\n"
fi
# Clears swap memory if necessary.
SWAPmem=`free -b | grep "Swap:" | awk '{print $3}'`
if [ "${SWAPmem}" != "0" ]
then
echo -e "Cleaning swap memory (only for super-user)..."
sudo swapoff -a
sudo swapon -a
echo -e "...done\n"
fi
# Computes the total memory available in bits.
FREEmem=`free -b | grep "Mem:" | awk '{print $4}'`
MCmem=`echo "(8 * ${FREEmem})" | bc`
echo -e "Available memory: ${MCmem} bits\n"
verif=0
echo -e "Choose the kind of computation:"
while [ ${verif} -eq 0 ]
do
echo -n "(type 0 for penalty analysis or 1 for best graph) "
read option
if [ "${option}" == "0" ]
then
# Compiles the program.
cd src
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -n "Do you want to clean old compilations? (y or n) "
read option
if [ "${option}" == "y" ]
then
verif=1
echo -e "\nCleaning old compilations:\n"
make clean
make graphPenalty
check=`echo $?`
if [ ${check} == 2 ]
then
exit -1
fi
echo -e "...done\n"
elif [ "${option}" == "n" ]
then
verif=1
echo -e "\nCompiling changes:\n"
make graphPenalty
check=`echo $?`
if [ ${check} == 2 ]
then
exit -1
fi
echo -e "...done\n"
else
echo -e "\nWrong option!\n"
fi
done
cd ../
# Choosing the mouse
verif=0
while [ ${verif} -eq 0 ]
do
echo -n "Choose the mouse you want to study (4, 5, 6, 9, 12, 13 or all): "
read opt
if [ "${opt}" == "4" ]
then
mouse="4"
stepsMax=`echo "3 * ${MCmem} / 756" | bc`
verif=1
elif [ "${opt}" == "5" ]
then
mouse="5"
stepsMax=`echo "3 * ${MCmem} / 520" | bc`
verif=1
elif [ "${opt}" == "6" ]
then
mouse="6"
stepsMax=`echo "3 * ${MCmem} / 756" | bc`
verif=1
elif [ "${opt}" == "9" ]
then
mouse="9"
stepsMax=`echo "3 * ${MCmem} / 1722" | bc`
verif=1
elif [ "${opt}" == "12" ]
then
mouse="12"
stepsMax=`echo "3 * ${MCmem} / 812" | bc`
verif=1
elif [ "${opt}" == "13" ]
then
mouse="13"
stepsMax=`echo "3 * ${MCmem} / 930" | bc`
verif=1
elif [ "${opt}" == "all" ]
then
mouse="all"
stepsMax=`echo "3 * ${MCmem} / 1722" | bc`
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Choosing the brain region
verif=0
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -e "Choose the brain region you want to study"
echo -e "1. Hippocampus (HP)"
echo -e "2. Primary Somatic Sensory Cortex (S1)"
echo -e "3. Primary Visual Cortex (V1)"
echo -e "4. Hippocampus Dentate Gyrus (HPDG)"
echo -e "5. Hippocampus Cornu Ammonis 1 (HPCA1)"
echo -e "6. all regions\n"
echo -n "Type the option (1, 2, 3, 4, 5 or 6): "
read opt
if [ "${opt}" == "1" ]
then
region="HP"
verif=1
elif [ "${opt}" == "2" ]
then
region="S1"
verif=1
elif [ "${opt}" == "3" ]
then
region="V1"
verif=1
elif [ "${opt}" == "4" ]
then
region="HPDG"
verif=1
elif [ "${opt}" == "5" ]
then
region="HPCA1"
verif=1
elif [ "${opt}" == "6" ]
then
region="0"
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Ask if the user wants an arbitrary number of MC steps.
verif=0
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -n "Do you want to choose a fixed number of MC steps? (y or n) "
read option
if [ "${option}" == "y" ]
then
while [ ${verif} -eq 0 ]
do
echo -e ""
echo -n "Type the number of MC steps (less than ${stepsMax}): "
read mcSteps
if [ ${mcSteps} -lt ${stepsMax} ]
then
MCmem=${mcSteps}
stepsMax=1
verif=1
else
echo -e "\nWrong option!"
fi
done
elif [ "${option}" == "n" ]
then
stepsMax=0
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Checks if output directory exists and is readable.
check=out/outPenalty
if [ -r ${check} ]
then
echo -e ""
echo -n "Removing old results "
if [ "${region}" == "0" ] && [ "${mouse}" == "all" ]
then
rm out/outPenalty/*
echo -e "...done\n"
elif [ "${region}" == "0" ]
then
rm out/outPenalty/*${mouse}*
echo -e "...done\n"
elif [ "${mouse}" == "all" ]
then
rm out/outPenalty/*${region}*
echo -e "...done\n"
else
rm out/outPenalty/*${mouse}${region}*
echo -e "...done\n"
fi
else
echo -e ""
echo -n "Creating directory for output results... "
mkdir out/outPenalty
echo -e "done\n"
fi
# Runs the program.
cd bin
echo -e "\nRunning the program...\n"
echo -n "Start of run: "
date
ini=$(date +%s%N) # initial time with nanoseconds accuracy
if [ "${region}" == "0" ] && [ "${mouse}" == "all" ]
then
for region in "HP" "S1" "V1" "HPDG" "HPCA1"
do
for mouse in "4" "5" "6" "9" "12" "13"
do
./graphPenalty ../path/ ../out/outPenalty/ ${MCmem} ${stepsMax} ${region} ${mouse}
done
done
elif [ "${region}" == "0" ]
then
for region in "HP" "S1" "V1" "HPDG" "HPCA1"
do
./graphPenalty ../path/ ../out/outPenalty/ ${MCmem} ${stepsMax} ${region} ${mouse}
done
elif [ "${mouse}" == "all" ]
then
for mouse in "4" "5" "6" "9" "12" "13"
do
./graphPenalty ../path/ ../out/outPenalty/ ${MCmem} ${stepsMax} ${region} ${mouse}
done
else
./graphPenalty ../path/ ../out/outPenalty/ ${MCmem} ${stepsMax} ${region} ${mouse}
fi
fim=$(date +%s%N) # final time with nanoseconds accuracy
echo -e ""
echo -n "End of run: "
date
tempo=`echo "scale = 10; (${fim} - ${ini}) / 60000000000" | bc`
echo -e "\nRun time: ${tempo} min\n"
cd ../
elif [ "${option}" == "1" ]
then
# Compiles the program.
cd src
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -n "Do you want to clean old compilations? (y or n) "
read option
if [ "${option}" == "y" ]
then
verif=1
echo -e "\nCleaning old compilations:\n"
make clean
make bestGraph
check=`echo $?`
if [ ${check} == 2 ]
then
exit -1
fi
echo -e "...done\n"
elif [ "${option}" == "n" ]
then
verif=1
echo -e "\nCompiling changes:\n"
make bestGraph
check=`echo $?`
if [ ${check} == 2 ]
then
exit -1
fi
echo -e "...done\n"
else
echo -e "\nWrong option!\n"
fi
done
cd ../
# Choosing the mouse
verif=0
while [ ${verif} -eq 0 ]
do
echo -n "Choose the mouse you want to study (4, 5, 6, 9, 12 or 13): "
read opt
if [ "${opt}" == "4" ]
then
mouse="4"
stepsMax=`echo "3 * ${MCmem} / 756" | bc`
verif=1
elif [ "${opt}" == "5" ]
then
mouse="5"
stepsMax=`echo "3 * ${MCmem} / 520" | bc`
verif=1
elif [ "${opt}" == "6" ]
then
mouse="6"
stepsMax=`echo "3 * ${MCmem} / 756" | bc`
verif=1
elif [ "${opt}" == "9" ]
then
mouse="9"
stepsMax=`echo "3 * ${MCmem} / 1722" | bc`
verif=1
elif [ "${opt}" == "12" ]
then
mouse="12"
stepsMax=`echo "3 * ${MCmem} / 812" | bc`
verif=1
elif [ "${opt}" == "13" ]
then
mouse="13"
stepsMax=`echo "3 * ${MCmem} / 930" | bc`
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Choosing the brain region
verif=0
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -e "Choose the brain region you want to study"
echo -e "1. Hippocampus (HP)"
echo -e "2. Primary Somatic Sensory Cortex (S1)"
echo -e "3. Primary Visual Cortex (V1)"
echo -e "4. Hippocampus Dentate Gyrus (HPDG)"
echo -e "5. Hippocampus Cornu Ammonis 1 (HPCA1)\n"
echo -n "Type the option (1, 2, 3, 4 or 5): "
read opt
if [ "${opt}" == "1" ]
then
region="HP"
verif=1
elif [ "${opt}" == "2" ]
then
region="S1"
verif=1
elif [ "${opt}" == "3" ]
then
region="V1"
verif=1
elif [ "${opt}" == "4" ]
then
region="HPDG"
verif=1
elif [ "${opt}" == "5" ]
then
region="HPCA1"
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Ask if the user wants an arbitrary number of MC steps.
verif=0
echo -e ""
while [ ${verif} -eq 0 ]
do
echo -n "Do you want to choose a fixed number of MC steps? (y or n) "
read option
if [ "${option}" == "y" ]
then
while [ ${verif} -eq 0 ]
do
echo -e ""
echo -n "Type the number of MC steps (less than ${stepsMax}): "
read mcSteps
if [ ${mcSteps} -lt ${stepsMax} ]
then
MCmem=${mcSteps}
stepsMax=1
verif=1
else
echo -e "\nWrong option!"
fi
done
elif [ "${option}" == "n" ]
then
stepsMax=0
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Checks if output directory exists and is readable.
check=out/outBestGraph
if [ -r ${check} ]
then
echo -e ""
echo -n "Removing old results "
rm out/outBestGraph/*${mouse}${region}*
echo -e "...done\n"
else
echo -e ""
echo -n "Creating directory for output results... "
mkdir out/outBestGraph
echo -e "done\n"
fi
# Choosing the method for probability computation
verif=0
while [ ${verif} -eq 0 ]
do
echo -n "Choose the method for probability computation (1, 2 or 3): "
read method
if [ "${method}" == "1" ]
then
verif=1
elif [ "${method}" == "2" ]
then
verif=1
elif [ "${method}" == "3" ]
then
verif=1
else
echo -e "\nWrong option!\n"
fi
done
# Choosing the penalty constant
echo -e ""
echo -n "Type the positive penalty constant: "
read penal
# Runs the program.
cd bin
echo -e "\nRunning the program...\n"
echo -n "Start of run: "
date
ini=$(date +%s%N) # initial time with nanoseconds accuracy
./bestGraph ../path/ ../out/outBestGraph/ ${MCmem} ${stepsMax} ${region} ${mouse} ${method} ${penal}
fim=$(date +%s%N) # final time with nanoseconds accuracy
echo -e "\n"
echo -n "End of run: "
date
tempo=`echo "scale = 10; (${fim} - ${ini}) / 60000000000" | bc`
echo -e "\nRun time: ${tempo} min\n"
cd ../
else
echo -e "\nWrong option!\n"
fi
done