Skip to content

Commit

Permalink
Removing the unused srand with pid and time because it was never used…
Browse files Browse the repository at this point in the history
… in initializing the mt19937 which was generating randoms
  • Loading branch information
andrewdavidsmith committed Oct 20, 2024
1 parent 402a67f commit d35eaf4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 54 deletions.
10 changes: 4 additions & 6 deletions src/bound_pop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

#include <OptionParser.hpp>

#include <unistd.h>

#include <algorithm>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <random>
#include <random> // std::mt19937
#include <stdexcept>
#include <string>
#include <vector>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -323,7 +322,6 @@ counts of observed species in an initial sample.
vector<double> quad_estimates;

// setup rng
srand(time(0) + getpid());
mt19937 rng(seed);

// hist may be sparse, to speed up bootstrapping
Expand Down
22 changes: 5 additions & 17 deletions src/c_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,27 @@
#include <smithlab_os.hpp>
#include <smithlab_utils.hpp>

#include <sys/types.h>
#include <unistd.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <cstddef> // std::size_t
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <random>
#include <string>
#include <vector>

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 <typename T>
Expand All @@ -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;
Expand Down Expand Up @@ -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<double> counts_hist;
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 9 additions & 8 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -110,7 +112,7 @@ interpolate_distinct(const vector<double> &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
Expand All @@ -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;
Expand Down Expand Up @@ -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<double> &orig_hist,
const uint32_t seed, const vector<double> &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,
Expand All @@ -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<size_t> orig_hist_distinct_counts;
vector<double> distinct_orig_hist;
Expand All @@ -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(
Expand Down Expand Up @@ -364,7 +365,7 @@ resample_hist(mt19937 &gen, const vector<size_t> &vals_hist_distinct_counts,
vector<uint32_t> 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);

Expand Down
2 changes: 1 addition & 1 deletion src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> &orig_hist,
const std::uint32_t seed, const std::vector<double> &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,
Expand Down
6 changes: 5 additions & 1 deletion src/gc_extrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <OptionParser.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/lc_extrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#include "lc_extrap.hpp"

#include "common.hpp"

#include "load_data_for_complexity.hpp"

#include "OptionParser.hpp"
#include <OptionParser.hpp>

#include <algorithm>
#include <cstddef>
#include <cstddef> // std::size_t
#include <cstdint>
#include <filesystem>
#include <fstream>
Expand All @@ -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
Expand All @@ -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;
Expand Down
24 changes: 9 additions & 15 deletions src/load_data_for_complexity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@

#include "load_data_for_complexity.hpp"

#include "GenomicRegion.hpp"
#include "MappedRead.hpp"
#include <GenomicRegion.hpp>
#include <MappedRead.hpp>

#ifdef HAVE_HTSLIB
#include "bam_record_utils.hpp" // from dnmtools
#include <bamxx.hpp> // from bamxx
#include <htslib_wrapper.hpp>
#endif // HAVE_HTSLIB

#include <unistd.h>

#include <algorithm> // std::min
#include <cstddef>
#include <cstdint>
#include <algorithm> // std::min
#include <cstddef> // std::size_t
#include <cstdint> // std::uint32_t
#include <functional> // std::greater
#include <iostream>
#include <queue>
Expand All @@ -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;

Expand Down Expand Up @@ -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<double> &coverage_hist) {
srand(time(0) + getpid());
// Runif runif(rand());
std::mt19937 generator(seed);

std::ifstream in(input_file_name);
Expand Down Expand Up @@ -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<double> &coverage_hist) {
srand(time(0) + getpid());
std::mt19937 generator(seed);

std::ifstream in(input_file_name);
Expand Down Expand Up @@ -724,10 +719,9 @@ update_coverage_hist(const T &curr, const T &prev, vector<double> &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<double> &coverage_hist) {
srand(time(0) + getpid());
std::mt19937 generator(seed);

bamxx::bam_tpool tp(n_threads);
Expand Down
5 changes: 4 additions & 1 deletion src/pop_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <OptionParser.hpp>

#include <algorithm>
#include <cstddef> // std::size_t
#include <cstdint>
#include <filesystem>
#include <fstream>
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit d35eaf4

Please sign in to comment.