#!/bin/bash

# Attention:
# Hamid Nassiby found if build with -Ox for x>0 a crash
# occurs and Valgrind can only lead to the same place in this scenario.
# That is here:
#  https://github.com/cbcrg/tcoffee/blob/master/lib/util_lib/util.c#L6151
#  name_array[a][0]='\0';
# If the program is compiled with -O(1-3), when we reach to this line,
# the name_array[a][0] is not allocated (or it may has been freed earlier),
# so the assignment leads to a crash!
# That's why -O0 is forced in d/rules.

set -e

pkg='t-coffee'

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
fi

cp -a /usr/share/doc/${pkg}/examples/* $AUTOPKGTEST_TMP

cd $AUTOPKGTEST_TMP
find . -name "*.gz" -exec gunzip \{\} \;

# Make sure HOME is set in environment (see bug #909530)
export HOME="$PWD"

t_coffee sample_rnaseq1.fasta
t_coffee sample_rnaseq1.fasta -mode quickaln
t_coffee sample_rnaseq1.fasta -mode quickaln -ndiag=10
t_coffee proteases_small.fasta -aln g0.aln g5.aln g10.aln g15.aln -output=clustalw,html
t_coffee -infile=sample_aln1.aln -lib=sample_aln1.tc_lib -special_mode=evaluate
t_coffee -other_pg seq_reformat -in proteases_small.aln -output fasta_aln > proteases_small.fasta_aln
t_coffee -other_pg seq_reformat -in proteases_small.aln -output msf > proteases_small.msf
t_coffee -other_pg seq_reformat -in proteases_small.aln -output fasta_seq > proteases_small.fasta
t_coffee -other_pg seq_reformat -in proteases_small.aln -action +lower -output clustalw
t_coffee -other_pg seq_reformat -in sample_aln1.aln -action +upper +edit_residue hmgb_chite 10 lower
t_coffee -other_pg seq_reformat -in sample_aln1.aln -in3 sample_aln1.aln -action +upper +3evaluate idmat +lower ''
t_coffee -other_pg seq_reformat -in proteases_large.fasta -output code_name > proteases_large.code_name
t_coffee -other_pg seq_reformat -code proteases_large.code_name -in proteases_large.fasta >proteases_large.coded.fasta
t_coffee -other_pg seq_reformat -decode proteases_large.code_name -in proteases_large.coded.fasta
t_coffee -other_pg seq_reformat -in sample_aln1.aln -in3 sample_aln1.aln -action  +3convert a0 -output color_html > colored.html
t_coffee -other_pg seq_reformat -in sample_aln1.aln -action +color_residue hmgb_chite 10 1 -output color_html > color.html
t_coffee -other_pg seq_reformat -in sample_aln1.aln -in3 sample_aln1.aln -action +3evaluate pam250mt -output color_html > color.html
t_coffee -other_pg seq_reformat -in sample_aln1.aln -in3 sample_aln1.aln -action +3evaluate boxshade -output color_html > color.html
t_coffee -other_pg seq_reformat -in=sample_dnaseq2.aln -output=clustalw_aln -out=cache.aln -action +convert 'Aa1' '.--' +convert '#0'
t_coffee -other_pg seq_reformat -in=sample_dnaseq2.aln -output=fasta_seq -out=cache.seq -action +convert 'Aa1' '.--' +convert '#0'
t_coffee -other_pg seq_reformat -in=sample_dnaseq2.aln -output=fasta_seq -out=cache -action +convert 'Aa1' '.--'
t_coffee -other_pg seq_reformat -in=sample_dnaseq2.aln -struc_in=sample_dnaseq2.cache -struc_in_f number_fasta -output=color_html -out=x.html
