#!/bin/bash
set -e

pkg=poretools

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 /usr/share/${pkg}/data -a "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"
gunzip -r *

mv data test_data
echo 'Test 1'
echo 'poretools fastq --min-length 5000 test_data/'
poretools fastq --min-length 5000 test_data/
echo 'PASS'
echo

echo 'Test 2'
echo 'poretools yield_plot \
          --plot-type basepairs \
          --saveas foo.pdf \
          test_data/'

poretools yield_plot \
          --plot-type basepairs \
          --saveas foo.pdf \
          test_data/

echo 'poretools yield_plot \
          --plot-type basepairs \
          --saveas foo.png \
	  --theme-bw \'

poretools yield_plot \
          --plot-type basepairs \
          --saveas foo.png \
	  --theme-bw \
          test_data/
echo 'PASS'
echo

echo 'Test 3'
echo 'poretools winner test_data/'
poretools winner test_data/

echo 'poretools winner --type all test_data/'
poretools winner --type all test_data/

echo 'poretools winner --type 2D test_data/'
poretools winner --type 2D test_data/

echo 'poretools winner --type fwd,rev test_data/'
poretools winner --type fwd,rev test_data/

echo 'poretools winner --type best test_data/'
poretools winner --type best test_data/
echo 'PASS'
echo

echo 'Test 4'
echo 'poretools stats test_data/'
poretools stats test_data/
echo 'PASS'
echo

echo 'Test 5'
echo 'poretools hist --num-bins 20 --max-length 10000 test_data/ --saveas pdf'
poretools hist --num-bins 20 --max-length 10000 test_data/ --saveas pdf
echo 'PASS'
echo

echo 'Test 6'
echo 'poretools nucdist test_data/'
poretools nucdist test_data/
echo 'PASS'
echo

echo 'Test 7'
echo 'poretools qualdist test_data/'
poretools qualdist test_data/
echo 'PASS'
echo

echo 'Test 8'
echo 'poretools qualpos test_data/'
poretools qualpos test_data/
echo 'PASS'
echo

echo 'Test 9'
echo 'poretools tabular  test_data/2016_3_4_3507_1_ch120_read418_strand.fast5'
poretools tabular  test_data/2016_3_4_3507_1_ch120_read418_strand.fast5 
echo 'PASS'
echo

echo 'Test 10'
echo 'poretools events test_data/ | head -5'
poretools events test_data/ | head -5
echo 'PASS'
echo

echo 'Test 11'
echo 'poretools events --pre-basecalled test_data/ | head -5'
poretools events --pre-basecalled test_data/ | head -5
echo 'PASS'
echo

echo 'Test 12'
echo 'poretools times test_data/'
poretools times test_data/
echo 'PASS'
echo

echo 'Test 13'
echo 'poretools index test_data | head -5'
poretools index test_data | head -5
echo 'PASS'
echo
