#!/bin/bash
set -e

pkg="pinfish"

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 -a /usr/share/doc/${pkg}-examples/* $AUTOPKGTEST_TMP

cd $AUTOPKGTEST_TMP
gunzip -r *

echo "Test 1"
cluster_gff -a rs_clusters.tab -c 1 real_small.gff
[ -s rs_clusters.tab ] || exit 1
rm -f rs_clusters.tab
echo "PASS"

echo "Test 2"
collapse_partials small_test.gff
rm -f test_data/rs_clusters.tab
echo "PASS"

echo "Test 3"
polish_clusters -t 40 -c 50 -o test3 -a sirv_e0.tab sirv_e0_sorted.bam 1> /dev/null
[ -s test3 ] || exit 1
cat test3 | head -20
rm -f test3
echo "PASS"

echo "Test 4"
spliced_bam2gff -M -s sirv_e0_sorted.bam | head -20
spliced_bam2gff  -g sirv_errors_gmap.bam | head -20
echo "PASS"
