|
1 | | -/* preseq: to predict properties of genomic sequencing libraries |
| 1 | +/* preseq: a tool for analyzing sequencing library complexity |
2 | 2 | * |
3 | | - * Copyright (C) 2013-2024 University of Southern California and |
| 3 | + * Copyright (C) 2013-2025 University of Southern California and |
4 | 4 | * Andrew D. Smith and Timothy Daley |
5 | 5 | * |
6 | | - * Authors: Timothy Daley, Chao Deng, Victoria Helus, and Andrew Smith |
| 6 | + * Author: Andrew D Smith |
7 | 7 | * |
8 | | - * This program is free software: you can redistribute it and/or |
9 | | - * modify it under the terms of the GNU General Public License as |
10 | | - * published by the Free Software Foundation, either version 3 of the |
11 | | - * License, or (at your option) any later version. |
| 8 | + * This program is free software: you can redistribute it and/or modify it |
| 9 | + * under the terms of the GNU General Public License as published by the Free |
| 10 | + * Software Foundation, either version 3 of the License, or (at your option) |
| 11 | + * any later version. |
12 | 12 | * |
13 | | - * This program is distributed in the hope that it will be useful, but |
14 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | - * General Public License for more details. |
| 13 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | + * more details. |
17 | 17 | * |
18 | | - * You should have received a copy of the GNU General Public License |
19 | | - * along with this program. If not, see |
20 | | - * <http://www.gnu.org/licenses/>. |
| 18 | + * You should have received a copy of the GNU General Public License along |
| 19 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 20 | */ |
22 | 21 |
|
23 | 22 | #include "bound_pop.hpp" |
24 | 23 | #include "c_curve.hpp" |
| 24 | +#include "common.hpp" |
25 | 25 | #include "gc_extrap.hpp" |
26 | 26 | #include "lc_extrap.hpp" |
27 | 27 | #include "pop_size.hpp" |
28 | 28 |
|
| 29 | +#include "CLI11/CLI11.hpp" |
| 30 | + |
29 | 31 | #include <config.h> |
30 | 32 |
|
31 | 33 | #include <cstdlib> |
32 | 34 | #include <iostream> |
33 | | -#include <sstream> |
| 35 | +#include <memory> |
34 | 36 | #include <string> |
35 | 37 |
|
36 | | -static std::string |
37 | | -usage_message() { |
38 | | - std::ostringstream oss; |
39 | | - oss << "preseq: a program for analyzing library complexity\n" |
40 | | - "Version: "; |
41 | | - oss << VERSION; |
42 | | - oss << "\n\n" |
43 | | - "Usage: preseq <command> [OPTIONS]\n\n" |
44 | | - "<command>: c_curve generate complexity curve for a library\n" |
45 | | - " lc_extrap predict the yield for future experiments\n" |
46 | | - " gc_extrap predict genome coverage low input\n" |
47 | | - " sequencing experiments\n" |
48 | | - " bound_pop lower bound on population size\n" |
49 | | - " pop_size estimate number of unique species\n"; |
50 | | - return oss.str(); |
51 | | -} |
52 | | - |
53 | 38 | int |
54 | | -main(int argc, char *argv[]) { |
| 39 | +main(int argc, char *argv[]) { // NOLINT(*-c-arrays) |
| 40 | + CLI::App app{"preseq: a tool for analyzing sequencing library complexity"}; |
| 41 | + argv = app.ensure_utf8(argv); |
| 42 | + app.formatter(std::make_shared<preseq_formatter>()); |
| 43 | + app.usage("\nUsage: preseq command [OPTIONS]"); |
| 44 | + // if (argc >= 3) |
| 45 | + // app.footer(rlstrip(footer_msg)); |
| 46 | + |
| 47 | + app.require_subcommand(0, 1); |
| 48 | + app.allow_extras(); |
| 49 | + |
| 50 | + bool print_version{}; |
| 51 | + |
| 52 | + // clang-format off |
| 53 | + app.add_flag("--version", print_version, "output version information and exit"); |
| 54 | + const auto lc_extrap = app.add_subcommand("lc_extrap", rlstrip(lc_extrap::about_msg)); |
| 55 | + const auto gc_extrap = app.add_subcommand("gc_extrap", rlstrip(gc_extrap::about_msg)); |
| 56 | + const auto pop_size = app.add_subcommand("pop_size", rlstrip(pop_size::about_msg)); |
| 57 | + const auto bound_pop = app.add_subcommand("bound_pop", rlstrip(bound_pop::about_msg)); |
| 58 | + const auto c_curve = app.add_subcommand("c_curve", rlstrip(c_curve::about_msg)); |
| 59 | + // clang-format on |
| 60 | + |
55 | 61 | if (argc < 2) { |
56 | | - std::cerr << usage_message() << '\n'; |
| 62 | + // std::println("{}", app.help()); |
| 63 | + std::cout << app.help() << '\n'; |
57 | 64 | return EXIT_SUCCESS; |
58 | 65 | } |
| 66 | + CLI11_PARSE(app, argc, argv); |
59 | 67 |
|
60 | | - static const std::string cmd = argv[1]; // NOLINT(*-pointer-arithmetic) |
61 | | - |
62 | | - if (cmd == "lc_extrap") |
63 | | - return lc_extrap_main(argc - 1, argv + 1); |
| 68 | + if (print_version) { |
| 69 | + std::cout << VERSION << '\n'; |
| 70 | + return EXIT_SUCCESS; |
| 71 | + } |
64 | 72 |
|
65 | | - if (cmd == "c_curve") |
66 | | - return c_curve_main(argc - 1, argv + 1); |
| 73 | + if (app.got_subcommand(lc_extrap)) |
| 74 | + return lc_extrap::main(argc - 1, argv + 1); |
67 | 75 |
|
68 | | - if (cmd == "gc_extrap") |
69 | | - return gc_extrap_main(argc - 1, argv + 1); |
| 76 | + if (app.got_subcommand(gc_extrap)) |
| 77 | + return gc_extrap::main(argc - 1, argv + 1); |
70 | 78 |
|
71 | | - if (cmd == "bound_pop") |
72 | | - return bound_pop_main(argc - 1, argv + 1); |
| 79 | + if (app.got_subcommand(c_curve)) |
| 80 | + return c_curve::main(argc - 1, argv + 1); |
73 | 81 |
|
74 | | - if (cmd == "pop_size") |
75 | | - return pop_size_main(argc - 1, argv + 1); |
| 82 | + if (app.got_subcommand(pop_size)) |
| 83 | + return pop_size::main(argc - 1, argv + 1); |
76 | 84 |
|
77 | | - std::cerr << "Error: unrecognized command: " |
78 | | - << argv[1] // NOLINT(*-pointer-arithmetic) |
79 | | - << '\n' |
80 | | - << usage_message() << '\n'; |
| 85 | + if (app.got_subcommand(bound_pop)) |
| 86 | + return bound_pop::main(argc - 1, argv + 1); |
81 | 87 |
|
82 | 88 | return EXIT_FAILURE; |
83 | 89 | } |
0 commit comments