Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose output for sym and xcounts #227

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/utils/symmetric-cpgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ get_first_site(T &in, T &out) {
}

template<class T> 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);
Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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<string> leftover_args;
opt_parse.parse(argc, argv, leftover_args);
if (argc == 1 || opt_parse.help_requested()) {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions src/utils/xcounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string> leftover_args;
opt_parse.parse(argc, argv, leftover_args);
if (argc == 1 || opt_parse.help_requested()) {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;

Expand Down
Loading