From 5d50c7d58e5937100d0d2cd4de2e9795e0e0143b Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Tue, 19 Nov 2024 12:16:01 -0600 Subject: [PATCH 1/5] fix: Improve index-by parameter parsing to handle 64-bit integers correctly --- src/interface/parse_args.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/interface/parse_args.hpp b/src/interface/parse_args.hpp index b9ac224d..d92b8d1f 100644 --- a/src/interface/parse_args.hpp +++ b/src/interface/parse_args.hpp @@ -30,7 +30,7 @@ struct Parameters { }; int64_t handy_parameter(const std::string& value) { - auto is_a_float = [](const std::string s) { + auto is_a_number = [](const std::string s) { return !s.empty() && s.find_first_not_of("0123456789.") == std::string::npos && std::count(s.begin(), s.end(), '.') < 2; }; @@ -48,7 +48,11 @@ int64_t handy_parameter(const std::string& value) { } const std::string tmp = value.substr(0, str_len); - return is_a_float(tmp) ? (int)(stof(tmp) * pow(10, exp)) : -1; + if (!is_a_number(tmp)) { + return -1; + } + double val = std::stod(tmp); + return static_cast(val * std::pow(10, exp)); } void parse_args(int argc, From eda60fc4040c2b0012839d0f3823f07f7bb0c4d2 Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Tue, 19 Nov 2024 12:17:29 -0600 Subject: [PATCH 2/5] fix: Correct index-by parameter parsing to handle large values --- src/interface/parse_args.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interface/parse_args.hpp b/src/interface/parse_args.hpp index d92b8d1f..d190f99a 100644 --- a/src/interface/parse_args.hpp +++ b/src/interface/parse_args.hpp @@ -582,12 +582,12 @@ void parse_args(int argc, map_parameters.create_index_only = false; if (index_by) { - const int64_t index_size = wfmash::handy_parameter(args::get(index_by)); - if (index_size <= 0) { + const int64_t index_size = handy_parameter(args::get(index_by)); + if (index_size < 0) { std::cerr << "[wfmash] ERROR, skch::parseandSave, index-by size must be a positive integer." << std::endl; exit(1); } - map_parameters.index_by_size = index_size; + map_parameters.index_by_size = static_cast(index_size); } else { map_parameters.index_by_size = std::numeric_limits::max(); // Default to indexing all sequences } From 4022c580e2c1a35765e4132f6b1e135226757d20 Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Tue, 19 Nov 2024 12:18:47 -0600 Subject: [PATCH 3/5] feat: Add debug logging for index-by parameter parsing --- src/interface/parse_args.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interface/parse_args.hpp b/src/interface/parse_args.hpp index d190f99a..f1181755 100644 --- a/src/interface/parse_args.hpp +++ b/src/interface/parse_args.hpp @@ -582,12 +582,16 @@ void parse_args(int argc, map_parameters.create_index_only = false; if (index_by) { - const int64_t index_size = handy_parameter(args::get(index_by)); + std::string index_by_str = args::get(index_by); + std::cerr << "[wfmash] DEBUG: Processing index-by parameter: '" << index_by_str << "'" << std::endl; + const int64_t index_size = handy_parameter(index_by_str); + std::cerr << "[wfmash] DEBUG: Parsed index size: " << index_size << std::endl; if (index_size < 0) { std::cerr << "[wfmash] ERROR, skch::parseandSave, index-by size must be a positive integer." << std::endl; exit(1); } map_parameters.index_by_size = static_cast(index_size); + std::cerr << "[wfmash] DEBUG: Final index_by_size: " << map_parameters.index_by_size << std::endl; } else { map_parameters.index_by_size = std::numeric_limits::max(); // Default to indexing all sequences } From 9634d8ea7bb45f6fc9f55536795017bfb34897ca Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Tue, 19 Nov 2024 12:19:54 -0600 Subject: [PATCH 4/5] fix: Improve memory parameter parsing in wfmash command-line arguments --- src/interface/parse_args.hpp | 47 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/interface/parse_args.hpp b/src/interface/parse_args.hpp index f1181755..f3c2fbfc 100644 --- a/src/interface/parse_args.hpp +++ b/src/interface/parse_args.hpp @@ -30,29 +30,44 @@ struct Parameters { }; int64_t handy_parameter(const std::string& value) { - auto is_a_number = [](const std::string s) { + auto is_a_number = [](const std::string& s) { return !s.empty() && s.find_first_not_of("0123456789.") == std::string::npos && std::count(s.begin(), s.end(), '.') < 2; }; - uint64_t str_len = value.length(); + std::string tmp = value; uint8_t exp = 0; - if (value[str_len-1] == 'k' || value[str_len-1] == 'K') { - exp = 3; - --str_len; - } else if (value[str_len-1] == 'm' || value[str_len-1] == 'M') { - exp = 6; - --str_len; - } else if (value[str_len-1] == 'g' || value[str_len-1] == 'G') { - exp = 9; - --str_len; - } - - const std::string tmp = value.substr(0, str_len); + + if (!tmp.empty()) { + char suffix = std::toupper(tmp.back()); + if (suffix == 'K') { + exp = 3; + tmp.pop_back(); + } else if (suffix == 'M') { + exp = 6; + tmp.pop_back(); + } else if (suffix == 'G') { + exp = 9; + tmp.pop_back(); + } + } + if (!is_a_number(tmp)) { return -1; } - double val = std::stod(tmp); - return static_cast(val * std::pow(10, exp)); + + try { + double val = std::stod(tmp); + if (val < 0) { + return -1; + } + double result = val * std::pow(10.0, exp); + if (result > static_cast(std::numeric_limits::max())) { + return -1; + } + return static_cast(result); + } catch (const std::exception&) { + return -1; + } } void parse_args(int argc, From 3601360e03b50550d816ffb3feeb68f2e06b5d1e Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Tue, 19 Nov 2024 12:21:43 -0600 Subject: [PATCH 5/5] feat: Add index-by size to parameter logging output --- src/interface/parse_args.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/interface/parse_args.hpp b/src/interface/parse_args.hpp index f3c2fbfc..9ee467e9 100644 --- a/src/interface/parse_args.hpp +++ b/src/interface/parse_args.hpp @@ -597,16 +597,12 @@ void parse_args(int argc, map_parameters.create_index_only = false; if (index_by) { - std::string index_by_str = args::get(index_by); - std::cerr << "[wfmash] DEBUG: Processing index-by parameter: '" << index_by_str << "'" << std::endl; - const int64_t index_size = handy_parameter(index_by_str); - std::cerr << "[wfmash] DEBUG: Parsed index size: " << index_size << std::endl; + const int64_t index_size = handy_parameter(args::get(index_by)); if (index_size < 0) { std::cerr << "[wfmash] ERROR, skch::parseandSave, index-by size must be a positive integer." << std::endl; exit(1); } map_parameters.index_by_size = static_cast(index_size); - std::cerr << "[wfmash] DEBUG: Final index_by_size: " << map_parameters.index_by_size << std::endl; } else { map_parameters.index_by_size = std::numeric_limits::max(); // Default to indexing all sequences } @@ -690,7 +686,8 @@ void parse_args(int argc, << ", P=" << map_parameters.max_mapping_length << ", n=" << map_parameters.numMappingsForSegment << ", p=" << std::fixed << std::setprecision(0) << map_parameters.percentageIdentity * 100 << "%" - << ", t=" << map_parameters.threads << std::endl; + << ", t=" << map_parameters.threads + << ", b=" << map_parameters.index_by_size << std::endl; std::cerr << "[wfmash] Filters: " << (map_parameters.skip_self ? "skip-self" : "no-skip-self") << ", hg(Δ=" << map_parameters.ANIDiff << ",conf=" << map_parameters.ANIDiffConf << ")" << ", mode=" << map_parameters.filterMode << " (1=map,2=1-to-1,3=none)" << std::endl;