diff --git a/src/bound_pop.cpp b/src/bound_pop.cpp index b0f6caa..0eaf0c5 100644 --- a/src/bound_pop.cpp +++ b/src/bound_pop.cpp @@ -26,13 +26,12 @@ #include -#include - #include +#include #include #include #include -#include +#include // std::mt19937 #include #include #include @@ -43,8 +42,8 @@ using std::isfinite; using std::min; using std::mt19937; using std::runtime_error; -using std::setprecision; using std::string; +using std::uint32_t; using std::vector; static void @@ -104,7 +103,7 @@ bound_pop_main(const int argc, const char *argv[]) { size_t n_bootstraps = 500; double c_level = 0.95; size_t max_iter = 100; - uint64_t seed = 408; + uint32_t seed = 408; const string description = R"( Estimate a bound on the size of the underlying population based on @@ -323,7 +322,6 @@ counts of observed species in an initial sample. vector quad_estimates; // setup rng - srand(time(0) + getpid()); mt19937 rng(seed); // hist may be sparse, to speed up bootstrapping diff --git a/src/c_curve.cpp b/src/c_curve.cpp index 9676a5b..271c204 100644 --- a/src/c_curve.cpp +++ b/src/c_curve.cpp @@ -29,17 +29,11 @@ #include #include -#include -#include - #include -#include -#include -#include +#include // std::size_t #include #include #include -#include #include #include #include @@ -47,20 +41,15 @@ #include using std::accumulate; -using std::array; using std::cbegin; using std::cend; using std::cerr; using std::endl; -using std::isfinite; -using std::max; -using std::min; using std::mt19937; -using std::runtime_error; -using std::setprecision; using std::size; +using std::size_t; using std::string; -using std::uint64_t; +using std::uint32_t; using std::vector; template @@ -83,7 +72,7 @@ c_curve_main(const int argc, const char *argv[]) { bool PAIRED_END = false; bool HIST_INPUT = false; bool VALS_INPUT = false; - uint64_t seed = 408; + uint32_t seed = 408; string outfile; string histogram_outfile; @@ -158,7 +147,6 @@ instead resamples from the given data. /******************************************************************/ // Setup the random number generator - srand(time(0) + getpid()); // random seed mt19937 rng(seed); vector counts_hist; @@ -198,7 +186,7 @@ instead resamples from the given data. n_reads = load_counts_BED_se(input_file_name, counts_hist); } - const size_t max_observed_count = counts_hist.size() - 1; + const size_t max_observed_count = size(counts_hist) - 1; const double distinct_reads = accumulate(cbegin(counts_hist), cend(counts_hist), 0.0); diff --git a/src/common.cpp b/src/common.cpp index 063e2eb..a0d1448 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -38,6 +38,8 @@ using std::array; using std::begin; +using std::cbegin; +using std::cend; using std::cerr; using std::end; using std::endl; @@ -46,7 +48,7 @@ using std::mt19937; using std::runtime_error; using std::size_t; using std::string; -using std::uint64_t; +using std::uint32_t; using std::vector; double @@ -110,7 +112,7 @@ interpolate_distinct(const vector &hist, const size_t N, const size_t S, numer[i] = exp(x - denom) * hist[i]; } } - return S - accumulate(begin(numer), end(numer), 0); + return S - accumulate(cbegin(numer), cend(numer), 0); } static void @@ -136,7 +138,7 @@ extrap_single_estimate(const bool VERBOSE, const bool allow_defects, yield_estimate.clear(); const double vals_sum = get_counts_from_hist(hist); - const double initial_distinct = accumulate(begin(hist), end(hist), 0.0); + const double initial_distinct = accumulate(cbegin(hist), cend(hist), 0.0); // interpolate complexity curve by random sampling w/out replacement const size_t upper_limit = vals_sum; @@ -197,7 +199,7 @@ extrap_single_estimate(const bool VERBOSE, const bool allow_defects, void extrap_bootstrap(const bool VERBOSE, const bool allow_defects, - const uint64_t seed, const vector &orig_hist, + const uint32_t seed, const vector &orig_hist, const size_t n_bootstraps, const size_t orig_max_terms, const int diagonal, const double bin_step_size, const double max_extrap, const size_t max_iter, @@ -206,11 +208,10 @@ extrap_bootstrap(const bool VERBOSE, const bool allow_defects, bootstrap_estimates.clear(); // setup rng - srand(time(0) + getpid()); mt19937 rng(seed); const double initial_distinct = - std::accumulate(begin(orig_hist), end(orig_hist), 0.0); + std::accumulate(cbegin(orig_hist), cend(orig_hist), 0.0); vector orig_hist_distinct_counts; vector distinct_orig_hist; @@ -236,7 +237,7 @@ extrap_bootstrap(const bool VERBOSE, const bool allow_defects, hist.pop_back(); // compute complexity curve by random sampling w/out replacement - const size_t distinct = accumulate(begin(hist), end(hist), 0.0); + const size_t distinct = accumulate(cbegin(hist), cend(hist), 0.0); size_t curr_sample_sz = bin_step_size; while (curr_sample_sz < sample_vals_sum) { yield_vector.push_back( @@ -364,7 +365,7 @@ resample_hist(mt19937 &gen, const vector &vals_hist_distinct_counts, vector sample_distinct_counts_hist(hist_size, 0); const uint32_t distinct = - accumulate(begin(distinct_counts_hist), end(distinct_counts_hist), 0.0); + accumulate(cbegin(distinct_counts_hist), cend(distinct_counts_hist), 0.0); multinomial(gen, distinct_counts_hist, distinct, sample_distinct_counts_hist); diff --git a/src/common.hpp b/src/common.hpp index 357c84c..0ab08b8 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -46,7 +46,7 @@ extrap_single_estimate(const bool VERBOSE, const bool allow_defects, void extrap_bootstrap(const bool VERBOSE, const bool allow_defects, - const std::uint64_t seed, const std::vector &orig_hist, + const std::uint32_t seed, const std::vector &orig_hist, const std::size_t n_bootstraps, const std::size_t orig_max_terms, const int diagonal, const double bin_step_size, const double max_extrap, diff --git a/src/gc_extrap.cpp b/src/gc_extrap.cpp index 0c5b16e..ee0942c 100644 --- a/src/gc_extrap.cpp +++ b/src/gc_extrap.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -39,7 +41,9 @@ using std::cerr; using std::endl; using std::min; using std::runtime_error; +using std::size_t; using std::string; +using std::uint32_t; using std::vector; // ADS: functions same, header different (above and this one) @@ -92,7 +96,7 @@ gc_extrap_main(const int argc, const char *argv[]) { bool SINGLE_ESTIMATE = false; double max_extrap = 1.0e12; size_t n_bootstraps = 100; - uint64_t seed = 408; + uint32_t seed = 408; bool allow_defects = false; bool NO_SEQUENCE = false; diff --git a/src/lc_extrap.cpp b/src/lc_extrap.cpp index dfcaa5f..120a1b9 100644 --- a/src/lc_extrap.cpp +++ b/src/lc_extrap.cpp @@ -21,13 +21,12 @@ #include "lc_extrap.hpp" #include "common.hpp" - #include "load_data_for_complexity.hpp" -#include "OptionParser.hpp" +#include #include -#include +#include // std::size_t #include #include #include @@ -48,7 +47,6 @@ using std::size_t; using std::string; using std::to_string; using std::uint32_t; -using std::uint64_t; using std::vector; int @@ -68,7 +66,7 @@ lc_extrap_main(const int argc, const char **argv) { size_t n_bootstraps = 100; int diagonal = 0; double c_level = 0.95; - uint64_t seed = 408; + uint32_t seed = 408; /* FLAGS */ bool verbose = false; diff --git a/src/load_data_for_complexity.cpp b/src/load_data_for_complexity.cpp index 79c17cf..02ee34f 100644 --- a/src/load_data_for_complexity.cpp +++ b/src/load_data_for_complexity.cpp @@ -20,8 +20,8 @@ #include "load_data_for_complexity.hpp" -#include "GenomicRegion.hpp" -#include "MappedRead.hpp" +#include +#include #ifdef HAVE_HTSLIB #include "bam_record_utils.hpp" // from dnmtools @@ -29,11 +29,9 @@ #include #endif // HAVE_HTSLIB -#include - -#include // std::min -#include -#include +#include // std::min +#include // std::size_t +#include // std::uint32_t #include // std::greater #include #include @@ -51,7 +49,7 @@ using std::runtime_error; using std::size; using std::size_t; using std::string; -using std::uint64_t; +using std::uint32_t; using std::unordered_map; using std::vector; @@ -413,11 +411,9 @@ SplitMappedRead(const MappedRead &inputMR, mt19937 &generator, } size_t -load_coverage_counts_MR(const string &input_file_name, const uint64_t seed, +load_coverage_counts_MR(const string &input_file_name, const uint32_t seed, const size_t bin_size, const size_t max_width, vector &coverage_hist) { - srand(time(0) + getpid()); - // Runif runif(rand()); std::mt19937 generator(seed); std::ifstream in(input_file_name); @@ -465,10 +461,9 @@ load_coverage_counts_MR(const string &input_file_name, const uint64_t seed, } size_t -load_coverage_counts_GR(const string &input_file_name, const uint64_t seed, +load_coverage_counts_GR(const string &input_file_name, const uint32_t seed, const size_t bin_size, const size_t max_width, vector &coverage_hist) { - srand(time(0) + getpid()); std::mt19937 generator(seed); std::ifstream in(input_file_name); @@ -724,10 +719,9 @@ update_coverage_hist(const T &curr, const T &prev, vector &counts_hist, // first mate for each mapped read size_t load_coverage_counts_BAM(const uint32_t n_threads, const string &inputfile, - const uint64_t seed, const size_t bin_size, + const uint32_t seed, const size_t bin_size, const size_t max_width, vector &coverage_hist) { - srand(time(0) + getpid()); std::mt19937 generator(seed); bamxx::bam_tpool tp(n_threads); diff --git a/src/pop_size.cpp b/src/pop_size.cpp index 0677be5..e5ca1df 100644 --- a/src/pop_size.cpp +++ b/src/pop_size.cpp @@ -26,6 +26,7 @@ #include #include +#include // std::size_t #include #include #include @@ -41,8 +42,10 @@ using std::count_if; using std::endl; using std::min; using std::runtime_error; +using std::size_t; using std::string; using std::to_string; +using std::uint32_t; using std::vector; int @@ -63,7 +66,7 @@ pop_size_main(const int argc, const char *argv[]) { size_t n_bootstraps = 100; int diagonal = 0; double c_level = 0.95; - uint64_t seed = 408; + uint32_t seed = 408; /* FLAGS */ bool verbose = false;