From edb4b967f0ea8edf23dcea0f047a04f7bf955121 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sat, 8 Jun 2024 16:52:54 -0700 Subject: [PATCH] sym and xcounts: adding verbose output to indicating chromosome being processed --- src/utils/symmetric-cpgs.cpp | 12 +++++++----- src/utils/xcounts.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/utils/symmetric-cpgs.cpp b/src/utils/symmetric-cpgs.cpp index 3c4190cb..b1d0cd9f 100644 --- a/src/utils/symmetric-cpgs.cpp +++ b/src/utils/symmetric-cpgs.cpp @@ -76,7 +76,7 @@ get_first_site(T &in, T &out) { } template static bool -process_sites(T &in, T &out) { +process_sites(const bool verbose, T &in, T &out) { // get the first site while dealing with the header auto [prev_site, prev_is_cpg] = get_first_site(in, out); @@ -101,6 +101,8 @@ process_sites(T &in, T &out) { } } else { + if (verbose) + cerr << "processing: " << curr_site.chrom << endl; if (chroms_seen.find(curr_site.chrom) != cend(chroms_seen)) return false; chroms_seen.insert(curr_site.chrom); @@ -125,7 +127,7 @@ main_symmetric_cpgs(int argc, const char **argv) { try { // file types from HTSlib use "-" for the filename to go to stdout string outfile{"-"}; - // (not used) bool VERBOSE = false; + bool verbose = false; bool compress_output = false; int32_t n_threads = 1; @@ -139,7 +141,7 @@ main_symmetric_cpgs(int argc, const char **argv) { outfile); opt_parse.add_opt("threads", 't', "number of threads", false, n_threads); opt_parse.add_opt("zip", 'z', "output gzip format", false, compress_output); - // opt_parse.add_opt("verbose", 'v', "print more run info", false, VERBOSE); + opt_parse.add_opt("verbose", 'v', "print more run info", false, verbose); std::vector leftover_args; opt_parse.parse(argc, argv, leftover_args); if (argc == 1 || opt_parse.help_requested()) { @@ -179,11 +181,11 @@ main_symmetric_cpgs(int argc, const char **argv) { tp.set_io(out); } - const bool sites_are_sorted = process_sites(in, out); + const bool sites_are_sorted = process_sites(verbose, in, out); if (!sites_are_sorted) { - namespace fs = std::filesystem; cerr << "sites are not sorted in: " << filename << endl; + namespace fs = std::filesystem; const fs::path outpath{outfile}; if (fs::exists(outpath)) fs::remove(outpath); return EXIT_FAILURE; diff --git a/src/utils/xcounts.cpp b/src/utils/xcounts.cpp index 2c77a49a..c9ddc3c9 100644 --- a/src/utils/xcounts.cpp +++ b/src/utils/xcounts.cpp @@ -82,6 +82,7 @@ fill_output_buffer(const uint32_t offset, const MSite &s, T &buf) { int main_xcounts(int argc, const char **argv) { try { + bool verbose = false; bool require_coverage = false; size_t n_threads = 1; string genome_file; @@ -104,6 +105,7 @@ main_xcounts(int argc, const char **argv) { false, header_file); opt_parse.add_opt("threads", 't', "threads for compression (use few)", false, n_threads); + opt_parse.add_opt("verbose", 'v', "print more run info", false, verbose); std::vector leftover_args; opt_parse.parse(argc, argv, leftover_args); if (argc == 1 || opt_parse.help_requested()) { @@ -132,20 +134,18 @@ main_xcounts(int argc, const char **argv) { const int ret = get_chrom_sizes_for_counts_header(n_threads, genome_file, chrom_names, chrom_sizes); - if (ret) throw dnmt_error("failed to get chrom sizes from: " + - genome_file); + if (ret) + throw dnmt_error{"failed to get chrom sizes from: " + genome_file}; } - bamxx::bam_tpool tpool(n_threads); - bgzf_file in(filename, "r"); - if (!in) throw dnmt_error("could not open file: " + filename); + if (!in) throw dnmt_error{"could not open file: " + filename}; const auto outfile_mode = in.is_compressed() ? "w" : "wu"; bgzf_file out(outfile, outfile_mode); - if (!out) throw dnmt_error("error opening output file: " + outfile); + if (!out) throw dnmt_error{"error opening output file: " + outfile}; if (n_threads > 1) { if (in.is_bgzf()) @@ -184,6 +184,8 @@ main_xcounts(int argc, const char **argv) { if (!status_ok || !found_header) break; if (site.chrom != prev_chrom) { + if (verbose) + cerr << "processing: " << site.chrom << endl; prev_chrom = site.chrom; offset = 0;