#!/bin/bash
##This script optimizes the dataset from
##Owczarzy, Richard, et al. 
##"Effects of sodium ions on DNA duplex oligomers: improved predictions of melting temperatures." 
##Biochemistry 43.12 (2004): 3537-3554.
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}OW04-global
mkdir -p ${WD}
echo " ******* "
echo " ******* "
echo " ******* This script takes about 5 minutes to run"
echo " ******* "
echo " ******* If you wish to reproduce the files data/AOP-OW04.par and data/BOP-OW04.par"
echo " ******* Edit this script and set MRR=1000 and ASL=0.0001 and be prepared for several hours of processing"
export MRR=5
export ASL=0.1
for SALT in 69 119 220 621 1020
do
echo " ******* "
echo " ******* Starting Global Minimization Round 1 for salt concentration ${SALT}"
$BIN  -calc=minglobal -cl=10 -data=${DATA}/D-OW04-${SALT}.dat -gn=0 \
-me=3000 -minmethod=gsl -mm=6 -mrr=${MRR} \
-o=${WD}/BOP-OW04-${SALT} -par=${DATA}/init_s98.par \
-parid=BOP-OW04-${SALT} -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 no self-complementary sequences in dataset D-OW04DSC
echo " ******* "
echo " ******* "
echo " ******* Starting Global Minimization Round 2 for salt concentration ${SALT}"
echo " ******* "
echo " ******* "

$BIN  -asl=${ASL} -calc=minglobal -cl=10 -data=${DATA}/D-OW04-${SALT}.dat -gn=0 -ee=0.3 -me=3000 -minmethod=gsl -mm=6 \
-o=${WD}/AOP-OW04-${SALT} -par=${WD}/BOP-OW04-${SALT}.par.best -parid=AOP-OW04-${SALT} \
-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 no self-complementary sequences in dataset D-OW04DSC
echo " ******* "
echo " ******* "
echo " ******* Calculating predictions with new parameters "
echo " ******* "
echo " ******* "

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