Skip to content

Commit

Permalink
Merge pull request #233 from smithlabcode/bamxx-submodule-update
Browse files Browse the repository at this point in the history
Updating bamxx submodule
  • Loading branch information
andrewdavidsmith authored Jun 23, 2024
2 parents 0f9e1e3 + 8aacec5 commit 4c39184
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 101 deletions.
21 changes: 1 addition & 20 deletions src/analysis/cpgbins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ format_levels_counter(const LevelsCounter &lc) {
return oss.str();
}

inline auto
getline(bgzf_file &file, kstring_t &line) -> bgzf_file & {
if (file.f == nullptr) return file;
const int x = bgzf_getline(file.f, '\n', &line);
if (x == -1) {
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
if (x < -1) {
// ADS: this is an error condition and should be handled
// differently from the EOF above.
file.destroy();
free(line.s);
line = {0, 0, nullptr};
throw runtime_error{"failed reading bgzf file"};
}
return file;
}

static unordered_map<string, uint64_t>
get_chrom_sizes(const string &chrom_sizes_file) {
Expand Down Expand Up @@ -163,7 +144,7 @@ read_xsym_by_chrom(const uint32_t n_threads, const string &xsym_file) {

vector<xsym_entry> curr_chrom;

while (getline(in, line)) {
while (bamxx::getline(in, line)) {
if (is_counts_header_line(line.s)) continue; // ADS: early loop exit

if (!std::isdigit(line.s[0])) { // check if we have a chrom line
Expand Down
2 changes: 1 addition & 1 deletion src/bamxx
Submodule bamxx updated 1 files
+22 −0 bamxx.hpp
22 changes: 1 addition & 21 deletions src/common/counts_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ write_counts_header_from_file(const string &header_file, bgzf_file &out) {
}


inline bgzf_file &
getline(bgzf_file &file, kstring_t &line) {
if (file.f == nullptr) return file;
const int x = bgzf_getline(file.f, '\n', &line);
if (x == -1) {
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
if (x < -1) {
// ADS: this is an error condition and should be handled
// differently from the EOF above.
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
return file;
}


bamxx::bgzf_file &
skip_counts_header(bamxx::bgzf_file &in) {

Expand All @@ -97,7 +77,7 @@ skip_counts_header(bamxx::bgzf_file &in) {
const int ret = ks_resize(&line, 1024);
if (ret) return in;

while (getline(in, line) && line.s[0] == '#') {
while (bamxx::getline(in, line) && line.s[0] == '#') {
if (line.s[0] == '#' && line.l == 1)
return in;
}
Expand Down
20 changes: 1 addition & 19 deletions src/utils/covered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ using std::string;

using bamxx::bgzf_file;

inline auto
getline(bgzf_file &file, kstring_t &line) -> bgzf_file & {
if (file.f == nullptr) return file;
const int x = bgzf_getline(file.f, '\n', &line);
if (x == -1) {
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
if (x < -1) {
// ADS: this is an error condition and should be handled
// differently from the EOF above.
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
return file;
}

static inline bool
get_is_mutated(const kstring_t &line) {
Expand Down Expand Up @@ -131,7 +113,7 @@ main_covered(int argc, const char **argv) {
if (ret) throw runtime_error("failed to acquire buffer");

bool write_ok = true;
while (getline(in, line) && write_ok) {
while (bamxx::getline(in, line) && write_ok) {
const bool is_mutated = get_is_mutated(line);
const uint32_t n_reads = get_n_reads(line);
if (n_reads > 0u || is_mutated) {
Expand Down
21 changes: 1 addition & 20 deletions src/utils/unxcounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ read_fasta_file_short_names_uppercase(const string &chroms_file,
[](const char c) { return std::toupper(c); });
}

inline auto
getline(bgzf_file &file, kstring_t &line) -> bgzf_file & {
if (file.f == nullptr) return file;
const int x = bgzf_getline(file.f, '\n', &line);
if (x == -1) {
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
if (x < -1) {
// ADS: this is an error condition and should be handled
// differently from the EOF above.
file.destroy();
free(line.s);
line = {0, 0, nullptr};
throw runtime_error{"failed reading bgzf file"};
}
return file;
}

static void
verify_chrom_orders(const bool verbose, const uint32_t n_threads,
Expand All @@ -108,7 +89,7 @@ verify_chrom_orders(const bool verbose, const uint32_t n_threads,
const int ret = ks_resize(&line, 1024);
if (ret) throw runtime_error("failed to acquire buffer");

while (getline(in, line)) {
while (bamxx::getline(in, line)) {
if (std::isdigit(line.s[0])) continue;
if (is_counts_header_line(line.s)) continue;

Expand Down
21 changes: 1 addition & 20 deletions src/utils/xcounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ using std::to_string;

using bamxx::bgzf_file;

inline auto
getline(bgzf_file &file, kstring_t &line) -> bgzf_file & {
if (file.f == nullptr) return file;
const int x = bgzf_getline(file.f, '\n', &line);
if (x == -1) {
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
if (x < -1) {
// ADS: this is an error condition and should be handled
// differently from the EOF above.
file.destroy();
free(line.s);
line = {0, 0, nullptr};
}
return file;
}


template<typename T>
static inline uint32_t
Expand Down Expand Up @@ -171,7 +152,7 @@ main_xcounts(int argc, const char **argv) {
bool found_header = (!genome_file.empty() || !header_file.empty());

MSite site;
while (status_ok && getline(in, line)) {
while (status_ok && bamxx::getline(in, line)) {
if (is_counts_header_line(line.s)) {
if (!genome_file.empty() || !header_file.empty()) continue;
found_header = true;
Expand Down

0 comments on commit 4c39184

Please sign in to comment.