#!/bin/bash
set -e

pkg=biobambam2

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}"

echo -e "\e[93m\e[1mTest 1\e[0m"
case "$(dpkg --print-architecture)" in
i386)
	echo -e "\e[91m\e[1mSkipped on i386 due to memory requirements\e[0m"
	;;
*)
	bamsormadup < SRR11728627.bam > SRR11728627.sorted.bam
	echo -e "\e[92m\e[1mPassed\e[0m"
	;;
esac
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
bamcollate2 index=1 collate=3 indexfilename=SRR11728627.idx < SRR11728627.bam  > SRR11728627.collated.bam
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"
bammarkduplicates2 I=SRR11728641.bam O=SRR11728641.uniq.bam D=SRR11728641.dups.bam rmdup=1
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"
bammarkduplicates2 I=SRR11728641.bam O=SRR11728641.dupmarked.bam md5=1 md5filename=SRR11728641.dupmarked.bam.md5
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5\e[0m"
bammaskflags maskneg=16 < SRR11728627.bam > SRR11728627.masked.bam
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 6\e[0m"
bamrecompress level=9 < SRR11728627.bam > SRR11728627.lvl9.bam
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 7\e[0m"
bamsort SO=coordinate < SRR11728641.bam > SRR11728641.sorted.bam
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 8\e[0m"
bamtofastq collate=1 < SRR11728627.bam > SRR11728627.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

