#!/bin/bash

echo $@

SAM=$1
shift
REF=$1
shift
OUTVCF=$1

TMPBAM=$$.tmpbam
TMPBAM2=$$.tmpbam2

samtools view -bS $SAM > $TMPBAM
samtools sort $TMPBAM $TMPBAM2

CMD="samtools mpileup -t DP,DV,DP4,DPR,SP -Auf $REF $TMPBAM2.bam | bcftools call -m -f GQ > $OUTVCF"

echo "CMD: "$CMD
eval $CMD
rm $TMPBAM
rm $TMPBAM2.bam
