#!/bin/bash

echo "Running mscore to get scores of alignments ..."

# verbose flag - set this flag to have verbose output (cannot be plotted!)
#verbflag=-v

# root dir for data + programs
rootdir=/home/goetz/multal

# dir where the reference alignments are stored
refdir=$rootdir/alcompar/BAliBASE

# location of mscore program
mscore=$rootdir/mscore/mscore

# dir containing all data
datadir=`pwd`

# scorefilename
scores=scores

for prgname in clustalx msa dialign2 TCOFFEE hmmer; do
    # first all dirs with secondary structure info
    for dirname in ref1/test1 ref1/test2 ref1/test3 ref2/test ref3/test ref4/test ref5/test; do
	cd $datadir/$prgname/$dirname
	pwd

	rm -f $scores

	for file in *.msf; do
	    echo "File: $file";
	    echo "$file" >> $scores;
	    
	    # set some local variables for convenience:
	    reffile=$refdir/$dirname/$file;
	    ftbfile=$refdir/$dirname/`basename $file .msf`.ftb;
	    groupfile=$refdir/$dirname/`basename $file .msf`.html;

	    # now do different scoring types
	    
	    # distance score
	    echo -n "dis: " >> $scores;
	    $mscore $verbflag -d -r $reffile $file >> $scores;
	    # distance score with simple secstructure weighting
	    echo -n "sdis: " >> $scores;
	    $mscore $verbflag -d -f $ftbfile -r $reffile -s 2 -t 2 $file >> $scores;
	    # distance score with secstructure weighting and group cutting
	    echo -n "csdis: " >> $scores;
	    $mscore $verbflag -d -f $ftbfile -r $reffile -s 2 -t 2 -G $groupfile $file >> $scores;

	    # pam250, gap=5 score
	    echo -n "pam: " >> $scores;
	    $mscore $verbflag -m pam250 $file >> $scores;
	    # pam250, gap=5 score with simple secstructure weighting
	    echo -n "spam: " >> $scores;
	    $mscore $verbflag -m pam250 -f $ftbfile -r $reffile -s 2 -t 2 $file >> $scores;

	    # pam250, gap=5 score with secstructure weighting and group cutting
	    echo -n "cspam: " >> $scores;
	    $mscore $verbflag -m pam250 -f $ftbfile -r $reffile -s 2 -t 2 -G $groupfile $file >> $scores;

	    # blosum62, gap=5 score
	    echo -n "blosum: " >> $scores;
	    $mscore $verbflag -m blosum62 $file >> $scores;
	    # blosum62, gap=5 score with simple secstructure weighting
	    echo -n "sblosum: " >> $scores;
	    $mscore $verbflag -m blosum62 -f $ftbfile -r $reffile -s 2 -t 2 $file >> $scores;

	    # blosum62, gap=5 score with progressive weighting and grp cutting
	    echo -n "csblosum: " >> $scores;
	    $mscore $verbflag -m blosum62 -f $ftbfile -r $reffile -s 2 -t 2 -G $groupfile $file >> $scores;
	    
	    # done $file
	done;
    # done $dirname
    done;

    # now all other dirs
    for dirname in ref6/test ref6/test_1a ref6/test_1b ref6/test_2a ref6/test_2b ref6/test_2c ref6/test_3 ref6/test_4 ref7/test ref8/test; do
	cd $datadir/$prgname/$dirname
	pwd

	rm -f $scores

	for file in *.msf; do
	    echo "File: $file";
	    echo "$file" >> $scores;
	    
	    # set some local variables for convenience:
	    reffile=$refdir/$dirname/$file;

	    # now do different scoring types
	    
	    # distance score
	    echo -n "dis: " >> $scores;
	    $mscore $verbflag -d -r $reffile $file >> $scores;
	    
	    # pam250, gap=5 score
	    echo -n "pam: " >> $scores;
	    $mscore $verbflag -m pam250 $file >> $scores;

	    # blosum62, gap=5 score
	    echo -n "blosum: " >> $scores;
	    $mscore $verbflag -m blosum62 $file >> $scores;
	    
	    # done $file
	done;
    # done $dirname
    done;

#done $prgname
done;

echo "done."
