#!/bin/bash 
#The script is used to generate multiple models with the cmap2struct (contact map-to-structure) pipeline. 
#The input arguments are: 


#$1-<argument-file> - a file with arguments for cmap2struct function listed in a column, 
#$2-<run-num> - number of runs (each run generates 4 symetric models)
#$3-<first-dir-name> - name of the first directory (it must be an integer number!)

#FORMAT OF THE ARGUMENT FILE
#<name_10con12.cmap> - contact map
#<threshold>  - threshold for contacts
#<use_filter> - an ft-comar contacts filtering option
#<pdb_file> - original pdb_file
#<orient_pdb_full_path> - pdb_file for orienting models perpendicular to membrane
#<chainIDs_in_output> - the seqeunce of chain names in output files eg ABDC - important later when calculating RMSD to original
#<rmsd_threshold> - a threshold for CA_trace RMSD for repating ft-comar run
#<run_num> - run number
#<insert_loops_flag> - use loops between subunit chain (1/0) before ft-comar runs
#<loop length> - we sugest 20
#<insert_pt1> - where to insert first loop
#<insert_pt2> - where to put consecutive loops
#....

EXPECTED_ARGS=3
BAD_ARGS=55

if [ $# -lt ${EXPECTED_ARGS} ]
then
        echo "USAGE: c2s_generate_models <arg_file> <num_run> <first_dir_name>

<argument-file> - a file with arguments for cmap2struct function listed in a column,
<num_run> - number of runs (each run generates symetric models based on each chain plus an averaged model)
<first-dir-name> - name of the first directory (it must be an integer number!)

FORMAT OF THE ARGUMENT FILE
<name_10con12.cmap> - contact map
<threshold>  - threshold for contacts
<use_filter> - an ft-comar contacts filtering option
<pdb_file> - original pdb_file
<orient_pdb_full_path> - pdb_file for orienting models perpendicular to membrane
<chainIDs_in_output> - the seqeunce of chain names in output files eg ABDC - important later when calculating RMSD to original
<rmsd_threshold> - a threshold for CA_trace RMSD for repating ft-comar run
<run_num> - run number
<insert_loops_flag> - use loops between subunit chain (1/0) before ft-comar runs
<loop length> - we sugest 20
<insert_pt1> - where to insert first loop
<insert_pt2> - where to put consecutive loops 
....
"
        exit $BAD_ARGS
fi

arg_file=$1
num_run=$2
first_dir_name=$3
last_dir_name=$(( $num_run + $first_dir_name ))
i=0;
while read arg rest; do
	cmap2struct_args[$i]=$arg
	i=$(( $i + 1 ))
done < ${arg_file}

for (( i=$first_dir_name ; $i<last_dir_name ; i++ ));do
	cmap2struct_args[7]=$i
	cmap2struct ${cmap2struct_args[@]}
done



