#!/bin/bash
set -e

pkg=pizzly
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}/test/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

echo "Check functionality"
echo "Indexing"
kallisto index -i transcripts.kidx -k 31 transcripts.fasta.gz
[ -s transcripts.kidx ] || exit 1
echo "PASS"

echo "Quantifying using kallisto with fusion detection enabled"
kallisto quant -i transcripts.kidx --fusion -o output reads_1.fastq.gz reads_2.fastq.gz
[ -s output/fusion.txt ] || exit 1
tail -5 output/fusion.txt
echo "PASS"

echo "Run pizzly"
pizzly -k 31 --gtf transcripts.gtf.gz --cache index.cache.txt --align-score 2 \
        --insert-size 400 --fasta transcripts.fasta.gz --output test output/fusion.txt
for f in test.*
do
	[ -s $f ] || exit 1
done
tail -5 test.json
tail -1 test.fusions.fasta
echo "PASS"

