Mercurial > repos > siwaa > insilicow
comparison inSiliCow-run.sh @ 0:50112d3941d8 draft
"planemo upload for repository https://forgemia.inra.fr/insilicow/insilicow-tool commit a01dd8fc54d5015e703722d7acb8db4b54b4a468"
author | siwaa |
---|---|
date | Mon, 07 Apr 2025 15:18:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:50112d3941d8 |
---|---|
1 #!/bin/bash | |
2 | |
3 # Title: inSiliCow-run.sh | |
4 # Address: main/run | |
5 # Description: Launch simulations | |
6 # Authors: Olivier MARTIN ( https://orcid.org/0000-0001-7375-2850 ) | |
7 # Pierre Blavy | |
8 # Contact: olivier.martin-mosar@inrae.fr | |
9 # Date: 2025 | |
10 # Usage: inSiliCow-run.sh example_xx [out] | |
11 # example_xx is a folder in examples/ | |
12 # out is the output folder, default ./out | |
13 | |
14 clear | |
15 | |
16 #-------------------------------------- | |
17 #--- Colors for display in terminal --- | |
18 #-------------------------------------- | |
19 | |
20 # Set Bold High Intensity colors | |
21 R='\033[1;91m' # Red | |
22 B='\033[1;94m' # Blue | |
23 NC='\033[0m' # No Color | |
24 | |
25 #Set BIP sound | |
26 BIP='\007' | |
27 | |
28 # --- Opening message --- | |
29 echo -e ${B}"\n> Launching inSiliCow"${NC} | |
30 | |
31 # ----------------------- | |
32 # --- Input arguments --- | |
33 # ----------------------- | |
34 #$1 is an example folder that exists in examples | |
35 #$2 is the output folder, must exists, default "./out" | |
36 | |
37 if [ "$#" -le 0 ]; then | |
38 echo -e ${B}"\n>> Missing argument" | |
39 echo -e ">> Usage:"${NC}" inSilicow-run example_00 [out]" | |
40 echo -e ${B}"\n>> Aborted\n"${NC} | |
41 exit 1 | |
42 fi | |
43 | |
44 INPUT_DIR=$(realpath "examples/$1" ) | |
45 OUTPUT_DIR=$(realpath ${2:-"./out"}) | |
46 mkdir -p $OUTPUT_DIR | |
47 | |
48 | |
49 FARMER_LOG=$(realpath "examples/farmer-log.txt" ) | |
50 SCRIPTS_DIR=$(realpath ./) | |
51 SCILAB=$(ls -drt $HOME/* | grep scilab- | tail -1)"/bin/scilab-cli" | |
52 INSILICOW=$(realpath ./../insilicow-linux) | |
53 | |
54 CURRENT=`pwd` | |
55 | |
56 # -------------------------- | |
57 # --- Check things --------- | |
58 # -------------------------- | |
59 | |
60 #Input does'nt exists => return | |
61 if [ ! -d "$INPUT_DIR" ]; then | |
62 echo -e ${BIP}${R}"\n>> Input directory $INPUT_DIR does not exist\n"; | |
63 echo -e ">> Aborted\n"; | |
64 exit 1; | |
65 fi | |
66 | |
67 #Output does'nt exists => return | |
68 #if [ ! -d "$OUTPUT_DIR" ]; then | |
69 # echo -e ${BIP}${R}"\n>> Output directory $OUTPUT_DIR does not exist\n"; | |
70 # echo -e ">> Aborted\n"; | |
71 # exit 1; | |
72 #fi | |
73 | |
74 #inSiliCow binary does'nt exists => return | |
75 if [ ! -e "$INSILICOW" ]; then | |
76 echo -e ${BIP}${R}"\n>> inSiliCow binary $INSILICOW does not exist\n"; | |
77 echo -e ">> Aborted\n"; | |
78 exit 1; | |
79 fi | |
80 | |
81 # ----------------------- | |
82 # --- Output ------------ | |
83 # ----------------------- | |
84 | |
85 #Get current date to name output folder | |
86 d=`date "+%Y%m%d_%H%M%S_%N"` | |
87 OUT_JOB="$OUTPUT_DIR/job-$d" | |
88 ZIP_FILE=$(realpath "$OUTPUT_DIR/simulations-$d.zip" ) | |
89 | |
90 # ------------------------------ | |
91 # --- Print input and output --- | |
92 # ------------------------------ | |
93 | |
94 echo -e ${B}"\n>> Pathways:" | |
95 echo -e " Input:\t$INPUT_DIR"; | |
96 echo -e " Output:\t$OUT_JOB"; | |
97 echo -e " Scilab:\t$SCILAB"; | |
98 echo -e " inSiliCow:\t$INSILICOW\n"${NC}; | |
99 | |
100 | |
101 # --------------------------------- | |
102 # --- Make output folders --------- | |
103 # --------------------------------- | |
104 mkdir -p "$OUT_JOB/in"; | |
105 mkdir -p "$OUT_JOB/out"; | |
106 | |
107 # ------------------------------------- | |
108 # --- check if scilab is responding --- | |
109 # ------------------------------------- | |
110 | |
111 #check-scilab.sci xxx creates a file called "xxx/scilab_is_ok" | |
112 rm -f "$OUTPUT_DIR/scilab_is_ok" | |
113 | |
114 #"$SCILAB" -f "$SCRIPTS_DIR/check-scilab.sci" -nwni -quit -args "$OUTPUT_DIR"; | |
115 | |
116 #if [ ! -f "$OUTPUT_DIR/scilab_is_ok" ]; then | |
117 # echo -e ${BIP}${R}"\n>> Scilab is not responding\n"; | |
118 # echo -e ">> Aborted\n"; | |
119 # exit 0; | |
120 #fi | |
121 | |
122 rm "$OUTPUT_DIR/scilab_is_ok" | |
123 | |
124 # -------------------------- | |
125 # --- Run the jobs --------- | |
126 # -------------------------- | |
127 | |
128 # --- Track time --- | |
129 SECONDS=0; | |
130 | |
131 #Format elapsed time | |
132 FormatSeconds () { | |
133 seconds="$1" | |
134 date -ud @${seconds} +"$(( seconds/3600/24 ))d %Hh %Mm %Ss" \ | |
135 | sed -r 's/\b0([0-9])/\1/g; s/\b0(s|m|h|d)//g; s/ +/ /g; s/^ +//; s/ +$//; s/^$/0s/' | |
136 } | |
137 | |
138 #copy input to $OUT_JOB/in | |
139 cp -r "$INPUT_DIR/"* "$OUT_JOB/in/" | |
140 cp "$FARMER_LOG" "$OUT_JOB/in/" | |
141 | |
142 echo -e ${B}"\n>> Starting job $d\n"${NC} | |
143 | |
144 # -------------- | |
145 # --- explan --- | |
146 # -------------- | |
147 | |
148 #Create file explan-config.txt with right paths | |
149 cat > "$OUT_JOB/in/explan-config.txt" << EOF | |
150 explan{ | |
151 IN_CPU = 4 #number of parallel jobs | |
152 IN_EXPLAN = $OUT_JOB/in/explan.txt | |
153 OUT_FOLDER = $OUT_JOB/out/ | |
154 IN_FOLDER = $OUT_JOB/in/ | |
155 IN_EXE = $INSILICOW | |
156 SCRIPT_FOLDER = $SCRIPTS_DIR | |
157 OUT_FOLDER = $OUT_JOB/sim | |
158 IN_SCILAB = $SCILAB | |
159 } | |
160 EOF | |
161 | |
162 | |
163 # Execute R script to launch simulations | |
164 echo -e ${B}"\n>> Starting simulation\n"${NC} | |
165 Rscript "$SCRIPTS_DIR/explan2.R" "$OUT_JOB/in/explan-config.txt" | |
166 | |
167 | |
168 # ZIP | |
169 | |
170 #uncomment the block below to zip output | |
171 | |
172 #rm -f "$ZIP_FILE" | |
173 #echo -e ${B}"\n>> Compress simulation to $ZIP_FILE \n"${NC} | |
174 #cd "$OUT_JOB" && \ | |
175 #zip -rq9 "$ZIP_FILE" ./ -x out/sim_*/log_herd.txt && \ | |
176 #cd "$CURRENT" && \ | |
177 #rm -rf "$OUT_JOB" | |
178 | |
179 | |
180 # ----------------------------------- | |
181 # --- display final message --------- | |
182 # ----------------------------------- | |
183 | |
184 echo -e ${B}"\n>> Job "$d" done in $(FormatSeconds $SECONDS)${NC}\n" | |
185 |