diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inSiliCow-run.sh	Mon Apr 07 15:18:25 2025 +0000
@@ -0,0 +1,185 @@
+#!/bin/bash
+
+# Title:        inSiliCow-run.sh
+# Address:	main/run
+# Description:  Launch simulations
+# Authors:      Olivier MARTIN ( https://orcid.org/0000-0001-7375-2850 )
+#               Pierre Blavy
+# Contact:      olivier.martin-mosar@inrae.fr
+# Date:         2025
+# Usage: inSiliCow-run.sh example_xx  [out]
+#        example_xx is a folder in examples/
+#        out is the output folder, default ./out
+
+clear
+
+#--------------------------------------
+#--- Colors for display in terminal ---
+#--------------------------------------
+
+# Set Bold High Intensity colors 
+R='\033[1;91m'	# Red
+B='\033[1;94m'	# Blue
+NC='\033[0m' 	# No Color
+
+#Set BIP sound
+BIP='\007'
+
+# --- Opening message ---
+echo -e ${B}"\n> Launching inSiliCow"${NC}
+
+# -----------------------
+# --- Input arguments ---
+# -----------------------
+#$1 is an example folder that exists in examples
+#$2 is the output folder, must exists, default "./out"
+
+if [ "$#" -le 0 ]; then
+  echo -e ${B}"\n>> Missing argument"
+  echo -e ">> Usage:"${NC}" inSilicow-run example_00 [out]"
+  echo -e ${B}"\n>> Aborted\n"${NC}
+  exit 1
+fi
+
+INPUT_DIR=$(realpath "examples/$1"  ) 
+OUTPUT_DIR=$(realpath ${2:-"./out"})
+mkdir -p $OUTPUT_DIR
+
+
+FARMER_LOG=$(realpath "examples/farmer-log.txt"  ) 
+SCRIPTS_DIR=$(realpath ./)
+SCILAB=$(ls -drt $HOME/* | grep scilab- | tail -1)"/bin/scilab-cli"
+INSILICOW=$(realpath ./../insilicow-linux)
+
+CURRENT=`pwd`
+
+# --------------------------
+# --- Check things ---------
+# --------------------------
+
+#Input does'nt exists => return
+if [ ! -d "$INPUT_DIR" ]; then
+  echo -e ${BIP}${R}"\n>> Input directory $INPUT_DIR does not exist\n";
+  echo -e ">> Aborted\n";
+  exit 1;
+fi
+
+#Output does'nt exists => return
+#if [ ! -d "$OUTPUT_DIR" ]; then
+#  echo -e ${BIP}${R}"\n>> Output directory $OUTPUT_DIR does not exist\n";
+#  echo -e ">> Aborted\n";
+#  exit 1;
+#fi
+
+#inSiliCow binary does'nt exists => return
+if [ ! -e "$INSILICOW" ]; then
+  echo -e ${BIP}${R}"\n>> inSiliCow binary $INSILICOW does not exist\n";
+  echo -e ">> Aborted\n";
+  exit 1;
+fi
+
+# -----------------------
+# --- Output ------------
+# -----------------------
+
+#Get current date to name output folder 
+d=`date "+%Y%m%d_%H%M%S_%N"`
+OUT_JOB="$OUTPUT_DIR/job-$d"
+ZIP_FILE=$(realpath "$OUTPUT_DIR/simulations-$d.zip" ) 
+
+# ------------------------------
+# --- Print input and output ---
+# ------------------------------
+
+echo -e ${B}"\n>> Pathways:"
+echo -e "     Input:\t$INPUT_DIR";
+echo -e "    Output:\t$OUT_JOB";
+echo -e "    Scilab:\t$SCILAB";
+echo -e " inSiliCow:\t$INSILICOW\n"${NC};
+
+
+# ---------------------------------
+# --- Make output folders ---------
+# ---------------------------------
+mkdir -p "$OUT_JOB/in";
+mkdir -p "$OUT_JOB/out";
+
+# -------------------------------------
+# --- check if scilab is responding ---
+# -------------------------------------
+
+#check-scilab.sci xxx creates a file called "xxx/scilab_is_ok"
+rm -f "$OUTPUT_DIR/scilab_is_ok"
+
+#"$SCILAB" -f "$SCRIPTS_DIR/check-scilab.sci" -nwni -quit -args "$OUTPUT_DIR";
+
+#if [ ! -f "$OUTPUT_DIR/scilab_is_ok" ]; then
+#  echo -e ${BIP}${R}"\n>> Scilab is not responding\n";
+#  echo -e ">> Aborted\n";
+#  exit 0;
+#fi
+
+rm "$OUTPUT_DIR/scilab_is_ok"
+
+# --------------------------
+# --- Run the jobs ---------
+# --------------------------
+
+# --- Track time ---
+SECONDS=0;
+
+#Format elapsed time
+FormatSeconds () { 
+  seconds="$1"
+  date -ud @${seconds} +"$(( seconds/3600/24 ))d %Hh %Mm %Ss" \
+    | sed -r 's/\b0([0-9])/\1/g; s/\b0(s|m|h|d)//g; s/ +/ /g; s/^ +//; s/ +$//; s/^$/0s/'
+}
+
+#copy input to $OUT_JOB/in
+cp -r "$INPUT_DIR/"* "$OUT_JOB/in/"
+cp "$FARMER_LOG" "$OUT_JOB/in/"
+
+echo -e ${B}"\n>> Starting job $d\n"${NC}
+
+# --------------
+# --- explan ---
+# --------------
+
+#Create file explan-config.txt with right paths 
+cat > "$OUT_JOB/in/explan-config.txt" << EOF
+explan{
+	IN_CPU          = 4  #number of parallel jobs
+	IN_EXPLAN       = $OUT_JOB/in/explan.txt
+	OUT_FOLDER      = $OUT_JOB/out/
+	IN_FOLDER	= $OUT_JOB/in/
+	IN_EXE   	= $INSILICOW
+	SCRIPT_FOLDER	= $SCRIPTS_DIR
+	OUT_FOLDER	= $OUT_JOB/sim
+	IN_SCILAB       = $SCILAB
+}
+EOF
+
+
+# Execute R script to launch simulations  
+echo -e ${B}"\n>> Starting simulation\n"${NC}
+Rscript "$SCRIPTS_DIR/explan2.R" "$OUT_JOB/in/explan-config.txt"
+
+
+# ZIP
+
+#uncomment the block below to zip output 
+
+#rm -f "$ZIP_FILE"
+#echo -e ${B}"\n>> Compress simulation to $ZIP_FILE \n"${NC}
+#cd "$OUT_JOB" && \
+#zip -rq9 "$ZIP_FILE" ./  -x out/sim_*/log_herd.txt && \
+#cd "$CURRENT"  && \
+#rm -rf "$OUT_JOB" 
+
+
+# -----------------------------------
+# --- display final message ---------
+# -----------------------------------
+
+echo -e ${B}"\n>> Job "$d" done in $(FormatSeconds $SECONDS)${NC}\n"
+