diff --git a/src/analysis/cpgbins.cpp b/src/analysis/cpgbins.cpp index 97be547..fd49f20 100644 --- a/src/analysis/cpgbins.cpp +++ b/src/analysis/cpgbins.cpp @@ -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 get_chrom_sizes(const string &chrom_sizes_file) { @@ -163,7 +144,7 @@ read_xsym_by_chrom(const uint32_t n_threads, const string &xsym_file) { vector 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 diff --git a/src/common/counts_header.cpp b/src/common/counts_header.cpp index a4df368..6ac4ff0 100644 --- a/src/common/counts_header.cpp +++ b/src/common/counts_header.cpp @@ -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) { @@ -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; } diff --git a/src/utils/covered.cpp b/src/utils/covered.cpp index 26efbc7..117a352 100644 --- a/src/utils/covered.cpp +++ b/src/utils/covered.cpp @@ -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) { @@ -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) { diff --git a/src/utils/unxcounts.cpp b/src/utils/unxcounts.cpp index 0cff2d0..ee64f8c 100644 --- a/src/utils/unxcounts.cpp +++ b/src/utils/unxcounts.cpp @@ -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, @@ -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; diff --git a/src/utils/xcounts.cpp b/src/utils/xcounts.cpp index c9ddc3c..ccadfde 100644 --- a/src/utils/xcounts.cpp +++ b/src/utils/xcounts.cpp @@ -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 static inline uint32_t @@ -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;