Skip to content

Commit 402a67f

Browse files
only writing histograms to files and this is separate from verbose
1 parent afd38e7 commit 402a67f

File tree

6 files changed

+25
-33
lines changed

6 files changed

+25
-33
lines changed

src/bound_pop.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ using std::setprecision;
4747
using std::string;
4848
using std::vector;
4949

50-
namespace fs = std::filesystem;
51-
5250
static void
5351
report_bootstrapped_moments(const vector<double> &bootstrap_moments,
5452
const MomentSequence &bootstrap_mom_seq,
@@ -112,7 +110,7 @@ bound_pop_main(const int argc, const char *argv[]) {
112110
Estimate a bound on the size of the underlying population based on
113111
counts of observed species in an initial sample.
114112
)";
115-
string program_name = fs::path(argv[0]).filename();
113+
string program_name = std::filesystem::path(argv[0]).filename();
116114
program_name += " " + string(argv[1]);
117115

118116
/********** GET COMMAND LINE ARGUMENTS FOR BOUND_POP ***********/
@@ -239,13 +237,14 @@ counts of observed species in an initial sample.
239237
<< "DISTINCT OBSERVATIONS = " << distinct_obs << endl
240238
<< "MAX COUNT = " << counts_hist.size() - 1 << endl;
241239

242-
report_histogram(histogram_outfile, counts_hist);
243-
244240
cerr << "OBSERVED MOMENTS" << endl;
245241
for (size_t i = 0; i < measure_moments.size(); i++)
246242
cerr << std::setprecision(16) << measure_moments[i] << endl;
247243
}
248244

245+
if (!histogram_outfile.empty())
246+
report_histogram(histogram_outfile, counts_hist);
247+
249248
if (QUICK_MODE) {
250249
if (measure_moments.size() < 2 * max_num_points)
251250
max_num_points = static_cast<size_t>(floor(measure_moments.size() / 2));

src/c_curve.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
#include <string>
4747
#include <vector>
4848

49-
namespace fs = std::filesystem;
50-
5149
using std::accumulate;
5250
using std::array;
5351
using std::cbegin;
@@ -102,7 +100,7 @@ c_curve_main(const int argc, const char *argv[]) {
102100
Generate the complexity curve for data. This does not extrapolate, but
103101
instead resamples from the given data.
104102
)";
105-
string program_name = fs::path(argv[0]).filename();
103+
string program_name = std::filesystem::path(argv[0]).filename();
106104
program_name += " " + string(argv[1]);
107105

108106
/********** GET COMMAND LINE ARGUMENTS FOR C_CURVE ***********/
@@ -210,15 +208,17 @@ instead resamples from the given data.
210208
std::count_if(cbegin(counts_hist), cend(counts_hist),
211209
[](const double x) { return x > 0.0; });
212210

213-
if (verbose) {
211+
if (verbose)
214212
cerr << "TOTAL READS = " << n_reads << endl
215213
<< "COUNTS_SUM = " << total_reads << endl
216214
<< "DISTINCT READS = " << distinct_reads << endl
217215
<< "DISTINCT COUNTS = " << distinct_counts << endl
218216
<< "MAX COUNT = " << max_observed_count << endl
219217
<< "COUNTS OF 1 = " << counts_hist[1] << endl;
218+
219+
if (!histogram_outfile.empty())
220220
report_histogram(histogram_outfile, counts_hist);
221-
}
221+
222222
const size_t upper_limit = n_reads; // set upper limit equal to number of
223223
// molecules
224224

src/common.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <cstddef> // std::size_t
2525
#include <cstdint> // std::uint64_t
2626
#include <fstream>
27-
#include <iostream>
2827
#include <ostream>
2928
#include <random>
3029
#include <stdexcept>
@@ -119,15 +118,12 @@ multinomial(std::mt19937 &gen, const std::vector<double> &mult_probs,
119118
template <typename H>
120119
void
121120
report_histogram(const std::string &outfile, const H &h) {
122-
std::ofstream of;
123-
if (!outfile.empty())
124-
of.open(outfile);
125-
std::ostream o(outfile.empty() ? std::cerr.rdbuf() : of.rdbuf());
126-
o << "OBSERVED COUNTS (" << std::size(h) << ")" << std::endl;
121+
std::ofstream out(outfile);
122+
if (!out)
123+
throw std::runtime_error("failed to open output file: " + outfile);
127124
for (auto i = 0u; i < std::size(h); ++i)
128125
if (h[i] > 0)
129-
o << i << '\t' << static_cast<std::uint32_t>(h[i]) << std::endl;
130-
o << std::endl;
126+
out << i << '\t' << static_cast<std::uint32_t>(h[i]) << '\n';
131127
}
132128

133129
#endif // SRC_COMMON_HPP_

src/gc_extrap.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ using std::runtime_error;
4242
using std::string;
4343
using std::vector;
4444

45-
namespace fs = std::filesystem;
46-
4745
// ADS: functions same, header different (above and this one)
4846
static void
4947
write_predicted_coverage_curve(const string &outfile, const double c_level,
@@ -112,7 +110,7 @@ power-series expansion for the number of "unobserved" bases in the
112110
initial sample. The gc_extrap method is adapted to deal with
113111
individual nucleotides rather than distinct reads.
114112
)";
115-
string program_name = fs::path(argv[0]).filename();
113+
string program_name = std::filesystem::path(argv[0]).filename();
116114
program_name += " " + string(argv[1]);
117115

118116
// ********* GET COMMAND LINE ARGUMENTS FOR GC EXTRAP **********
@@ -219,7 +217,7 @@ individual nucleotides rather than distinct reads.
219217

220218
orig_max_terms = min(orig_max_terms, first_zero - 1);
221219

222-
if (verbose) {
220+
if (verbose)
223221
cerr << "TOTAL READS = " << n_reads << endl
224222
<< "BASE STEP SIZE = " << base_step_size << endl
225223
<< "BIN STEP SIZE = " << bin_step_size << endl
@@ -230,8 +228,9 @@ individual nucleotides rather than distinct reads.
230228
<< "TOTAL COVERED BASES = " << distinct_bins * bin_size << endl
231229
<< "MAX COVERAGE COUNT = " << max_observed_count << endl
232230
<< "COUNTS OF 1 = " << coverage_hist[1] << endl;
231+
232+
if (!histogram_outfile.empty())
233233
report_histogram(histogram_outfile, coverage_hist);
234-
}
235234

236235
// catch if all reads are distinct
237236
if (orig_max_terms < MIN_REQUIRED_COUNTS)

src/lc_extrap.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ using std::uint32_t;
5151
using std::uint64_t;
5252
using std::vector;
5353

54-
namespace fs = std::filesystem;
55-
5654
int
5755
lc_extrap_main(const int argc, const char **argv) {
5856
try {
@@ -95,7 +93,7 @@ original goal of estimating the number of distinct reads that a
9593
sequencing library would yield upon deeper sequencing. This
9694
method has been used for many different purposes since then.
9795
)";
98-
string program_name = fs::path(argv[0]).filename();
96+
string program_name = std::filesystem::path(argv[0]).filename();
9997
program_name += " " + string(argv[1]);
10098

10199
/********** GET COMMAND LINE ARGUMENTS FOR LC EXTRAP ***********/
@@ -217,15 +215,16 @@ method has been used for many different purposes since then.
217215
std::count_if(cbegin(counts_hist), cend(counts_hist),
218216
[](const double x) { return x > 0.0; });
219217

220-
if (verbose) {
218+
if (verbose)
221219
cerr << "TOTAL READS = " << n_reads << endl
222220
<< "DISTINCT READS = " << distinct_reads << endl
223221
<< "DISTINCT COUNTS = " << distinct_counts << endl
224222
<< "MAX COUNT = " << max_observed_count << endl
225223
<< "COUNTS OF 1 = " << counts_hist[1] << endl
226224
<< "MAX TERMS = " << orig_max_terms << endl;
225+
226+
if (!histogram_outfile.empty())
227227
report_histogram(histogram_outfile, counts_hist);
228-
}
229228

230229
// check to make sure library is not overly saturated
231230
const double two_fold_extrap = GoodToulmin2xExtrap(counts_hist);

src/pop_size.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ using std::string;
4545
using std::to_string;
4646
using std::vector;
4747

48-
namespace fs = std::filesystem;
49-
5048
int
5149
pop_size_main(const int argc, const char *argv[]) {
5250
try {
@@ -88,7 +86,7 @@ parameters assume that the initial sample represents at least 1e-9 of
8886
the population, which is sufficient for every example application we
8987
have seen.
9088
)";
91-
string program_name = fs::path(argv[0]).filename();
89+
string program_name = std::filesystem::path(argv[0]).filename();
9290
program_name += " " + string(argv[1]);
9391

9492
/********** GET COMMAND LINE ARGUMENTS FOR LC EXTRAP ***********/
@@ -213,15 +211,16 @@ have seen.
213211
std::count_if(begin(counts_hist), end(counts_hist),
214212
[](const double x) { return x > 0.0; });
215213

216-
if (verbose) {
214+
if (verbose)
217215
cerr << "TOTAL READS = " << n_reads << endl
218216
<< "DISTINCT READS = " << distinct_reads << endl
219217
<< "DISTINCT COUNTS = " << distinct_counts << endl
220218
<< "MAX COUNT = " << max_observed_count << endl
221219
<< "COUNTS OF 1 = " << counts_hist[1] << endl
222220
<< "MAX TERMS = " << orig_max_terms << endl;
221+
222+
if (!histogram_outfile.empty())
223223
report_histogram(histogram_outfile, counts_hist);
224-
}
225224

226225
// check to make sure library is not overly saturated
227226
const double two_fold_extrap = GoodToulmin2xExtrap(counts_hist);

0 commit comments

Comments
 (0)