Skip to content

Commit c063d4a

Browse files
src/common.hpp: adding the report_histogram to the common sources
1 parent 197c9e5 commit c063d4a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ write_predicted_complexity_curve(const string &outfile, const double c_level,
334334
const vector<double> &yield_upper_ci_lognorm) {
335335
std::ofstream of;
336336
if (!outfile.empty())
337-
of.open(outfile.c_str());
337+
of.open(outfile);
338338
std::ostream out(outfile.empty() ? std::cout.rdbuf() : of.rdbuf());
339339

340340
out << "TOTAL_READS\tEXPECTED_DISTINCT\t"

src/common.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include <cstddef> // std::size_t
2525
#include <cstdint> // std::uint64_t
26+
#include <fstream>
27+
#include <iostream>
28+
#include <ostream>
2629
#include <random>
2730
#include <stdexcept>
2831
#include <string>
@@ -113,4 +116,18 @@ multinomial(std::mt19937 &gen, const std::vector<double> &mult_probs,
113116
throw std::runtime_error("multinomial sampling failed");
114117
}
115118

119+
template <typename H>
120+
void
121+
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;
127+
for (auto i = 0u; i < std::size(h); ++i)
128+
if (h[i] > 0)
129+
o << i << '\t' << static_cast<std::uint32_t>(h[i]) << std::endl;
130+
o << std::endl;
131+
}
132+
116133
#endif // SRC_COMMON_HPP_

0 commit comments

Comments
 (0)