#!/bin/bash
set -e

pkg=snap-aligner

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

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

cd "${AUTOPKGTEST_TMP}"

gunzip -r *

echo -e "\e[93m\e[1mTest 1\e[0m"
snap-aligner index datatest.fa datatest
diff datatest/Genome ref/datatest/Genome
diff datatest/GenomeIndex ref/datatest/GenomeIndex
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
snap-aligner index datatest2.fa datatest2 -s 22
diff datatest2/Genome ref/datatest2/Genome
diff datatest2/GenomeIndex ref/datatest2/GenomeIndex
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"
snap-aligner single datatest datatest.fq -o output.sam
# Remove program version from output.sam to not being forced to adapt the reference for every new release
sed -i 's/\(^@PG.*single datatest.*VN:\)[0-9.]*/\1/' output.sam
diff output.sam ref/output.sam
echo -e "\e[92m\e[1mPassed\e[0m"
echo
