#!/bin/bash
set -e

pkg=pbdagcon

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

cd "${AUTOPKGTEST_TMP}"

echo -e "\e[93m\e[1mTest 1\e[0m"
rangen 0.005 -r2020 > target.fasta
fasta2DAM target target.fasta
dsimulator target -c20. -r2020 > queries.fasta
blasr queries.fasta target.fasta -m 5 --out mapped.m5
pbdagcon mapped.m5 > consensus.fasta

echo "6977ed74eab5a8b58c3a90e10f1cb96c  consensus.fasta" >> checksums
echo "327a35213054ec8702ea35b85f3b3c44  mapped.m5" >> checksums
echo "11015d691ec4d33c7ec4d8125349b739  queries.fasta" >> checksums
echo "160c2f8c3aeb52c98403c2c1c677c13e  target.dam" >> checksums
echo "63690c9bbfd08ef3ff51d040d619056a  target.fasta" >> checksums

md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"


echo -e "\e[93m\e[1mTest 2\e[0m"
rangen 0.01 -r2020 >R.fasta           
fasta2DAM R R.fasta           
dsimulator R -c20. -r2020 >G.fasta   
fasta2DB G G.fasta            
DBsplit -s0.1 G                
DBdust G.1                    
DBdust G.2             
HPC.daligner -mdust -t5 G | sh -v
dazcon -ox -j 4 -s G.db -a G.1.las > corrected.fasta

echo -e "\e[92m\e[1mPassed\e[0m"