#!/bin/bash
##This script optimizes the santalucia98 dataset
##Allawi, Hatim T., and John SantaLucia. 
##"Thermodynamics and NMR of internal GT mismatches in DNA." 
##Biochemistry 36.34 (1997): 10581-10594.
set -e
if [ -z "$1" ]; then export DATA=../data; else export DATA=$1; fi
if [ -z $BIN ]; then export BIN=vargibbs; fi
if [ -z $VER ]; then export VER=./; fi
set -e
export WD=${VER}SL98-global
mkdir -p ${WD}
echo " ******* "
echo " ******* "
echo " ******* This script takes about 10 minutes to run"
echo " ******* "
echo " ******* If you wish to reproduce the files data/AOP-SL98.par and data/BOP-SL98.par"
echo " ******* Edit this script and set MRR=1000 and ASL=0.0001 and be prepared for 1 or 2 days of processing"
export MRR=10
export ASL=0.1
echo " ******* "
echo " ******* Starting Global Minimization Round 1"
$BIN  -calc=minglobal -cl=10 -data=${DATA}/D-SL98.dat -gn=1 \
-me=3000 -minmethod=gsl -mm=6 -mrr=${MRR} \
-o=${WD}/BOP-SL98 -zlog=0 -par=${DATA}/init_s98.par \
-parid=BOP-SL98 -randominitial=0.5 -randomizedataset=0 -rs=1234 \
-var=AT_AT:entropy,AT_CG:entropy,AT_GC:entropy,AT_TA:entropy,CG_AT:entropy,\
CG_CG:entropy,CG_GC:entropy,GC_AT:entropy,GC_CG:entropy,TA_AT:entropy,\
AT_AT:enthalpy,AT_CG:enthalpy,AT_GC:enthalpy,AT_TA:enthalpy,CG_AT:enthalpy,\
CG_CG:enthalpy,CG_GC:enthalpy,GC_AT:enthalpy,GC_CG:enthalpy,TA_AT:enthalpy,\
terminal_CG_enthalpy,terminal_CG_entropy,terminal_AT_enthalpy,terminal_AT_entropy,symmetry_correction_entropy

echo " ******* "
echo " ******* "
echo " ******* Starting Global Minimization Round 2"
echo " ******* "
echo " ******* "

$BIN  -asl=${ASL} -calc=minglobal -cl=10 -data=${DATA}/D-SL98.dat -gn=1 -ee=0.3 -me=3000 -minmethod=gsl -mm=6 \
-o=${WD}/AOP-SL98 -zlog=0 -par=${WD}/BOP-SL98.par.best -parid=AOP-SL98 \
-randomizedataset=1 -rs=1234 \
-var=AT_AT:entropy,AT_CG:entropy,AT_GC:entropy,AT_TA:entropy,CG_AT:entropy,\
CG_CG:entropy,CG_GC:entropy,GC_AT:entropy,GC_CG:entropy,TA_AT:entropy,\
AT_AT:enthalpy,AT_CG:enthalpy,AT_GC:enthalpy,AT_TA:enthalpy,CG_AT:enthalpy,\
CG_CG:enthalpy,CG_GC:enthalpy,GC_AT:enthalpy,GC_CG:enthalpy,TA_AT:enthalpy,\
terminal_CG_enthalpy,terminal_CG_entropy,terminal_AT_enthalpy,terminal_AT_entropy,symmetry_correction_entropy

echo " ******* "
echo " ******* "
echo " ******* Calculating predictions with new parameters "
echo " ******* "
echo " ******* "

$BIN  -o=${WD}/SL98-global-prediction -par=${WD}/AOP-SL98.par.best \
-calc=prediction -data=${DATA}/D-SL98.dat
