Skip to content

Commit

Permalink
1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed Oct 28, 2021
1 parent df6b379 commit 7fbe0f4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
11 changes: 7 additions & 4 deletions base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using namespace std;
typedef uint32_t DepthType; // type for depth of coverage, kept it small
const char ref_char = '>'; // reference prefix for "counts" output

const string VERSION = "%prog 1.3.0"
const string VERSION = "%prog 1.3.1"
"\nCopyright (C) 2014-2019 Giovanni Birolo and Andrea Telatin\n"
"https://github.com/telatin/covtobed - License MIT"
".\n"
Expand Down Expand Up @@ -105,8 +105,11 @@ struct Coverage {
else
--f;
}
bool operator==(const Coverage &o) const {
return f == o.f && r == o.r;
bool equal(const Coverage &o, bool stranded) const {
if (stranded)
return f == o.f && r == o.r;
else
return f + r == o.f + o.r;
}
};

Expand All @@ -122,7 +125,7 @@ class Output {
// write interval to bed
void operator() (const Interval &i, const Coverage &c) {
// can the last interval be extended with the same coverage?
if (i.ref == last_interval.ref && i.start == last_interval.end && last_coverage == c)
if (i.ref == last_interval.ref && i.start == last_interval.end && last_coverage.equal(c, strands))
// extend previous interval
last_interval.end = i.end;
else {
Expand Down
Binary file added test/filt.bam
Binary file not shown.
Binary file added test/nano.bam
Binary file not shown.
Binary file added test/stranded.bam
Binary file not shown.
32 changes: 23 additions & 9 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@ if [ ! -e "./covtobed" ]; then
if [ `uname` == 'Darwin' ]; then
echo " - Copying macOS binary" || echo " ERROR: pre-compiled binary not working"
cp ./binaries/covtobed_mac ./covtobed
covtobed --version
covtobed --version >/dev/null || echo " ERROR: pre-compiled binary not working"
else
echo " - Trying Ubuntu binary"
cp ./binaries/covtobed ./covtobed
covtobed --version || echo " ERROR: pre-compiled binary not working"
covtobed --version >/dev/null || echo " ERROR: pre-compiled binary not working"
fi
fi

./covtobed --version

echo " ================================================ "
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" ];
if [ $(./covtobed --version | grep covtobed | wc -l ) -gt "1" ];
then
echo PASS 1
echo PASS $(./covtobed --version | grep covtobed |head -n 1)
else
echo FAIL $(./covtobed --version | grep covtobed | wc -l )
exit
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 test/demo.bam | wc -l) -eq "12" ];
Expand Down Expand Up @@ -78,20 +84,28 @@ else
exit 1
fi
echo -n " - Testing 'counts' format (printed lines): "
if [ $(./covtobed --format counts test/demo.bam | grep -v '>' | wc -l) -eq "202" ];
if [ $(./covtobed --format counts test/demo.bam | grep -v \> | wc -l) -eq "202" ];
then
echo PASS 6
else
echo FAIL
echo FAIL $(./covtobed --format counts test/demo.bam | grep -v \> | wc -l) when 202 expected
exit 1
fi

echo -n " - Testing strand with adjacent intervals: "
if [[ $(./covtobed test/stranded.bam | wc -l) -eq "1" && $(./covtobed --output-strands test/stranded.bam | wc -l) -eq "2" ]];
then
echo PASS 7
else
echo FAIL $(./covtobed --format counts test/demo.bam | grep -v \> | wc -l) when 202 expected
exit 1
fi
# Checking BED output with reference output file
echo -n " - Checking identity of BED output with pre-calculated: "
./covtobed test/demo.bam > test/output.test
if [ $(diff test/output.test test/output.bed | wc -l) -eq "0" ];
then
echo PASS 7
echo PASS 8
rm test/output.test
else
echo FAIL
Expand All @@ -103,7 +117,7 @@ echo -n " - Checking computed coverage for a synthetic BAM file: "
./covtobed -m 1 test/mock.bam > test/output.test
if [ $(diff test/output.test test/mock.bed | wc -l) -eq "0" ];
then
echo PASS 8
echo PASS 9
rm test/output.test
else
echo FAIL
Expand All @@ -113,7 +127,7 @@ fi
## Filter non valid alignments
echo -n " - Checking filtering of invalid alignments: "
if [ $(./covtobed -m 1 -d test/filtered.bam | wc -l) -eq "2" ] ; then
echo -n "PASS 9,"
echo -n "PASS 10,"
else
echo FAIL
exit 1
Expand Down

0 comments on commit 7fbe0f4

Please sign in to comment.