From 10e491538ef7828ec1ac7e34dee7004c9befc33a Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sun, 23 Jun 2024 13:27:17 -0700 Subject: [PATCH 1/2] Updating bamxx submodule --- src/bamxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bamxx b/src/bamxx index 7c2228c..e7f5a9b 160000 --- a/src/bamxx +++ b/src/bamxx @@ -1 +1 @@ -Subproject commit 7c2228c2f0233e9df1f1534f374e08c0a196ae55 +Subproject commit e7f5a9bd7ef785c2e426141d9f8cc9eaa2b80a07 From 8aacec55b5bf12e2f422a3c18fe02b35c0b92ff4 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sun, 23 Jun 2024 13:41:53 -0700 Subject: [PATCH 2/2] Removed redundant code that reads lines as kstring format from bgzf files --- src/analysis/cpgbins.cpp | 21 +-------------------- src/common/counts_header.cpp | 22 +--------------------- src/utils/covered.cpp | 20 +------------------- src/utils/unxcounts.cpp | 21 +-------------------- src/utils/xcounts.cpp | 21 +-------------------- 5 files changed, 5 insertions(+), 100 deletions(-) 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;