#!/bin/bash
set -e

pkg=maqview

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  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 *
ls -R
cd data
echo -e "\e[93m\e[1mPREP INPUT FILES FOR MAQVIEW\e[0m"
maq fasta2bfa test.fa test.bfa
echo 1
maq fastq2bfq test.fastq part1.bfq
echo 2
maq fastq2bfq test.fastq part2.bfq
echo 3
maq map part1.map test.fa part1.bfq
echo 4
maq map part2.map test.fa  part2.bfq
echo 5
maq mapmerge aln.map part1.map part2.map
echo 6
maq assemble cns.cns test.fa aln.map
echo 7
gzip test.fa
echo -e "\e[92m\e[1mDone\e[0m"
echo

#do_stuff_to_test_package#
echo -e "\e[93m\e[1mTest 1\e[0m"
zrio make test.fa.gz
diff test.fa.gz.zr ../ref/test.fa.gz.zr
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
zrio use test.fa.gz 0 > zrio.use.out
diff zrio.use.out ../ref/zrio.use.out
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"
maqindex -i part1.map
diff part1.map.vm ../ref/maqindex1/part1.map.vm
diff part1.map.zr ../ref/maqindex1/part1.map.zr
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"
maqindex -c cns.cns -i part1.map
diff part1.map.vm ../ref/maqindex2/part1.map.vm
diff part1.map.zr ../ref/maqindex2/part1.map.zr
diff cns.cns.zr ../ref/maqindex2/cns.cns.zr
diff cns.cns.summary ../ref/maqindex2/cns.cns.summary
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5\e[0m"
maqindex -i -c cns.cns
diff cns.cns.zr ../ref/maqindex3/cns.cns.zr
diff cns.cns.summary ../ref/maqindex3/cns.cns.summary
echo -e "\e[92m\e[1mPassed\e[0m"
echo

