#!/bin/bash
set -e

pkg=bbmap

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

if ! dpkg-query -s python-biopython-doc | grep -q '^Status: install' >/dev/null
then
	cat <<-END
	Notice: Please install the python-biopython-doc package to get the
	        dataset in use by the present test suite.
	END
fi

cp -a /usr/share/doc/python-biopython-doc/Tests/Quality/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

set -v

#	bbmap
	bbmap.sh --version
	bbmap.sh --help
	bbmap.sh ref=example.fasta
	test -d ref
	bbmap.sh in=misc_dna_as_sanger.fastq out=out.sam
	test -r out.sam
	bbmap.sh ref=example.fasta in=example.fastq out=out2.sam nodisk
	test -r out2.sam

#	bbduk
	bbduk.sh --version
	bbduk.sh --help
	bbduk.sh in1=misc_dna_as_illumina.fastq in2=misc_rna_as_illumina.fastq \
		qtrim=rl trimq=15 minlen=75 out=out.fastq.gz
	test -r out.fastq.gz

#	bbnorm
	bbnorm.sh --version
	bbnorm.sh --help
	bbnorm.sh in=sanger_full_range_original_sanger.fastq qin=33 \
		out=out3.fastq outt=outt.fastq hist=hist.plt
	test -r out3.fastq
	test -r outt.fastq
	test -r hist.plt
	bbnorm.sh in=illumina_full_range_original_illumina.fastq qin=64 \
		out=out4.fastq outt=outt2.fastq hist=hist2.plt
	test -r out4.fastq
	test -r outt2.fastq
	test -r hist2.plt
