#!/bin/sh -

# this script will run clustalx on a temporary file containing the concatenated
# contents of files listed in a file of filenames


PROG=clustalx


if [ $# != 1 ]
then
    echo usage: $0 file_of_filenames
fi

(echo "#!/bin/sh -"; echo "kill $$") > $PROG.kill

chmod a+x $PROG.kill

file_of_filenames=$1
date=`date +"%y_%m_%d"`
hostname=`hostname`
temp_file_name=/tmp/artemis_temp.$$.$hostname.$date.clustalx_input.fasta

cat $file_of_filenames | xargs cat > $temp_file_name

# make sure that the identifiers are unique for clustalx
perl -pne 'if (/^>(\S+)/) {
  $name = $1;
  if (exists $h{$name}) {
    $i = $h{$name}++;
    s/^>(\S+)/>$name.$i/;
  } else {
    $h{$name} = 0;
  }
}' $temp_file_name > $temp_file_name.processed

clustalx -INFILE=$temp_file_name.processed

exit 0
