Skip to content

Commit

Permalink
Merge pull request #199 from smithlabcode/covered-compression-mode
Browse files Browse the repository at this point in the history
covered compression mode
  • Loading branch information
andrewdavidsmith committed Dec 3, 2023
2 parents a91d899 + b5f987c commit d085d4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/bamxx
Submodule bamxx updated 1 files
+6 −0 bamxx.hpp
37 changes: 17 additions & 20 deletions src/utils/covered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
* General Public License for more details.
*/

#include <string>
#include <vector>
#include <bamxx.hpp>

#include <iostream>
#include <stdexcept>
#include <bamxx.hpp>
#include <string>
#include <vector>

// 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;
Expand All @@ -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{"-"};
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d085d4b

Please sign in to comment.