Skip to content

Commit afedffa

Browse files
src all command sources: using the main function in each case from the namespace and also the about and help footer messages
1 parent f901dc1 commit afedffa

5 files changed

Lines changed: 33 additions & 79 deletions

File tree

src/bound_pop.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
* <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
const auto about_msg = R"(
22-
preseq bound_pop: Estimate the size of the underlying population based on
23-
counts of observed species in an initial sample.
24-
)";
25-
2621
#include "bound_pop.hpp"
2722

2823
#include "common.hpp"
@@ -81,22 +76,22 @@ report_bootstrapped_moments(const std::vector<double> &bootstrap_moments,
8176
}
8277

8378
// bounding n_0
84-
int
85-
bound_pop_main(int argc, char *argv[]) { // NOLINT (*-avoid-c-arrays)
79+
auto
80+
bound_pop::main(int argc, char *argv[]) -> int { // NOLINT (*-avoid-c-arrays)
8681
try {
87-
bool verbose = false;
88-
bool PAIRED_END = false;
89-
bool HIST_INPUT = false;
90-
bool VALS_INPUT = false;
91-
bool QUICK_MODE = false;
82+
bool verbose{false};
83+
bool PAIRED_END{false};
84+
bool HIST_INPUT{false};
85+
bool VALS_INPUT{false};
86+
bool QUICK_MODE{false};
9287

9388
std::string input_file_name;
9489
std::string outfile;
9590
std::string histogram_outfile;
9691

9792
#ifdef HAVE_HTSLIB
98-
bool BAM_FORMAT_INPUT = false;
99-
std::size_t MAX_SEGMENT_LENGTH = 5000;
93+
bool BAM_FORMAT_INPUT{false};
94+
std::size_t MAX_SEGMENT_LENGTH{5000};
10095
std::uint32_t n_threads{1};
10196
#endif
10297

@@ -128,17 +123,17 @@ bound_pop_main(int argc, char *argv[]) { // NOLINT (*-avoid-c-arrays)
128123
app.add_option("-c,--clevel", c_level, "level for confidence intervals");
129124
app.add_flag("-P,--pe", PAIRED_END, "input is paired end read file");
130125
app.add_flag("-H,--hist", HIST_INPUT,
131-
"input is a text file containing the observed histogram");
126+
"input is a text file containing the observed histogram");
132127
app.add_flag("-V,--vals", VALS_INPUT,
133-
"input is a text file containing only the observed duplicate counts");
128+
"input is a text file containing only the observed duplicate counts");
134129
#ifdef HAVE_HTSLIB
135130
app.add_flag("-B,--bam", BAM_FORMAT_INPUT,
136-
"input is in BAM format");
131+
"input is in BAM format");
137132
app.add_option("-l,--seg_len", MAX_SEGMENT_LENGTH,
138133
"maximum segment length when merging paired end bam reads");
139134
#endif
140135
app.add_flag("-Q,--quick", QUICK_MODE,
141-
"quick mode, estimate without bootstrapping");
136+
"quick mode, estimate without bootstrapping");
142137
app.add_option("-r,--seed", seed, "seed for random number generator");
143138
app.add_flag("-v,--verbose", verbose, "print more info");
144139
// clang-format on
@@ -193,7 +188,7 @@ bound_pop_main(int argc, char *argv[]) { // NOLINT (*-avoid-c-arrays)
193188
std::size_t idx = 1;
194189
while (idx < std::size(counts_hist) && counts_hist[idx]) {
195190
// idx + 1 because function calculates (x-1)!
196-
measure_moments.push_back(std::exp(factorial(idx + 1) +
191+
measure_moments.push_back(std::exp(log_factorial(idx + 1) +
197192
std::log(counts_hist[idx]) -
198193
std::log(counts_hist[1])));
199194
if (!std::isfinite(measure_moments.back())) {
@@ -324,7 +319,7 @@ bound_pop_main(int argc, char *argv[]) { // NOLINT (*-avoid-c-arrays)
324319
std::vector<double> bootstrap_moments(1, 1.0);
325320
// moments[r] = (r + 1)! n_{r+1} / n_1
326321
for (std::size_t i = 0; i < 2 * max_num_points; i++)
327-
bootstrap_moments.push_back(std::exp(factorial(i + 3) +
322+
bootstrap_moments.push_back(std::exp(log_factorial(i + 3) +
328323
std::log(sample_hist[i + 2]) -
329324
std::log(sample_hist[1])));
330325

src/c_curve.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
* with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
static constexpr auto about_msg = R"(
21-
Generate the full observed complexity curve for data. This does not
22-
extrapolate, but instead resamples from the given data.
23-
)";
24-
2520
#include "c_curve.hpp"
2621

2722
#include "common.hpp"
@@ -42,8 +37,8 @@ extrapolate, but instead resamples from the given data.
4237

4338
// NOLINTBEGIN(*-avoid-magic-numbers,*-narrowing-conversions)
4439

45-
int
46-
c_curve_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
40+
auto
41+
c_curve::main(int argc, char *argv[]) -> int { // NOLINT(*-avoid-c-arrays)
4742
try {
4843
bool verbose = false;
4944
bool PAIRED_END = false;

src/gc_extrap.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
* <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
static constexpr auto about_msg = R"(
22-
preseq gc_extrap: Extrapolate the size of the covered genome by mapped reads.
23-
)";
24-
25-
static constexpr auto footer_msg = R"(
26-
This approach is described in Daley & Smith (2014). The method is the same as
27-
for lc_extrap: using rational function approximation to a power-series
28-
expansion for the number of "unobserved" bases in the initial sample. The
29-
gc_extrap method is adapted to deal with individual nucleotides rather than
30-
distinct reads.
31-
)";
32-
3321
#include "gc_extrap.hpp"
3422

3523
#include "common.hpp"
@@ -87,8 +75,8 @@ write_predicted_coverage_curve(
8775
}
8876
}
8977

90-
int
91-
gc_extrap_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
78+
auto
79+
gc_extrap::main(int argc, char *argv[]) -> int { // NOLINT(*-avoid-c-arrays)
9280
try {
9381
static constexpr auto MIN_REQUIRED_COUNTS = 4;
9482

src/lc_extrap.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
* <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
constexpr auto about_msg = R"(
22-
preseq lc_extrap: Estimate the complexity curve for a sequencing library.
23-
)";
24-
25-
constexpr auto footer_msg = R"(
26-
This is the approach described in Daley & Smith (2013). The method applies
27-
rational function approximation via continued fractions with the original goal
28-
of estimating the number of distinct reads that a sequencing library would
29-
yield upon deeper sequencing. This method has been used for many different
30-
purposes since then.
31-
)";
32-
3321
#include "lc_extrap.hpp"
3422

3523
#include "common.hpp"
@@ -52,8 +40,8 @@ purposes since then.
5240

5341
// NOLINTBEGIN(*-avoid-magic-numbers,*-narrowing-conversions)
5442

55-
int
56-
lc_extrap_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
43+
auto
44+
lc_extrap::main(int argc, char *argv[]) -> int { // NOLINT(*-avoid-c-arrays)
5745
try {
5846
static const std::size_t min_required_counts = 4;
5947
static const std::string min_required_counts_error_message =
@@ -72,16 +60,16 @@ lc_extrap_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
7260
double c_level = 0.95;
7361
std::uint32_t seed = 408;
7462

75-
/* FLAGS */
76-
bool verbose = false;
77-
bool VALS_INPUT = false;
78-
bool PAIRED_END = false;
79-
bool HIST_INPUT = false;
80-
bool SINGLE_ESTIMATE = false;
81-
bool allow_defects = false;
63+
// flags
64+
bool verbose{false};
65+
bool VALS_INPUT{false};
66+
bool PAIRED_END{false};
67+
bool HIST_INPUT{false};
68+
bool SINGLE_ESTIMATE{false};
69+
bool allow_defects{false};
8270

8371
#ifdef HAVE_HTSLIB
84-
bool BAM_FORMAT_INPUT = false;
72+
bool BAM_FORMAT_INPUT{false};
8573
std::size_t MAX_SEGMENT_LENGTH = 5000;
8674
std::uint32_t n_threads{1};
8775
#endif

src/pop_size.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
* <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
static constexpr auto about_msg = R"(
22-
preseq pop_size: Estimate the total population size using a small sample from
23-
the population.
24-
)";
25-
26-
static constexpr auto footer_msg = R"(
27-
Estimate the total population size using the approach described in Daley &
28-
Smith (2013), extrapolating to very long range. Default parameters assume that
29-
the initial sample represents at least 1e-9 of the population, which is
30-
sufficient for every example application we have seen.
31-
)";
32-
3321
#include "pop_size.hpp"
3422
#include "common.hpp"
3523
#include "load_data_for_complexity.hpp"
@@ -60,8 +48,8 @@ using std::vector;
6048

6149
// NOLINTBEGIN(*-avoid-magic-numbers,*-narrowing-conversions)
6250

63-
int
64-
pop_size_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
51+
auto
52+
pop_size::main(int argc, char *argv[]) -> int { // NOLINT(*-avoid-c-arrays)
6553
try {
6654
static const std::size_t min_required_counts = 4;
6755
static const string min_required_counts_error_message =
@@ -94,11 +82,11 @@ pop_size_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
9482
std::size_t MAX_SEGMENT_LENGTH = 5000;
9583
uint32_t n_threads{1};
9684
#endif
97-
CLI::App app{rlstrip(about_msg)};
85+
CLI::App app{rlstrip(pop_size::about_msg)};
9886
argv = app.ensure_utf8(argv);
9987
app.usage("\nUsage: preseq pop_size [OPTIONS]");
10088
if (argc >= 2)
101-
app.footer(rlstrip(footer_msg));
89+
app.footer(rlstrip(pop_size::footer_msg));
10290

10391
// clang-format off
10492
app.add_option("-i,--input", input_file_name, "input file")

0 commit comments

Comments
 (0)