1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#!/bin/bash
# This scripts allows to catch alterations of the code producing a different output from expected results
# The typical test is a comparison of number of lines produced
# Runs automatically with TravisCI, and is executed from the root of the repository.
# REQUIRES: ./test/demo.bam
# ./test/mock.bam
REMOVE=0
covtobed --version
set -eou pipefail
# Compilation success, checking that --version emits the expected "progname" string
echo -n " - Compiled binary prints version: "
if [ $(covtobed --version | grep covtobed | wc -l ) -eq "1" ];
then
echo PASS 1
fi
# Testing that -m MIN produces an output, and it fits the expectation for demo.bam (n. lines)
echo -n " - Minimum coverage, expected BED lines check: "
if [ $(covtobed -m 15 /usr/share/doc/covtobed-examples/examples/demo.bam | wc -l) -eq "12" ];
then
echo PASS 2
else
echo FAIL
exit 1
fi
# Checking thath --physical-coverage will work, and it fits the expected number of lines
echo -n " - Physical coverage, expected BED lines check: "
if [ $(covtobed --physical-coverage /usr/share/doc/covtobed-examples/examples/mp.bam | wc -l) -eq "136" ];
then
echo PASS 3
else
echo FAIL
exit 1
fi
# Checking stranded output: it should produce content in the fifth column of the bed file
echo -n " - Stranded output, testing column #5: "
if [ $(covtobed --out /usr/share/doc/covtobed-examples/examples/demo.bam | cut -f 5 | sort -u | wc -l) -eq "10" ];
then
echo PASS 4
else
echo FAIL
exit 1
fi
# Checking the "counts" output (counting the lines containing a ">")
echo -n " - Testing 'counts' format (printed headers): "
if [ $(covtobed --format counts /usr/share/doc/covtobed-examples/examples/demo.bam | grep '>' | wc -l) -eq "2" ];
then
echo PASS 5
else
echo FAIL
exit 1
fi
echo -n " - Testing 'counts' format (printed lines): "
if [ $(covtobed --format counts /usr/share/doc/covtobed-examples/examples/demo.bam | grep -v '>' | wc -l) -eq "202" ];
then
echo PASS 6
else
echo FAIL
exit 1
fi
# Checking BED output with reference output file
echo -n " - Checking identity of BED output with pre-calculated: "
covtobed /usr/share/doc/covtobed-examples/examples/demo.bam > output.test
if [ $(diff output.test /usr/share/doc/covtobed-examples/examples/output.bed | wc -l) -eq "0" ];
then
echo PASS 7
rm output.test
else
echo FAIL
exit 1
fi
## Synthetic BAM test
echo -n " - Checking computed coverage for a synthetic BAM file: "
covtobed -m 1 /usr/share/doc/covtobed-examples/examples/mock.bam > output.test
if [ $(diff output.test /usr/share/doc/covtobed-examples/examples/mock.bed | wc -l) -eq "0" ];
then
echo PASS 8
rm output.test
else
echo FAIL
exit 1
fi
## Filter non valid alignments
echo -n " - Checking filtering of invalid alignments: "
if [ $(covtobed -m 1 -d /usr/share/doc/covtobed-examples/examples/filtered.bam | wc -l) -eq "2" ] ; then
echo -n "PASS 9,"
else
echo FAIL
exit 1
fi
if [ $(covtobed -m 1 /usr/share/doc/covtobed-examples/examples/filtered.bam | wc -l) -eq "6" ] ; then
echo 10
else
echo "FAIL: $(covtobed -m 1 -d /usr/share/doc/covtobed-examples/examples/filtered.bam | wc -l)"
exit 1
fi
# A synthetic BAM containing reference name {n}X that should only print one reagion
# covered exactly {n}X times
echo " - Checking artificial coverage values:"
covtobed /usr/share/doc/covtobed-examples/examples/test_cov.bam -m 1 |cut -f 1,4| while read LINE;
do
echo "$LINE" | perl -ne '($exp, $cov)=split /\s+/, $_; if ("$exp" ne "${cov}X") {
die "$exp != $cov\n";
} else {
print "\t#OK expecting $exp, ${cov}X found\n";
}'
done
echo "ALL TESTS: PASSED"
|