# First field:
#   INIT = initialisation, not counted in testing
#   P = expected to pass
#   F = expected to fail

# Second field:
#   Filename of expected output

# Third onwards; command to execute. $fmt is replaced by the current file
# format, ie sam, bam or cram. $samtools is a pointer to the desired
# samtools binary. This can be useful for testing older versions.

# Create indexed BAMs
INIT x $samtools view -b -o xx#depth1.bam xx#depth1.sam
INIT x $samtools view -b -o xx#depth2.bam xx#depth2.sam
INIT x $samtools view -b -o xx#depth3.bam xx#depth3.sam
INIT x $samtools index xx#depth1.bam
INIT x $samtools index xx#depth2.bam
INIT x $samtools index xx#depth3.bam

# Test basic 1 and 2 file outputs
P d1_1.out  $samtools depth xx#depth1.sam
P d1_2.out  $samtools depth xx#depth2.sam
P d1_12.out $samtools depth xx#depth1.sam xx#depth2.sam

# Regions via -r or bed
P d1_12.out  $samtools depth -r xx:5-16 xx#depth1.bam xx#depth2.bam
P d1_12.out  $samtools depth -b xx.bed  xx#depth1.sam xx#depth2.sam
P d2_12r.out $samtools depth -r xx:8-13 xx#depth1.bam xx#depth2.bam
P d2_12r.out $samtools depth -b xx.bed2 xx#depth1.sam xx#depth2.sam

# With single -a for all (in used refs)
P d3_12r1a.out $samtools depth -a -r xx:5-16 xx#depth1.bam xx#depth2.bam
P d3_12r1a.out $samtools depth -a -b xx.bed  xx#depth1.bam xx#depth2.bam
P d3_12r2a.out $samtools depth -a -r xx:8-13 xx#depth1.bam xx#depth2.bam
P d3_12r2a.out $samtools depth -a -b xx.bed2 xx#depth1.bam xx#depth2.bam
P d3_3.out     $samtools depth -a xx#depth3.bam

# With double -a for all including unused refs
P d4_12.out  $samtools depth -a -a            xx#depth1.bam xx#depth2.bam
P d4_12r.out $samtools depth -a -a -r xx:5-16 xx#depth1.bam xx#depth2.bam
P d4_12b.out $samtools depth -a -a -b xx.bed  xx#depth1.bam xx#depth2.bam

# Various boundary cases (see samtools#579 and #374)
P d5_all1.out  $samtools depth               xx#depth3.bam
P d5_all2.out  $samtools depth -a            xx#depth3.bam
P d5_all3.out  $samtools depth -aa           xx#depth3.bam
P d5_blank.out $samtools depth     -r xy:5-6 xx#depth3.bam
P d5_xy1.out   $samtools depth -a  -r xy:5-6 xx#depth3.bam
P d5_xy1.out   $samtools depth -aa -r xy:5-6 xx#depth3.bam
P d5_xx1.out   $samtools depth     -r xx:4-10 xx#depth3.bam
P d5_xx2.out   $samtools depth -a  -r xx:4-10 xx#depth3.bam
P d5_xx2.out   $samtools depth -aa -r xx:4-10 xx#depth3.bam
P d5_blank.out $samtools depth     -r xx:9    xx#depth3.bam
P d5_xx3.out   $samtools depth -a  -r xx:9    xx#depth3.bam
P d5_xx3.out   $samtools depth -aa -r xx:9    xx#depth3.bam
P d5_b3.out    $samtools depth     -b xx.bed3 xx#depth3.bam
P d5_b3aa.out  $samtools depth -aa -b xx.bed3 xx#depth3.bam

# Fail as -a shouldn't output xn:16-20 (it doesn't with -r)
F d5_b3a.out   $samtools depth -a  -b xx.bed3 xx#depth3.bam

# All reference positions in a file with no alignments
INIT x $samtools view -H -b -o xx#depth-noreads.bam xx#depth1.sam
P d5_all4.out $samtools depth -aa xx#depth-noreads.bam

#-----------------------------------------------------------------------------
# With mpileup simulation of depth
# This is a useful check that depth vs mpileup have the the same -a, -aa, -r
# and -b / -l semantics.

# Test basic 1 and 2 file outputs
P d1_1.out  $samtools mpileup -ABQ0 xx#depth1.sam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]"'
P d1_2.out  $samtools mpileup -ABQ0 xx#depth2.sam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]"'
P d1_12.out $samtools mpileup -ABQ0 xx#depth1.sam xx#depth2.sam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'

# Regions via -r or bed
P d1_12.out  $samtools mpileup -ABQ0 -r xx:5-16 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d1_12.out  $samtools mpileup -ABQ0 -l xx.bed  xx#depth1.sam xx#depth2.sam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d2_12r.out $samtools mpileup -ABQ0 -r xx:8-13 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d2_12r.out $samtools mpileup -ABQ0 -l xx.bed2 xx#depth1.sam xx#depth2.sam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'

# With single -a for all (in used refs)
P d3_12r1a.out $samtools mpileup -ABQ0 -a -r xx:5-16 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d3_12r1a.out $samtools mpileup -ABQ0 -a -l xx.bed  xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d3_12r2a.out $samtools mpileup -ABQ0 -a -r xx:8-13 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d3_12r2a.out $samtools mpileup -ABQ0 -a -l xx.bed2 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'

# With double -a for all including unused refs
P d4_12.out  $samtools mpileup -ABQ0 -a -a            xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d4_12r.out $samtools mpileup -ABQ0 -a -a -r xx:5-16 xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'
P d4_12b.out $samtools mpileup -ABQ0 -a -a -l xx.bed  xx#depth1.bam xx#depth2.bam | perl -lane 'print "$F[0]\t$F[1]\t$F[3]\t$F[6]"'

# With and without -J (include deletions)
P d6_wdel.out  $samtools depth -J depth_del.sam
P d6_nodel.out $samtools depth    depth_del.sam

# With -s (remove operlaps)
P d7_nodup.out $samtools depth -s xx#depth4.sam
