#!/bin/sh
# autopkgtest check: build and run with default test data
# This test tries to run `reprof` from `reprof` package. 
# Package `librg-reprof-bundle-perl` is tested with `autopkgtest-pkg-perl`
# explicitly.
# Author: Tatiana Malygina <merlettaia@gmail.com>

set -e

pkg=reprof

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf $ADTTMP" 0 INT QUIT ABRT PIPE TERM
fi

cd $ADTTMP

cp -a /usr/share/doc/${pkg}/examples/* .
find . -type f -name "*.gz" -exec gunzip \{\} \;
for lnk in `find . -type l -name "*.gz"` ; do
    ln -s `basename $(readlink $lnk) .gz` `echo $lnk | sed 's/\.gz$//'`
    rm $lnk
done

echo "Run reprof for prediction from BLAST PSSM matrix..."
# Following examples were taken from man page.
# Prediction from BLAST PSSM matrix for best results:
reprof -i example.Q -o example.Q.new.reprof
[ -z $(cmp -s example.Q.new.reprof example.Q.reprof) ]

echo "Run reprof for prediction from .fasta..."
# Prediction from FASTA file:
reprof -i example.fasta -o example.fasta.new.reprof
[ -z $(cmp -s example.fasta.new.reprof example.fasta.reprof) ]

echo "Run reprof with --mutations parameter..."
# Prediction from BLAST PSSM matrix file using the mutation mode:
reprof -i example.Q -o mutations_example.Q.new.reprof --mutations mutations.txt
[ -z $(cmp -s mutations_example.Q.new.reprof mutations_example.Q.reprof) ]
[ -z $(cmp -s mutations_example.Q.new.reprof_F172P mutations_example.Q.reprof_F172P) ]
[ -z $(cmp -s mutations_example.Q.new.reprof_M1Q mutations_example.Q.reprof_M1Q) ]
[ -z $(cmp -s mutations_example.Q.new.reprof_N34Y mutations_example.Q.reprof_N34Y) ]
[ -z $(cmp -s mutations_example.Q.new.reprof_ORI mutations_example.Q.reprof_ORI) ]

echo "Reprof works as expected"
