#!/bin/bash
set -e

pkg=nanosv
examplepkg=samtools

export LC_ALL=C.UTF-8
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/${examplepkg}/examples/toy.sam "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"
mv -f toy.sam read.sam

cat read.sam| samtools view -Sb > reads.bam
samtools sort reads.bam > reads_sort.bam
samtools index reads_sort.bam reads_sort.bai
bedtools bamtobed -i  reads_sort.bam > target.bed

#Output generated is not consistent and cannot be compared with a reference. 
NanoSV reads_sort.bam -b target.bed -s sambamba -o output.vcf
[ -s "output.vcf" ] || exit 1
echo "PASS Test"
