#!/bin/bash
set -e

pkg="scrappie"
CUR_DIR=`pwd`

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 ${CUR_DIR}/reads $AUTOPKGTEST_TMP
cp -a ${CUR_DIR}/misc $AUTOPKGTEST_TMP

cd $AUTOPKGTEST_TMP
gunzip -r *

echo "Test functionality"

echo "Test 1"
scrappie raw -f sam reads --min_prob=0.1 --format=FASTA --output=test1.fa
[ -s test1.fa ]
head -n 1 test1.fa
echo "PASS"

echo "Test 2"
scrappie events reads > test2.fa
head -n 1 test2.fa
[ -s test2.fa ]
echo "PASS"

echo "Test 3"
scrappie raw reads | tee test2.fa | grep '^>' | cut -d ' ' -f 2- | python3 misc/json_to_tsv.py > test3.tsv
[ -s test3.tsv ]
cat test3.tsv
echo "PASS"

