Skip to content

Commit ef37269

Browse files
src/load_data_for_complexity.hcpp and all main sources: returning tuples for the hists read from input files along with number of observations (reads)
1 parent 42789b1 commit ef37269

File tree

7 files changed

+226
-233
lines changed

7 files changed

+226
-233
lines changed

src/bound_pop.cpp

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -150,42 +150,40 @@ bound_pop_main(int argc, char *argv[]) { // NOLINT (*-avoid-c-arrays)
150150
}
151151
CLI11_PARSE(app, argc, argv);
152152

153-
std::vector<double> counts_hist;
154-
std::size_t n_obs = 0;
155-
156-
// LOAD VALUES
157-
if (HIST_INPUT) {
158-
if (verbose)
159-
std::cerr << "HIST_INPUT\n";
160-
n_obs = load_histogram(input_file_name, counts_hist);
161-
}
162-
else if (VALS_INPUT) {
163-
if (verbose)
164-
std::cerr << "VALS_INPUT\n";
165-
n_obs = load_counts(input_file_name, counts_hist);
166-
}
153+
const auto [n_obs, counts_hist] = [&] {
154+
if (HIST_INPUT) {
155+
if (verbose)
156+
std::cerr << "HIST_INPUT\n";
157+
return load_histogram(input_file_name);
158+
}
159+
else if (VALS_INPUT) {
160+
if (verbose)
161+
std::cerr << "VALS_INPUT\n";
162+
return load_counts(input_file_name);
163+
}
167164
#ifdef HAVE_HTSLIB
168-
else if (BAM_FORMAT_INPUT && PAIRED_END) {
169-
if (verbose)
170-
std::cerr << "PAIRED_END_BAM_INPUT\n";
171-
n_obs = load_counts_BAM_pe(n_threads, input_file_name, counts_hist);
172-
}
173-
else if (BAM_FORMAT_INPUT) {
174-
if (verbose)
175-
std::cerr << "BAM_INPUT\n";
176-
n_obs = load_counts_BAM_se(n_threads, input_file_name, counts_hist);
177-
}
165+
else if (BAM_FORMAT_INPUT && PAIRED_END) {
166+
if (verbose)
167+
std::cerr << "PAIRED_END_BAM_INPUT\n";
168+
return load_counts_BAM_pe(n_threads, input_file_name);
169+
}
170+
else if (BAM_FORMAT_INPUT) {
171+
if (verbose)
172+
std::cerr << "BAM_INPUT\n";
173+
return load_counts_BAM_se(n_threads, input_file_name);
174+
}
178175
#endif
179-
else if (PAIRED_END) {
180-
if (verbose)
181-
std::cerr << "PAIRED_END_BED_INPUT\n";
182-
n_obs = load_counts_bed_pe(input_file_name, counts_hist);
183-
}
184-
else { // default is single end bed file
185-
if (verbose)
186-
std::cerr << "BED_INPUT\n";
187-
n_obs = load_counts_bed_se(input_file_name, counts_hist);
188-
}
176+
else if (PAIRED_END) {
177+
if (verbose)
178+
std::cerr << "PAIRED_END_BED_INPUT\n";
179+
return load_counts_bed_pe(input_file_name);
180+
}
181+
else { // default is single end bed file
182+
if (verbose)
183+
std::cerr << "BED_INPUT\n";
184+
return load_counts_bed_se(input_file_name);
185+
}
186+
}();
189187

190188
const double distinct_obs =
191189
std::accumulate(std::cbegin(counts_hist), std::cend(counts_hist), 0.0);

src/c_curve.cpp

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,42 +95,40 @@ c_curve_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
9595
}
9696
CLI11_PARSE(app, argc, argv);
9797

98-
std::vector<double> counts_hist;
99-
std::size_t n_reads = 0;
100-
101-
// LOAD VALUES
102-
if (HIST_INPUT) {
103-
if (verbose)
104-
std::cerr << "INPUT_HIST\n";
105-
n_reads = load_histogram(input_file_name, counts_hist);
106-
}
107-
else if (VALS_INPUT) {
108-
if (verbose)
109-
std::cerr << "VALS_INPUT\n";
110-
n_reads = load_counts(input_file_name, counts_hist);
111-
}
98+
const auto [n_reads, counts_hist] = [&] {
99+
if (HIST_INPUT) {
100+
if (verbose)
101+
std::cerr << "INPUT_HIST\n";
102+
return load_histogram(input_file_name);
103+
}
104+
else if (VALS_INPUT) {
105+
if (verbose)
106+
std::cerr << "VALS_INPUT\n";
107+
return load_counts(input_file_name);
108+
}
112109
#ifdef HAVE_HTSLIB
113-
else if (BAM_FORMAT_INPUT && PAIRED_END) {
114-
if (verbose)
115-
std::cerr << "PAIRED_END_BAM_INPUT\n";
116-
n_reads = load_counts_BAM_pe(n_threads, input_file_name, counts_hist);
117-
}
118-
else if (BAM_FORMAT_INPUT) {
119-
if (verbose)
120-
std::cerr << "BAM_INPUT\n";
121-
n_reads = load_counts_BAM_se(n_threads, input_file_name, counts_hist);
122-
}
110+
else if (BAM_FORMAT_INPUT && PAIRED_END) {
111+
if (verbose)
112+
std::cerr << "PAIRED_END_BAM_INPUT\n";
113+
return load_counts_BAM_pe(n_threads, input_file_name);
114+
}
115+
else if (BAM_FORMAT_INPUT) {
116+
if (verbose)
117+
std::cerr << "BAM_INPUT\n";
118+
return load_counts_BAM_se(n_threads, input_file_name);
119+
}
123120
#endif
124-
else if (PAIRED_END) {
125-
if (verbose)
126-
std::cerr << "PAIRED_END_BED_INPUT\n";
127-
n_reads = load_counts_bed_pe(input_file_name, counts_hist);
128-
}
129-
else { // default is single end bed file
130-
if (verbose)
131-
std::cerr << "BED_INPUT\n";
132-
n_reads = load_counts_bed_se(input_file_name, counts_hist);
133-
}
121+
else if (PAIRED_END) {
122+
if (verbose)
123+
std::cerr << "PAIRED_END_BED_INPUT\n";
124+
return load_counts_bed_pe(input_file_name);
125+
}
126+
else { // default is single end bed file
127+
if (verbose)
128+
std::cerr << "BED_INPUT\n";
129+
return load_counts_bed_se(input_file_name);
130+
}
131+
}();
134132

135133
const auto max_observed_count = std::size(counts_hist) - 1;
136134
const auto distinct_reads =

src/gc_extrap.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,14 @@ gc_extrap_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
158158
if (verbose)
159159
std::cerr << "LOADING READS (" << input_format << " format)\n";
160160

161-
std::vector<double> coverage_hist;
162-
const auto n_reads = [&] {
161+
const auto [n_reads, coverage_hist] = [&] {
163162
#ifdef HAVE_HTSLIB
164163
if (BAM_FORMAT_INPUT)
165164
return load_coverage_counts_BAM(n_threads, infile, seed, bin_size,
166-
max_width, coverage_hist);
165+
max_width);
167166
else
168167
#endif
169-
return load_coverage_counts(infile, seed, bin_size, max_width,
170-
coverage_hist);
168+
return load_coverage_counts(infile, seed, bin_size, max_width);
171169
}();
172170

173171
const auto total_bins = get_counts_from_hist(coverage_hist);

src/lc_extrap.cpp

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,42 @@ lc_extrap_main(int argc, char *argv[]) { // NOLINT(*-avoid-c-arrays)
130130
}
131131
CLI11_PARSE(app, argc, argv);
132132

133-
std::vector<double> counts_hist;
134-
std::size_t n_reads = 0;
135-
136-
/************ loading input ***************************************/
137-
if (HIST_INPUT) {
138-
if (verbose)
139-
std::cerr << "HIST_INPUT\n";
140-
n_reads = load_histogram(input_file_name, counts_hist);
141-
}
142-
else if (VALS_INPUT) {
143-
if (verbose)
144-
std::cerr << "VALS_INPUT\n";
145-
n_reads = load_counts(input_file_name, counts_hist);
146-
}
147-
#ifdef HAVE_HTSLIB
148-
else if (BAM_FORMAT_INPUT) {
149-
if (PAIRED_END) {
133+
const auto [n_reads, counts_hist] = [&] {
134+
if (HIST_INPUT) {
150135
if (verbose)
151-
std::cerr << "PAIRED_END_BAM_INPUT\n";
152-
n_reads = load_counts_BAM_pe(n_threads, input_file_name, counts_hist);
136+
std::cerr << "HIST_INPUT\n";
137+
return load_histogram(input_file_name);
153138
}
154-
else { // single end
139+
else if (VALS_INPUT) {
155140
if (verbose)
156-
std::cerr << "BAM_INPUT\n";
157-
n_reads = load_counts_BAM_se(n_threads, input_file_name, counts_hist);
141+
std::cerr << "VALS_INPUT\n";
142+
return load_counts(input_file_name);
143+
}
144+
#ifdef HAVE_HTSLIB
145+
else if (BAM_FORMAT_INPUT) {
146+
if (PAIRED_END) {
147+
if (verbose)
148+
std::cerr << "PAIRED_END_BAM_INPUT\n";
149+
return load_counts_BAM_pe(n_threads, input_file_name);
150+
}
151+
else { // single end
152+
if (verbose)
153+
std::cerr << "BAM_INPUT\n";
154+
return load_counts_BAM_se(n_threads, input_file_name);
155+
}
158156
}
159-
}
160157
#endif
161-
else if (PAIRED_END) {
162-
if (verbose)
163-
std::cerr << "PAIRED_END_BED_INPUT\n";
164-
n_reads = load_counts_bed_pe(input_file_name, counts_hist);
165-
}
166-
else { // default is single end bed file
167-
if (verbose)
168-
std::cerr << "BED_INPUT\n";
169-
n_reads = load_counts_bed_se(input_file_name, counts_hist);
170-
}
171-
/************ done loading input **********************************/
158+
else if (PAIRED_END) {
159+
if (verbose)
160+
std::cerr << "PAIRED_END_BED_INPUT\n";
161+
return load_counts_bed_pe(input_file_name);
162+
}
163+
else { // default is single end bed file
164+
if (verbose)
165+
std::cerr << "BED_INPUT\n";
166+
return load_counts_bed_se(input_file_name);
167+
}
168+
}();
172169

173170
const std::size_t max_observed_count = std::size(counts_hist) - 1;
174171
const double distinct_reads =

0 commit comments

Comments
 (0)