From 39207e11d522e4f2088f8ea7fa74d1ed244e3a42 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Sun, 16 Sep 2018 23:08:38 +0530 Subject: [PATCH 1/9] warn for unused parameters --- src/validator_main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/validator_main.cpp b/src/validator_main.cpp index c04b90499..3bfba44a9 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -160,15 +160,20 @@ int main(int argc, char** argv) po::options_description desc = build_command_line_options(); po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unused_args = collect_unrecognized(parsed.options, po::include_positional); + + for (auto a: unused_args) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + } + po::notify(vm); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } if (check_options > 0) { return check_options; } bool is_valid; - try { auto path = vm[ebi::vcf::INPUT].as(); auto level = vm[ebi::vcf::LEVEL].as(); From abf548789e7e0d2bb219d6eba80c3426014808bd Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 18 Sep 2018 01:25:53 +0530 Subject: [PATCH 2/9] refactor out the build_variable_map function --- src/validator_main.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/validator_main.cpp b/src/validator_main.cpp index 3bfba44a9..d4f9ec445 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -57,6 +57,21 @@ namespace return description; } + po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) + { + po::variables_map vm; + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unused_args = collect_unrecognized(parsed.options, po::include_positional); + + for (auto a: unused_args) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + } + + po::notify(vm); + return vm; + } + int check_command_line_options(po::variables_map const & vm, po::options_description const & desc) { if (vm.count(ebi::vcf::HELP)) { @@ -112,7 +127,8 @@ namespace return outdir_boost_path.string(); } - std::vector> get_outputs(std::string const &output_str, std::string const &input) { + std::vector> get_outputs(std::string const &output_str, std::string const &input) + { std::vector outs; ebi::util::string_split(output_str, ",", outs); size_t initial_size = outs.size(); @@ -159,16 +175,7 @@ int main(int argc, char** argv) ebi::util::init_boost_loggers(); po::options_description desc = build_command_line_options(); - po::variables_map vm; - po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); - po::store(parsed,vm); - std::vector unused_args = collect_unrecognized(parsed.options, po::include_positional); - - for (auto a: unused_args) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; - } - - po::notify(vm); + po::variables_map vm = build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } if (check_options > 0) { return check_options; } From 59b0988b148d9fb70ff0466ff83c8b20956623d1 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 18 Sep 2018 01:28:25 +0530 Subject: [PATCH 3/9] changed name of vector with unrecognised parms --- src/validator_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validator_main.cpp b/src/validator_main.cpp index d4f9ec445..f7b9c9783 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -62,9 +62,9 @@ namespace po::variables_map vm; po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); po::store(parsed,vm); - std::vector unused_args = collect_unrecognized(parsed.options, po::include_positional); + std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - for (auto a: unused_args) { + for (auto & a: unrecognised_parameters) { BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; } From 47433a08c06a11490af088e7c1f4a570b1da3d88 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 18 Sep 2018 01:39:18 +0530 Subject: [PATCH 4/9] sync all the tools --- src/assembly_checker_main.cpp | 20 +++++++++++++++++--- src/debugulator_main.cpp | 21 ++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/assembly_checker_main.cpp b/src/assembly_checker_main.cpp index 4b3204d52..6b1546f57 100644 --- a/src/assembly_checker_main.cpp +++ b/src/assembly_checker_main.cpp @@ -46,6 +46,21 @@ namespace return description; } + po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) + { + po::variables_map vm; + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); + + for (auto & a: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + } + + po::notify(vm); + return vm; + } + int check_command_line_options(po::variables_map const & vm, po::options_description const & desc) { if (vm.count(ebi::vcf::HELP)) { @@ -152,10 +167,9 @@ namespace int main(int argc, char** argv) { ebi::util::init_boost_loggers(); + po::options_description desc = build_command_line_options(); - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); + po::variables_map vm = build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } diff --git a/src/debugulator_main.cpp b/src/debugulator_main.cpp index 4cb8cf950..b8f95c961 100644 --- a/src/debugulator_main.cpp +++ b/src/debugulator_main.cpp @@ -53,6 +53,21 @@ namespace return description; } + po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) + { + po::variables_map vm; + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); + + for (auto & a: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + } + + po::notify(vm); + return vm; + } + int check_command_line_options(po::variables_map const &vm, po::options_description const &desc) { if (vm.count(ebi::vcf::HELP)) { @@ -86,12 +101,8 @@ int main(int argc, char **argv) { ebi::util::init_boost_loggers(); - namespace po = boost::program_options; - po::options_description desc = build_command_line_options(); - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); + po::variables_map vm = build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } From a80f6f4c2dbd09c61553b374eedff113020c7729 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 18 Sep 2018 01:43:25 +0530 Subject: [PATCH 5/9] sync indentation in debugulator main --- src/debugulator_main.cpp | 136 +++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/debugulator_main.cpp b/src/debugulator_main.cpp index b8f95c961..575489d24 100644 --- a/src/debugulator_main.cpp +++ b/src/debugulator_main.cpp @@ -27,74 +27,74 @@ namespace { - namespace po = boost::program_options; - - enum class ValidationLevel - { - error, warning, stop - }; - - const std::string version_info = "vcf-debugulator version " + std::to_string(VERSION_MAJOR) + "." - + std::to_string(VERSION_MINOR); - - po::options_description build_command_line_options() - { - po::options_description description(version_info + "\n\nUsage: vcf-debugulator [OPTIONS] [< input_file]\nAllowed options"); - - description.add_options() - (ebi::vcf::HELP_OPTION, "Display this help") - (ebi::vcf::VERSION_OPTION, "Display version of the debugulator") - (ebi::vcf::INPUT_OPTION, po::value()->default_value(ebi::vcf::STDIN), "Path to the input VCF file, or stdin") - (ebi::vcf::ERRORS_OPTION, po::value(), "Path to the errors report from the input VCF file") - (ebi::vcf::LEVEL_OPTION, po::value()->default_value(ebi::vcf::WARNING_LEVEL), "Validation level (error, warning, stop)") - (ebi::vcf::OUTPUT_OPTION, po::value()->default_value(ebi::vcf::STDOUT), "Write to a file or stdout") - ; - - return description; - } - - po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) - { - po::variables_map vm; - po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); - po::store(parsed,vm); - std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - - for (auto & a: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; - } - - po::notify(vm); - return vm; - } - - int check_command_line_options(po::variables_map const &vm, po::options_description const &desc) - { - if (vm.count(ebi::vcf::HELP)) { - std::cout << desc << std::endl; - return -1; - } - - if (vm.count(ebi::vcf::VERSION)) { - std::cout << version_info << std::endl; - return -1; - } - - std::string level = vm[ebi::vcf::LEVEL].as(); - if (level != ebi::vcf::ERROR_LEVEL && level != ebi::vcf::WARNING_LEVEL && level != ebi::vcf::STOP_LEVEL) { - std::cout << desc << std::endl; - BOOST_LOG_TRIVIAL(error) << "Please choose one of the accepted validation levels"; - return 1; - } - - if (!vm.count(ebi::vcf::ERRORS)) { - std::cout << desc << std::endl; - BOOST_LOG_TRIVIAL(error) << "Please specify the path to the errors report (--errors)"; - return 1; - } - - return 0; - } + namespace po = boost::program_options; + + enum class ValidationLevel + { + error, warning, stop + }; + + const std::string version_info = "vcf-debugulator version " + std::to_string(VERSION_MAJOR) + "." + + std::to_string(VERSION_MINOR); + + po::options_description build_command_line_options() + { + po::options_description description(version_info + "\n\nUsage: vcf-debugulator [OPTIONS] [< input_file]\nAllowed options"); + + description.add_options() + (ebi::vcf::HELP_OPTION, "Display this help") + (ebi::vcf::VERSION_OPTION, "Display version of the debugulator") + (ebi::vcf::INPUT_OPTION, po::value()->default_value(ebi::vcf::STDIN), "Path to the input VCF file, or stdin") + (ebi::vcf::ERRORS_OPTION, po::value(), "Path to the errors report from the input VCF file") + (ebi::vcf::LEVEL_OPTION, po::value()->default_value(ebi::vcf::WARNING_LEVEL), "Validation level (error, warning, stop)") + (ebi::vcf::OUTPUT_OPTION, po::value()->default_value(ebi::vcf::STDOUT), "Write to a file or stdout") + ; + + return description; + } + + po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) + { + po::variables_map vm; + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); + + for (auto & a: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + } + + po::notify(vm); + return vm; + } + + int check_command_line_options(po::variables_map const &vm, po::options_description const &desc) + { + if (vm.count(ebi::vcf::HELP)) { + std::cout << desc << std::endl; + return -1; + } + + if (vm.count(ebi::vcf::VERSION)) { + std::cout << version_info << std::endl; + return -1; + } + + std::string level = vm[ebi::vcf::LEVEL].as(); + if (level != ebi::vcf::ERROR_LEVEL && level != ebi::vcf::WARNING_LEVEL && level != ebi::vcf::STOP_LEVEL) { + std::cout << desc << std::endl; + BOOST_LOG_TRIVIAL(error) << "Please choose one of the accepted validation levels"; + return 1; + } + + if (!vm.count(ebi::vcf::ERRORS)) { + std::cout << desc << std::endl; + BOOST_LOG_TRIVIAL(error) << "Please specify the path to the errors report (--errors)"; + return 1; + } + + return 0; + } } int main(int argc, char **argv) From 8c11d3f972ae4908a02558d43f146ad87ec90913 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Thu, 20 Sep 2018 15:46:49 +0530 Subject: [PATCH 6/9] better names for loop variables --- src/assembly_checker_main.cpp | 4 ++-- src/debugulator_main.cpp | 4 ++-- src/validator_main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/assembly_checker_main.cpp b/src/assembly_checker_main.cpp index 6b1546f57..8c6238a89 100644 --- a/src/assembly_checker_main.cpp +++ b/src/assembly_checker_main.cpp @@ -53,8 +53,8 @@ namespace po::store(parsed,vm); std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - for (auto & a: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + for (auto & parameter: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; } po::notify(vm); diff --git a/src/debugulator_main.cpp b/src/debugulator_main.cpp index 575489d24..fbfa832e5 100644 --- a/src/debugulator_main.cpp +++ b/src/debugulator_main.cpp @@ -60,8 +60,8 @@ namespace po::store(parsed,vm); std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - for (auto & a: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + for (auto & parameter: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; } po::notify(vm); diff --git a/src/validator_main.cpp b/src/validator_main.cpp index f7b9c9783..50a7e8b81 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -64,8 +64,8 @@ namespace po::store(parsed,vm); std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - for (auto & a: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << a; + for (auto & parameter: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; } po::notify(vm); From abc1de7a3800434ec5e9d14c332eedc721fb2054 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 25 Sep 2018 18:41:55 +0530 Subject: [PATCH 7/9] extracted out cli functions in cli_utils.hpp --- inc/util/cli_utils.hpp | 51 +++++++++++++++++++++++++++++++++++ src/assembly_checker_main.cpp | 20 +++----------- src/debugulator_main.cpp | 20 +++----------- src/validator_main.cpp | 30 ++++++--------------- 4 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 inc/util/cli_utils.hpp diff --git a/inc/util/cli_utils.hpp b/inc/util/cli_utils.hpp new file mode 100644 index 000000000..8d72c0c7f --- /dev/null +++ b/inc/util/cli_utils.hpp @@ -0,0 +1,51 @@ +/** + * Copyright 2017 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTIL_CLI_UTILS_HPP +#define UTIL_CLI_UTILS_HPP + +#include +#include + +#include + +#include "util/logger.hpp" +#include "vcf/validator.hpp" + +namespace ebi +{ + namespace util + { + namespace po = boost::program_options; + + po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) + { + po::variables_map vm; + po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + po::store(parsed,vm); + std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); + + for (auto & parameter: unrecognised_parameters) { + BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; + } + + po::notify(vm); + return vm; + } + } +} + +#endif // UTIL_CLI_UTILS_HPP diff --git a/src/assembly_checker_main.cpp b/src/assembly_checker_main.cpp index 8c6238a89..ed5894222 100644 --- a/src/assembly_checker_main.cpp +++ b/src/assembly_checker_main.cpp @@ -18,10 +18,11 @@ #include #include "cmake_config.hpp" +#include "util/cli_utils.hpp" +#include "util/logger.hpp" #include "vcf/assembly_checker.hpp" #include "vcf/assembly_report_writer.hpp" #include "vcf/string_constants.hpp" -#include "util/logger.hpp" namespace { @@ -46,21 +47,6 @@ namespace return description; } - po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) - { - po::variables_map vm; - po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); - po::store(parsed,vm); - std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - - for (auto & parameter: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; - } - - po::notify(vm); - return vm; - } - int check_command_line_options(po::variables_map const & vm, po::options_description const & desc) { if (vm.count(ebi::vcf::HELP)) { @@ -169,7 +155,7 @@ int main(int argc, char** argv) ebi::util::init_boost_loggers(); po::options_description desc = build_command_line_options(); - po::variables_map vm = build_variables_map(argc, argv, desc); + po::variables_map vm = ebi::util::build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } diff --git a/src/debugulator_main.cpp b/src/debugulator_main.cpp index fbfa832e5..4e1824d14 100644 --- a/src/debugulator_main.cpp +++ b/src/debugulator_main.cpp @@ -20,10 +20,11 @@ #include #include "cmake_config.hpp" +#include "util/cli_utils.hpp" #include "util/logger.hpp" +#include "vcf/debugulator.hpp" #include "vcf/odb_report.hpp" #include "vcf/string_constants.hpp" -#include "vcf/debugulator.hpp" namespace { @@ -53,21 +54,6 @@ namespace return description; } - po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) - { - po::variables_map vm; - po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); - po::store(parsed,vm); - std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - - for (auto & parameter: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; - } - - po::notify(vm); - return vm; - } - int check_command_line_options(po::variables_map const &vm, po::options_description const &desc) { if (vm.count(ebi::vcf::HELP)) { @@ -102,7 +88,7 @@ int main(int argc, char **argv) ebi::util::init_boost_loggers(); po::options_description desc = build_command_line_options(); - po::variables_map vm = build_variables_map(argc, argv, desc); + po::variables_map vm = ebi::util::build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } diff --git a/src/validator_main.cpp b/src/validator_main.cpp index 50a7e8b81..0c65aaf20 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -14,25 +14,26 @@ * limitations under the License. */ -#include +#include #include +#include +#include #include +#include #include #include -#include -#include -#include #include #include #include "cmake_config.hpp" +#include "util/cli_utils.hpp" #include "util/logger.hpp" #include "vcf/file_structure.hpp" -#include "vcf/validator.hpp" -#include "vcf/report_writer.hpp" #include "vcf/odb_report.hpp" +#include "vcf/report_writer.hpp" #include "vcf/summary_report_writer.hpp" +#include "vcf/validator.hpp" namespace { @@ -57,21 +58,6 @@ namespace return description; } - po::variables_map build_variables_map(int argc, char** argv, const po::options_description & desc) - { - po::variables_map vm; - po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); - po::store(parsed,vm); - std::vector unrecognised_parameters = collect_unrecognized(parsed.options, po::include_positional); - - for (auto & parameter: unrecognised_parameters) { - BOOST_LOG_TRIVIAL(warning) << "unused parameter: " << parameter; - } - - po::notify(vm); - return vm; - } - int check_command_line_options(po::variables_map const & vm, po::options_description const & desc) { if (vm.count(ebi::vcf::HELP)) { @@ -175,7 +161,7 @@ int main(int argc, char** argv) ebi::util::init_boost_loggers(); po::options_description desc = build_command_line_options(); - po::variables_map vm = build_variables_map(argc, argv, desc); + po::variables_map vm = ebi::util::build_variables_map(argc, argv, desc); int check_options = check_command_line_options(vm, desc); if (check_options < 0) { return 0; } if (check_options > 0) { return check_options; } From e9887c9d36f7fd89ea704a109d9ff4838dc2d46e Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Tue, 25 Sep 2018 21:22:45 +0530 Subject: [PATCH 8/9] extracted out get_outdir function --- inc/util/cli_utils.hpp | 22 ++++++++++++++++++++++ src/assembly_checker_main.cpp | 22 +--------------------- src/validator_main.cpp | 22 +--------------------- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/inc/util/cli_utils.hpp b/inc/util/cli_utils.hpp index 8d72c0c7f..7e0671533 100644 --- a/inc/util/cli_utils.hpp +++ b/inc/util/cli_utils.hpp @@ -21,6 +21,7 @@ #include #include +#include #include "util/logger.hpp" #include "vcf/validator.hpp" @@ -45,6 +46,27 @@ namespace ebi po::notify(vm); return vm; } + + std::string get_output_path(const std::string &outdir, const std::string &file_path) + { + if (outdir == "") { + return file_path; + } + + boost::filesystem::path file_boost_path{file_path}; + boost::filesystem::path outdir_boost_path{outdir}; + if (!boost::filesystem::exists(outdir_boost_path)) { + throw std::invalid_argument{"Directory not found: " + outdir_boost_path.string()}; + } + if (!boost::filesystem::is_directory(outdir_boost_path)) { + throw std::invalid_argument{"outdir should be a directory, not a file: " + outdir_boost_path.string()}; + } + + outdir_boost_path /= file_boost_path.filename(); + + return outdir_boost_path.string(); + } + } } diff --git a/src/assembly_checker_main.cpp b/src/assembly_checker_main.cpp index ed5894222..02284244b 100644 --- a/src/assembly_checker_main.cpp +++ b/src/assembly_checker_main.cpp @@ -74,26 +74,6 @@ namespace return 0; } - std::string get_output_path(const std::string &outdir, const std::string &file_path) - { - if (outdir == "") { - return file_path; - } - - boost::filesystem::path file_boost_path{file_path}; - boost::filesystem::path outdir_boost_path{outdir}; - if (!boost::filesystem::exists(outdir_boost_path)) { - throw std::invalid_argument{"Directory not found: " + outdir_boost_path.string()}; - } - if (!boost::filesystem::is_directory(outdir_boost_path)) { - throw std::invalid_argument{"outdir should be a directory, not a file: " + outdir_boost_path.string()}; - } - - outdir_boost_path /= file_boost_path.filename(); - - return outdir_boost_path.string(); - } - std::vector> get_outputs(std::string const &output_str, std::string const &input) { @@ -165,7 +145,7 @@ int main(int argc, char** argv) auto vcf_path = vm[ebi::vcf::INPUT].as(); auto fasta_path = vm[ebi::vcf::FASTA].as(); auto fasta_index_path = fasta_path + ".fai"; - auto outdir = get_output_path(vm[ebi::vcf::OUTDIR].as(), vcf_path); + auto outdir = ebi::util::get_output_path(vm[ebi::vcf::OUTDIR].as(), vcf_path); auto outputs = get_outputs(vm[ebi::vcf::REPORT].as(), outdir); BOOST_LOG_TRIVIAL(info) << "Reading from input FASTA file..."; diff --git a/src/validator_main.cpp b/src/validator_main.cpp index 0c65aaf20..2136cbea7 100644 --- a/src/validator_main.cpp +++ b/src/validator_main.cpp @@ -93,26 +93,6 @@ namespace throw std::invalid_argument{"Please choose one of the accepted validation levels"}; } - std::string get_output_path(const std::string &outdir, const std::string &file_path) - { - if (outdir == "") { - return file_path; - } - - boost::filesystem::path file_boost_path{file_path}; - boost::filesystem::path outdir_boost_path{outdir}; - if (!boost::filesystem::exists(outdir_boost_path)) { - throw std::invalid_argument{"Directory not found: " + outdir_boost_path.string()}; - } - if (!boost::filesystem::is_directory(outdir_boost_path)) { - throw std::invalid_argument{"outdir should be a directory, not a file: " + outdir_boost_path.string()}; - } - - outdir_boost_path /= file_boost_path.filename(); - - return outdir_boost_path.string(); - } - std::vector> get_outputs(std::string const &output_str, std::string const &input) { std::vector outs; @@ -171,7 +151,7 @@ int main(int argc, char** argv) auto path = vm[ebi::vcf::INPUT].as(); auto level = vm[ebi::vcf::LEVEL].as(); ebi::vcf::ValidationLevel validationLevel = get_validation_level(level); - auto outdir = get_output_path(vm[ebi::vcf::OUTDIR].as(), path); + auto outdir = ebi::util::get_output_path(vm[ebi::vcf::OUTDIR].as(), path); auto outputs = get_outputs(vm[ebi::vcf::REPORT].as(), outdir); if (path == ebi::vcf::STDIN) { From 3c36b54e6131c494f15adadca2ee8c557af87dc8 Mon Sep 17 00:00:00 2001 From: Sarbjit Singh Date: Wed, 26 Sep 2018 15:05:04 +0530 Subject: [PATCH 9/9] removed vcf namespace from util util namespaces are to be independent from vcf namespaces --- inc/util/cli_utils.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/util/cli_utils.hpp b/inc/util/cli_utils.hpp index 7e0671533..5c4f03cc5 100644 --- a/inc/util/cli_utils.hpp +++ b/inc/util/cli_utils.hpp @@ -24,7 +24,6 @@ #include #include "util/logger.hpp" -#include "vcf/validator.hpp" namespace ebi {