Skip to content

Commit

Permalink
Removed redundant code that reads lines as kstring format from bgzf f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
andrewdavidsmith committed Jun 23, 2024
1 parent 10e4915 commit 8aacec5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 100 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
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 8aacec5

Please sign in to comment.