Skip to content

Commit 3d76deb

Browse files
committed
2 parents dc6fd7f + 0a691f6 commit 3d76deb

17 files changed

+91
-49
lines changed

CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
If you wish to fix a bug or add new features to the software we welcome Pull Requests.
1+
# Contributing to `covtobed`
2+
3+
If you wish to fix a bug or add new features to the software we welcome **Pull Requests**.
24

35
We use [GitHub Flow style development](https://guides.github.com/introduction/flow/).
46

Docker/README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# Docker container
22

33
This directories contains files to generate the Docker/Singularity images that provide:
4-
* `covtobed` as described in the [README](../README.md)
5-
* `coverage` a legacy program with some more features that has been used for the EU project _MD-PAEDIGREE_.
4+
5+
* `covtobed` as described in the [README](../README.md)
6+
* `coverage` a legacy program with some more features that has been used for the EU project _MD-PAEDIGREE_.
67

7-
## How to get it
8+
## How to get it
89

9-
The Docker image is distributed via [Docker Hub](https://hub.docker.com/r/andreatelatin/covtobed):
10+
The Docker image is distributed via [Docker Hub](https://hub.docker.com/r/andreatelatin/covtobed):
1011

11-
```
12-
sudo docker pull andreatelatin/covtobed
13-
```
12+
```bash
13+
sudo docker pull andreatelatin/covtobed
14+
```
1415

1516
The Singularity image can be pulled from Docker Hub as well. A snapshot (v. 0.3) is available from [Zenodo](https://zenodo.org/record/1063493):
16-
```
17+
18+
```bash
1719
singularity pull andreatelatin/covtobed
1820
```

Dockerfile

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
FROM ubuntu:14.04
2-
MAINTAINER Andrea Telatin <[email protected]>
32
COPY Docker/coverage /bin/coverage
43
COPY Docker/v2.3.0.tar.gz /
54
RUN mkdir /covtobed
65
COPY *.cpp *.h /covtobed/
7-
RUN apt-get update && apt-get install -y software-properties-common
6+
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common=0.92.37.8 \
7+
&& apt-get clean \
8+
&& rm -rf /var/lib/apt/lists/*
89

910
RUN add-apt-repository universe && apt-get update
10-
RUN apt-get install -y build-essential cmake wget libz-dev
11+
RUN apt-get install -y --no-install-recommends build-essential=11.6ubuntu6 cmake=2.8.12.2-0ubuntu3 wget=1.15-1ubuntu1 zlib1g-dev=1:1.2.8.dfsg-1ubuntu1.1 \
12+
&& apt-get clean \
13+
&& rm -rf /var/lib/apt/lists/*
1114
RUN tar xvfz "v2.3.0.tar.gz"
12-
RUN mkdir /bamtools-2.3.0/build && cd /bamtools-2.3.0/build && cmake .. && make
15+
RUN mkdir /bamtools-2.3.0/build
16+
WORKDIR /bamtools-2.3.0/build
17+
RUN cmake ..
18+
RUN make
1319
RUN cp /bamtools-2.3.0/lib/libbamtools* /usr/lib/x86_64-linux-gnu/
1420

15-
RUN cd /covtobed && c++ -std=c++11 *.cpp -I/bamtools-2.3.0/include/ /usr/lib/x86_64-linux-gnu/libbamtools.a \
21+
WORKDIR /covtobed
22+
RUN c++ -std=c++11 ./*.cpp -I/bamtools-2.3.0/include/ /usr/lib/x86_64-linux-gnu/libbamtools.a \
1623
-o /bin/covtobed -lz;

OptionParser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace optparse {
2626
////////// auxiliary (string) functions { //////////
2727
class str_wrap {
2828
public:
29-
str_wrap(const string& l, const string& r) : lwrap(l), rwrap(r) {}
30-
str_wrap(const string& w) : lwrap(w), rwrap(w) {}
29+
explicit str_wrap(const string& l, const string& r) : lwrap(l), rwrap(r) {}
30+
explicit str_wrap(const string& w) : lwrap(w), rwrap(w) {}
3131
string operator() (const string& s) { return lwrap + s + rwrap; }
3232
const string lwrap, rwrap;
3333
};

README.md

+38-16
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
[![Bioconda installs](https://img.shields.io/conda/dn/bioconda/covtobed)](https://anaconda.org/bioconda/covtobed)
66
[![TravisCI Build Status](https://travis-ci.org/telatin/covtobed.svg?branch=master)](https://travis-ci.org/telatin/covtobed)
77
[![Docker build](https://img.shields.io/docker/cloud/build/andreatelatin/covtobed)](https://hub.docker.com/r/andreatelatin/covtobed)
8-
[![Singularity Zenodo Record](https://img.shields.io/badge/singularity-available-yellow)](https://zenodo.org/record/3600261)
9-
8+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/36944efb0d2b44cca850964e96c036a4)](https://www.codacy.com/manual/telatin/covtobed?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=telatin/covtobed&amp;utm_campaign=Badge_Grade)
9+
[![status](https://joss.theoj.org/papers/0ed74df9f40a58a852bf3fff512acd2b/status.svg)](https://joss.theoj.org/papers/0ed74df9f40a58a852bf3fff512acd2b)
1010

1111
### a tool to generate BED coverage tracks from BAM files
1212

1313
Reads one (or more) [alignment](https://en.wikipedia.org/wiki/Sequence_alignment) files
1414
(sorted [BAM](https://en.wikipedia.org/wiki/SAM_(file_format))) and prints a [BED](https://en.wikipedia.org/wiki/BED_(file_format)) with the [coverage](https://en.wikipedia.org/wiki/Coverage_(genetics)). It will join consecutive bases with the same coverage, and can be used to only print a BED file with the regions having a specific coverage range.
1515

16-
:book: [Read more in the wiki](https://github.com/telatin/covtobed/wiki)
16+
:book: **[Read more in the wiki](https://github.com/telatin/covtobed/wiki)** - this is the **main** documentation source
1717

1818

19-
[![covtobed example](img/coverage_bam_to_bed.png)](https://github.com/telatin/covtobed/wiki)
19+
[![covtobed example](img/covtobed-vignette.png)](https://github.com/telatin/covtobed/wiki)
2020

2121

2222
## Usage
@@ -58,7 +58,7 @@ Command:
5858
covtobed -m 0 -x 5 test/demo.bam
5959
```
6060
Output:
61-
```
61+
```text
6262
[...]
6363
NC_001416.1 0 2 0
6464
NC_001416.1 2 6 1
@@ -69,29 +69,30 @@ NC_001416.1 169 170 4
6969
NC_001416.1 201 206 4
7070
[...]
7171
```
72+
7273
See the full example output from different tools [:open_file_folder: here](https://github.com/telatin/covtobed/blob/master/test/output/README.md)
7374

7475
## Install
7576

76-
* To install with Miniconda:
77+
* To install with Miniconda:
7778

78-
```
79+
```bash
7980
conda install -c bioconda covtobed
8081
```
8182

82-
* Both **covtobed**, and the legacy program [**coverage**](https://github.com/telatin/covtobed/wiki/Using-coverage) are available as a single Docker container available from Docker Hub [![Docker build](https://img.shields.io/docker/cloud/build/andreatelatin/covtobed)](https://hub.docker.com/r/andreatelatin/covtobed)
83-
:
84-
```
83+
* Both **covtobed**, and the legacy program [**coverage**](https://github.com/telatin/covtobed/wiki/Using-coverage) are available as a single Docker container available from Docker Hub [![Docker build](https://img.shields.io/docker/cloud/build/andreatelatin/covtobed)](https://hub.docker.com/r/andreatelatin/covtobed):
84+
85+
```bash
8586
sudo docker pull andreatelatin/covtobed
8687
sudo docker run --rm -ti andreatelatin/covtobed coverage -h
8788
```
8889

8990
* Download Singularity image by `singularity pull docker://andreatelatin/covtobed`, then:
90-
```
91+
92+
```bash
9193
singularity exec covtobed.simg coverage -h
9294
```
9395

94-
9596
## Performance
9697

9798
*covtobed* is generally faster than *bedtools*. More details are in the [benchmark](benchmark) page.
@@ -107,17 +108,38 @@ c++ -std=c++11 *.cpp -I/path/to/bamtools/ -L${HOME}/path/to/lib/ -lbamtools -o c
107108

108109
## Issues, Limitations and how to contribute
109110

110-
- This program will read the coverage from *sorted BAM* files. The *CRAM* format is not supported at the moment.
111-
- If you find a problem feel free to [raise an issue](https://github.com/telatin/covtobed/issues), we will try to address it as soon as possible
112-
- [Contributions](CONTRIBUTING.md) are welcome via PR.
111+
* This program will read the coverage from *sorted BAM* files. The *CRAM* format is not supported at the moment.
112+
* If you find a problem feel free to [raise an issue](https://github.com/telatin/covtobed/issues), we will try to address it as soon as possible
113+
* [Contributions](CONTRIBUTING.md) are welcome via PR.
113114

114115
## Acknowledgements
115116

116117
This tools uses [libbamtools](https://github.com/pezmaster31/bamtools) by Derek Barnett, Erik Garrison, Gabor Marth and Michael Stromberg, and [cpp-optparse](https://github.com/weisslj/cpp-optparse) by Johannes Weißl. Both tools and this program are released with MIT license.
117118

118-
119119
## Authors
120120

121121
Giovanni Birolo ([@gbirolo](https://github.com/gbirolo)), University of Turin, and Andrea Telatin ([@telatin](https://github.com/telatin)), Quadram Institute Bioscience.
122122

123123
This program was finalized with a Flexible Talent Mobility Award funded by BBSRC through the [Quadram Institute](https://quadram.ac.uk).
124+
125+
## Citation
126+
127+
If you use this tool, why not citing the paper?
128+
129+
> Birolo et al., (2020). covtobed: a simple and fast tool to extract coverage tracks from BAM files. Journal of Open Source Software, 5(47), 2119, https://doi.org/10.21105/joss.02119
130+
131+
BibTeX citation:
132+
```latex
133+
@article{Birolo2020,
134+
doi = {10.21105/joss.02119},
135+
url = {https://doi.org/10.21105/joss.02119},
136+
year = {2020},
137+
publisher = {The Open Journal},
138+
volume = {5},
139+
number = {47},
140+
pages = {2119},
141+
author = {Giovanni Birolo and Andrea Telatin},
142+
title = {covtobed: a simple and fast tool to extract coverage tracks from BAM files},
143+
journal = {Journal of Open Source Software}
144+
}
145+
```

base.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ using namespace std;
1616
typedef uint32_t DepthType; // type for depth of coverage, kept it small
1717
const char ref_char = '>'; // reference prefix for "counts" output
1818

19-
const string VERSION = "%prog 1.1.0"
19+
const string VERSION = "%prog 1.1.3"
2020
"\nCopyright (C) 2014-2019 Giovanni Birolo and Andrea Telatin\n"
21-
"License MIT"
21+
"https://github.com/telatin/covtobed - License MIT"
2222
".\n"
2323
"This is free software: you are free to change and redistribute it.\n"
2424
"There is NO WARRANTY, to the extent permitted by law.";
@@ -210,6 +210,12 @@ int main(int argc, char *argv[]) {
210210
min_mapq = options.get("min_mapq");
211211
}
212212

213+
if (physical_coverage and only_valid) {
214+
// https://github.com/telatin/covtobed/issues/11
215+
cerr << "Parameters --physical-coverage and --discard-invalid-alignments are currently mutually exclusive." << endl;
216+
exit(0);
217+
}
218+
213219
try {
214220
// open input and output
215221
Input input(parser.args(), min_mapq, only_valid);
@@ -274,7 +280,7 @@ int main(int argc, char *argv[]) {
274280
if (more_alignments) {
275281
throw string("Unexpected alignment found, is the BAM sorted?");
276282
}
277-
} catch (string msg) {
283+
} catch (const string &msg) {
278284
parser.error(msg);
279285
}
280286
return 0;

benchmark/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ See also [example2.bam benchmark](disk/benchmark2_example2.md).
7474

7575
### Human whole genome sequencing - Saving to disk
7676

77-
The human genome was downloaded from:
77+
The human genome alignment file (124,379,080 alignments) was downloaded from:
7878

79-
ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/data_collections/1000_genomes_project/data/GBR/HG00114/alignment/HG00114.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram
79+
:link: ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/data_collections/1000_genomes_project/data/GBR/HG00114/alignment/HG00114.alt_bwamem_GRCh38DH.20150718.GBR.low_coverage.cram
8080

8181
| Command | Mean [s] | Min [s] | Max [s] | Relative |
8282
|:---|---:|---:|---:|---:|

binaries/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Precompiled binaries for Linux and OS X
22

3-
* Linux: https://github.com/telatin/covtobed/releases/download/v0.3/covtobed
4-
* OS X: https://github.com/telatin/covtobed/releases/download/v0.3/covtobed_osx
3+
* Linux: [https://github.com/telatin/covtobed/releases/download/v0.3/covtobed](https://github.com/telatin/covtobed/releases/download/v0.3/covtobed)
4+
* OS X: [https://github.com/telatin/covtobed/releases/download/v0.3/covtobed_osx](https://github.com/telatin/covtobed/releases/download/v0.3/covtobed_osx)
55

66
The Linux binary has been tested with Ubuntu 14.04, Ubuntu 18.04, Fedora 26 and Fedora 30.

binaries/build_osx.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
1414
cd "$SCRIPT_DIR/.."
1515

1616
sed -i.bak 's/#define debug if(.*)/#define debug if(true)/' base.cpp
17-
c++ -std=c++11 *.cpp -I${HOME}/miniconda3/include/bamtools/ -L${HOME}/miniconda3/lib/ $HOME/miniconda3/lib/libbamtools.a \
17+
c++ -std=c++11 ./*.cpp -I"${HOME}"/miniconda3/include/bamtools/ -L$"{HOME}"/miniconda3/lib/ "$HOME"/miniconda3/lib/libbamtools.a \
1818
-o binaries/covtobed_mac_debug -lz
1919

2020
sed -i.bak 's/#define debug if(.*)/#define debug if(false)/' base.cpp
21-
c++ -std=c++11 *.cpp -I${HOME}/miniconda3/include/bamtools/ -L${HOME}/miniconda3/lib/ $HOME/miniconda3/lib/libbamtools.a \
21+
c++ -std=c++11 ./*.cpp -I"${HOME}"/miniconda3/include/bamtools/ -L"${HOME}"/miniconda3/lib/ "$HOME"/miniconda3/lib/libbamtools.a \
2222
-o binaries/covtobed_mac -lz
2323
cd -

binaries/build_ubuntu.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ cd "$SCRIPT_DIR/.."
77

88
# Make DEBUG
99
sed -i 's/#define debug if(.*)/#define debug if(true)/' base.cpp
10-
c++ -std=c++11 *.cpp -I/usr/include/bamtools /usr/lib/x86_64-linux-gnu/libbamtools.a /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a \
10+
c++ -std=c++11 ./*.cpp -I/usr/include/bamtools /usr/lib/x86_64-linux-gnu/libbamtools.a /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a \
1111
-o binaries/covtobed_debug -lz
12-
cd -
1312

1413

1514
# Make NORMAL
1615
sed -i 's/#define debug if(.*)/#define debug if(false)/' base.cpp
17-
c++ -std=c++11 *.cpp -I/usr/include/bamtools /usr/lib/x86_64-linux-gnu/libbamtools.a /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a \
16+
c++ -std=c++11 ./*.cpp -I/usr/include/bamtools /usr/lib/x86_64-linux-gnu/libbamtools.a /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a \
1817
-o binaries/covtobed -lz
19-
cd -
18+
cd -

binaries/covtobed

0 Bytes
Binary file not shown.

binaries/covtobed_debug

0 Bytes
Binary file not shown.

binaries/covtobed_mac

10.3 KB
Binary file not shown.

binaries/covtobed_mac_debug

10.3 KB
Binary file not shown.

img/covtobed-vignette.png

30.5 KB
Loading

test/output/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
Output of *mosdepth*, *covtobed* and *bedtools genomecov* from the ../demo.bam file
44

5-
6-
```
5+
```bash
76
covtobed ../demo.bam > covtobed.bed
87
bedtools genomecov -bga -ibam ../demo.bam > bedtools.bed
98
mosdepth mos ../demo.bam && zcat mos.per-base.bed.gz > mosdepth.bed && rm mos.*

test/test.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
# REQUIRES: ./test/demo.bam
77
# ./test/mock.bam
88

9-
9+
REMOVE=0
1010
if [ ! -e "test/demo.bam" ]; then
1111
echo "WARNING: running this test from a bad location"
1212
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
1313
cd "$DIR"/..
1414
fi
1515

1616
if [ ! -e "./covtobed" ]; then
17+
REMOVE=1
1718
echo "WARNING:"
1819
echo "Binary not found: tring to use pre-compiled...";
1920
if [ `uname` == 'Darwin' ]; then
@@ -129,10 +130,14 @@ fi
129130
echo " - Checking artificial coverage values:"
130131
./covtobed test/test_cov.bam -m 1 |cut -f 1,4| while read LINE;
131132
do
132-
echo $LINE | perl -ne '($exp, $cov)=split /\s+/, $_; if ("$exp" ne "${cov}X") {
133+
echo "$LINE" | perl -ne '($exp, $cov)=split /\s+/, $_; if ("$exp" ne "${cov}X") {
133134
die "$exp != $cov\n";
134135
} else {
135136
print "\t#OK expecting $exp, ${cov}X found\n";
136137
}'
137138
done
138139
echo "ALL TESTS: PASSED"
140+
141+
if [[ $REMOVE -eq 1 ]]; then
142+
rm ./covtobed
143+
fi

0 commit comments

Comments
 (0)