Skip to content

Commit

Permalink
hcitk: support replaying warnings right before app exit
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 6, 2024
1 parent da6732a commit 4574105
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 68 deletions.
8 changes: 8 additions & 0 deletions src/hictk/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "hictk/tools/cli.hpp"

#include <fmt/format.h>
#include <spdlog/spdlog.h>

#include <CLI/CLI.hpp>
#include <cassert>
Expand All @@ -25,6 +26,13 @@ std::string_view Cli::get_printable_subcommand() const noexcept {
return Cli::subcommand_to_str(get_subcommand());
}

void Cli::log_warnings() const noexcept {
for (const auto& w : _warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}
_warnings.clear();
}

auto Cli::parse_arguments() -> Config {
try {
_cli.name(_exec_name);
Expand Down
13 changes: 4 additions & 9 deletions src/hictk/cli/cli_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ void Cli::make_dump_subcommand() {
void Cli::validate_dump_subcommand() const {
assert(_cli.get_subcommand("dump")->parsed());

std::vector<std::string> warnings;
std::vector<std::string> errors;
const auto& c = std::get<DumpConfig>(_config);

Expand All @@ -164,26 +163,26 @@ void Cli::validate_dump_subcommand() const {
const auto resolution_parsed = !subcmd.get_option("--resolution")->empty();

if ((is_cooler || is_scool) && resolution_parsed) {
warnings.emplace_back("--resolution is ignored when file is in .[s]cool format.");
_warnings.emplace_back("--resolution is ignored when file is in .[s]cool format.");
}

const auto range_parsed = !subcmd.get_option("--range")->empty();
if (range_parsed && c.table != "chroms" && c.table != "bins" && c.table != "pixels" &&
c.table != "weights") {
warnings.emplace_back(
_warnings.emplace_back(
"--range and --range2 are ignored when --table is not bins, chroms, pixels, or weights");
}

const auto query_file_parsed = !subcmd.get_option("--query-file")->empty();
if (query_file_parsed && c.table != "bins" && c.table != "pixels") {
warnings.emplace_back("--query-file is ignored when --table is not bins or pixels");
_warnings.emplace_back("--query-file is ignored when --table is not bins or pixels");
}

const auto matrix_type_parsed = !subcmd.get_option("--matrix-type")->empty();
const auto matrix_unit_parsed = !subcmd.get_option("--matrix-unit")->empty();

if (!is_hic && (matrix_type_parsed || matrix_unit_parsed)) {
warnings.emplace_back(
_warnings.emplace_back(
"--matrix-type and --matrix-unit are ignored when input file is not in .hic format.");
}

Expand All @@ -205,10 +204,6 @@ void Cli::validate_dump_subcommand() const {
errors.emplace_back("--balance requires --table=pixels.");
}

for (const auto& w : warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}

if (!errors.empty()) {
throw std::runtime_error(
fmt::format(FMT_STRING("the following error(s) where encountered while validating CLI "
Expand Down
15 changes: 5 additions & 10 deletions src/hictk/cli/cli_fix_mcool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void Cli::make_fix_mcool_subcommand() {
void Cli::validate_fix_mcool_subcommand() const {
const auto& c = std::get<FixMcoolConfig>(_config);
std::vector<std::string> errors;
std::vector<std::string> warnings{};

if (!c.force && std::filesystem::exists(c.path_to_output)) {
errors.emplace_back(fmt::format(
Expand All @@ -113,20 +112,20 @@ void Cli::validate_fix_mcool_subcommand() const {
if (c.skip_balancing) {
const auto* sc = _cli.get_subcommand("fix-mcool");
if (!sc->get_option("--tmpdir")->empty()) {
warnings.emplace_back("option --tmpdir is ignored when --skip-balancing is provided.");
_warnings.emplace_back("option --tmpdir is ignored when --skip-balancing is provided.");
}
if (!sc->get_option("--in-memory")->empty()) {
warnings.emplace_back("option --in-memory is ignored when --skip-balancing is provided.");
_warnings.emplace_back("option --in-memory is ignored when --skip-balancing is provided.");
}
if (!sc->get_option("--compression-lvl")->empty()) {
warnings.emplace_back(
_warnings.emplace_back(
"option --compression-lvl is ignored when --skip-balancing is provided.");
}
if (!sc->get_option("--chunk-size")->empty()) {
warnings.emplace_back("option --chunk-size is ignored when --skip-balancing is provided.");
_warnings.emplace_back("option --chunk-size is ignored when --skip-balancing is provided.");
}
if (!sc->get_option("--threads")->empty()) {
warnings.emplace_back("option --threads is ignored when --skip-balancing is provided.");
_warnings.emplace_back("option --threads is ignored when --skip-balancing is provided.");
}
}

Expand All @@ -137,10 +136,6 @@ void Cli::validate_fix_mcool_subcommand() const {
FMT_STRING("fixing .mcool with storage-mode=\"{}\" is not supported"), *storage_mode));
}

for (const auto& w : warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}

if (!errors.empty()) {
throw std::runtime_error(fmt::format(
FMT_STRING(
Expand Down
7 changes: 1 addition & 6 deletions src/hictk/cli/cli_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ void Cli::make_load_subcommand() {
void Cli::validate_load_subcommand() const {
assert(_cli.get_subcommand("load")->parsed());

std::vector<std::string> warnings;
std::vector<std::string> errors;
const auto& c = std::get<LoadConfig>(_config);
const auto& sc = *_cli.get_subcommand("load");
Expand Down Expand Up @@ -230,14 +229,10 @@ void Cli::validate_load_subcommand() const {
}

if (c.format == "4dn" && c.format == "validpairs" && c.assume_sorted) {
warnings.emplace_back(
_warnings.emplace_back(
"--assume-sorted has no effect when ingesting interactions in 4dn or validpairs format.");
}

for (const auto& w : warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}

if (!errors.empty()) {
throw std::runtime_error(
fmt::format(FMT_STRING("the following error(s) where encountered while validating CLI "
Expand Down
9 changes: 2 additions & 7 deletions src/hictk/cli/cli_zoomify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ static std::vector<std::uint32_t> detect_invalid_resolutions(
void Cli::validate_zoomify_subcommand() const {
assert(_cli.get_subcommand("zoomify")->parsed());

std::vector<std::string> warnings;
std::vector<std::string> errors;
const auto& c = std::get<ZoomifyConfig>(_config);

Expand Down Expand Up @@ -206,7 +205,7 @@ void Cli::validate_zoomify_subcommand() const {

if (base_resolution == 0) { // Variable bin size
errors.clear();
warnings.clear();
_warnings.clear();
errors.emplace_back("Zoomifying files with variable bin size is currently not supported.");
} else {
if (const auto dupl = detect_duplicate_resolutions(c.resolutions); !dupl.empty()) {
Expand All @@ -226,16 +225,12 @@ void Cli::validate_zoomify_subcommand() const {
const auto nice_or_pow2_steps_parsed =
!sc->get_option("--nice-steps")->empty() || !sc->get_option("--pow2-steps")->empty();
if (!c.resolutions.empty() && nice_or_pow2_steps_parsed) {
warnings.emplace_back(
_warnings.emplace_back(
"--nice-steps and --pow2-steps are ignored when resolutions are explicitly set with "
"--resolutions.");
}
}

for (const auto& w : warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}

if (!errors.empty()) {
throw std::runtime_error(
fmt::format(FMT_STRING("the following error(s) where encountered while validating CLI "
Expand Down
2 changes: 2 additions & 0 deletions src/hictk/include/hictk/tools/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class Cli {
[[nodiscard]] int exit(const CLI::ParseError& e) const;
[[nodiscard]] int exit() const noexcept;
[[nodiscard]] static std::string_view subcommand_to_str(subcommand s) noexcept;
void log_warnings() const noexcept;

private:
int _argc;
Expand All @@ -229,6 +230,7 @@ class Cli {
Config _config{};
CLI::App _cli{};
subcommand _subcommand{subcommand::help};
mutable std::vector<std::string> _warnings{};

void make_balance_subcommand();
void make_ice_balance_subcommand(CLI::App& app);
Expand Down
Loading

0 comments on commit 4574105

Please sign in to comment.