diff --git a/src/bamxx b/src/bamxx index a9bf1878..09cfe360 160000 --- a/src/bamxx +++ b/src/bamxx @@ -1 +1 @@ -Subproject commit a9bf1878022235cdb331880957eff55889845315 +Subproject commit 09cfe360be875271014b2824fecd8b732e640630 diff --git a/src/utils/covered.cpp b/src/utils/covered.cpp index 9f9f5927..0ce1c916 100644 --- a/src/utils/covered.cpp +++ b/src/utils/covered.cpp @@ -15,26 +15,26 @@ * General Public License for more details. */ -#include -#include +#include + #include #include -#include +#include +#include // from smithlab_cpp #include "OptionParser.hpp" -#include "smithlab_utils.hpp" #include "smithlab_os.hpp" +#include "smithlab_utils.hpp" -using std::string; -using std::cout; using std::cerr; +using std::cout; using std::endl; using std::runtime_error; +using std::string; using bamxx::bgzf_file; - inline auto getline(bgzf_file &file, kstring_t &line) -> bgzf_file & { if (file.f == nullptr) return file; @@ -54,30 +54,25 @@ getline(bgzf_file &file, kstring_t &line) -> bgzf_file & { return file; } - -static inline -bool get_is_mutated(const kstring_t &line) { +static inline bool +get_is_mutated(const kstring_t &line) { const auto end_itr = line.s + line.l; return std::find(line.s, end_itr, 'x') != end_itr; } - -static inline -uint32_t get_n_reads(const kstring_t &line) { +static inline uint32_t +get_n_reads(const kstring_t &line) { const auto end_itr = std::make_reverse_iterator(line.s + line.l); const auto beg_itr = std::make_reverse_iterator(line.s); - auto n_reads_pos = std::find_if(end_itr, beg_itr, [](const char c) { - return c == ' ' || c == '\t'; - }); + auto n_reads_pos = std::find_if( + end_itr, beg_itr, [](const char c) { return c == ' ' || c == '\t'; }); ++n_reads_pos; return atoi(n_reads_pos.base()); } - int main_covered(int argc, const char **argv) { try { - size_t n_threads = 1; string outfile{"-"}; @@ -118,12 +113,14 @@ main_covered(int argc, const char **argv) { bgzf_file in(filename, "r"); if (!in) throw runtime_error("could not open file: " + filename); - bgzf_file out(outfile, "w"); + const auto outfile_mode = in.compression() ? "w" : "wu"; + + bgzf_file out(outfile, outfile_mode); if (!out) throw runtime_error("error opening output file: " + outfile); if (n_threads > 1) { // ADS: something breaks when we use the thread for the input - // tpool.set_io(in); + tpool.set_io(in); tpool.set_io(out); }