Skip to content

Commit

Permalink
Deprecate ts::table_index_t and ts::NULL_INDEX. (#347)
Browse files Browse the repository at this point in the history
Class types/constants are now preferred.
  • Loading branch information
molpopgen authored Jul 6, 2021
1 parent b524997 commit 52e84fe
Show file tree
Hide file tree
Showing 46 changed files with 1,097 additions and 886 deletions.
39 changes: 23 additions & 16 deletions examples/edge_buffering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ generate_main_options(command_line_options& o)
struct parent
{
std::size_t index;
fwdpp::ts::table_index_t node0, node1;
parent(std::size_t i, fwdpp::ts::table_index_t n0, fwdpp::ts::table_index_t n1)
fwdpp::ts::table_collection::id_type node0, node1;
parent(std::size_t i, fwdpp::ts::table_collection::id_type n0,
fwdpp::ts::table_collection::id_type n1)
: index(i), node0(n0), node1(n1)
{
}
Expand All @@ -119,7 +120,7 @@ struct parent
struct birth
{
std::size_t index;
fwdpp::ts::table_index_t p0node0, p0node1, p1node0, p1node1;
fwdpp::ts::table_collection::id_type p0node0, p0node1, p1node0, p1node1;
birth(std::size_t i, const parent& p0, const parent& p1)
: index(i), p0node0(p0.node0), p0node1(p0.node1), p1node0(p1.node0),
p1node1(p1.node1)
Expand Down Expand Up @@ -166,10 +167,11 @@ recombination_breakpoints(const fwdpp::GSLrng_mt& rng, double littler, double ma
void
generate_births(const fwdpp::GSLrng_mt& rng, const std::vector<birth>& births,
double littler, std::vector<double>& breakpoints, double birth_time,
bool buffer_new_edges, fwdpp::ts::edge_buffer& new_edges,
bool buffer_new_edges,
fwdpp::ts::edge_buffer<fwdpp::ts::table_collection::id_type>& new_edges,
std::vector<parent>& parents, fwdpp::ts::table_collection& tables)
{
fwdpp::ts::table_index_t new_node_0, new_node_1;
fwdpp::ts::table_collection::id_type new_node_0, new_node_1;
for (auto& b : births)
{
auto p0n0 = b.p0node0;
Expand Down Expand Up @@ -226,9 +228,10 @@ generate_births(const fwdpp::GSLrng_mt& rng, const std::vector<birth>& births,

template <typename SimplificationState>
void
sort_n_simplify(const std::vector<fwdpp::ts::table_index_t>& samples,
sort_n_simplify(const std::vector<fwdpp::ts::table_collection::id_type>& samples,
SimplificationState& state, fwdpp::ts::table_collection& tables,
fwdpp::ts::simplify_tables_output& simplification_output)
fwdpp::ts::simplify_tables_output<fwdpp::ts::table_collection::id_type>&
simplification_output)
{
auto cmp = fwdpp::ts::get_edge_sort_cmp(tables);
std::sort(begin(tables.edges), end(tables.edges), cmp);
Expand All @@ -239,11 +242,14 @@ sort_n_simplify(const std::vector<fwdpp::ts::table_index_t>& samples,
template <typename SimplificationState>
void
flush_buffer_n_simplify(
bool simplify_from_buffer, const std::vector<fwdpp::ts::table_index_t>& samples,
const std::vector<fwdpp::ts::table_index_t>& alive_at_last_simplification,
fwdpp::ts::simplify_tables_output& simplification_output,
fwdpp::ts::edge_buffer& new_edges, SimplificationState& state,
fwdpp::ts::table_collection::edge_table& edge_liftover,
bool simplify_from_buffer,
const std::vector<fwdpp::ts::table_collection::id_type>& samples,
const std::vector<fwdpp::ts::table_collection::id_type>&
alive_at_last_simplification,
fwdpp::ts::simplify_tables_output<fwdpp::ts::table_collection::id_type>&
simplification_output,
fwdpp::ts::edge_buffer<fwdpp::ts::table_collection::id_type>& new_edges,
SimplificationState& state, fwdpp::ts::table_collection::edge_table& edge_liftover,
fwdpp::ts::table_collection& tables)
{
double max_time = -1; //-1;//std::numeric_limits<double>::max();
Expand Down Expand Up @@ -345,7 +351,7 @@ simulate(const command_line_options& options)
{
fwdpp::GSLrng_mt rng(options.seed);
fwdpp::ts::table_collection tables(1.0);
fwdpp::ts::edge_buffer buffer;
fwdpp::ts::edge_buffer<fwdpp::ts::table_collection::id_type> buffer;
fwdpp::ts::table_collection::edge_table edge_liftover;
auto simplifier_state = fwdpp::ts::make_simplifier_state(tables);
std::vector<parent> parents;
Expand All @@ -357,13 +363,14 @@ simulate(const command_line_options& options)
}

// The next bits are all for buffering
std::vector<fwdpp::ts::table_index_t> alive_at_last_simplification(
std::vector<fwdpp::ts::table_collection::id_type> alive_at_last_simplification(
tables.num_nodes());
std::iota(begin(alive_at_last_simplification), end(alive_at_last_simplification), 0);

std::vector<birth> births;
std::vector<fwdpp::ts::table_index_t> samples;
fwdpp::ts::simplify_tables_output simplification_output;
std::vector<fwdpp::ts::table_collection::id_type> samples;
fwdpp::ts::simplify_tables_output<fwdpp::ts::table_collection::id_type>
simplification_output;
bool simplified = false;
double littler = options.rho / (4. * static_cast<double>(options.N));
std::vector<double> breakpoints;
Expand Down
15 changes: 10 additions & 5 deletions examples/simplify_tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#include "fwdpp/ts/exceptions.hpp"

template <typename Simplifier, typename poptype>
std::pair<std::vector<fwdpp::ts::table_index_t>, std::vector<std::size_t>>
std::pair<std::vector<fwdpp::ts::table_collection::id_type>, std::vector<std::size_t>>
simplify_tables(poptype &pop, const fwdpp::uint_t generation,
std::vector<fwdpp::uint_t> &mcounts_from_preserved_nodes,
fwdpp::ts::table_collection &tables, Simplifier &simplifier,
const fwdpp::ts::table_index_t first_sample_node,
const fwdpp::ts::table_collection::id_type first_sample_node,
const std::size_t num_samples,
std::vector<fwdpp::ts::table_index_t> &preserved_nodes,
std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes,
const bool preserve_fixations = false)
{
fwdpp::ts::sort_tables_for_simplification(tables.edge_offset, tables);
Expand Down Expand Up @@ -62,11 +62,16 @@ simplify_tables(poptype &pop, const fwdpp::uint_t generation,
fwdpp::ts::remove_fixations_from_haploid_genomes(
pop.haploid_genomes, pop.mutations, pop.mcounts,
mcounts_from_preserved_nodes,
2 * static_cast<fwdpp::ts::table_index_t>(pop.diploids.size()), false);
2
* static_cast<fwdpp::ts::table_collection::id_type>(
pop.diploids.size()),
false);

fwdpp::ts::flag_mutations_for_recycling(
pop, mcounts_from_preserved_nodes,
2 * static_cast<fwdpp::ts::table_index_t>(pop.diploids.size()),
2
* static_cast<fwdpp::ts::table_collection::id_type>(
pop.diploids.size()),
generation, std::false_type(), std::false_type());
confirm_mutation_counts(pop, tables);
}
Expand Down
83 changes: 43 additions & 40 deletions examples/tree_sequence_examples_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply_neutral_mutations_details(const options &o, const GSLrng &rng,
fwdpp::ts::table_collection &tables, poptype &pop,
fwdpp::flagged_mutation_queue &mutation_recycling_bin)
{
std::vector<fwdpp::ts::table_index_t> s(2 * o.N);
std::vector<fwdpp::ts::table_collection::id_type> s(2 * o.N);

std::iota(s.begin(), s.end(), 0);
const auto neutral_variant_maker
Expand All @@ -43,8 +43,7 @@ apply_neutral_mutations_details(const options &o, const GSLrng &rng,

int
apply_neutral_mutations(const options &o, const GSLrng &rng,
fwdpp::ts::table_collection &tables,
ts_examples_poptype &pop,
fwdpp::ts::table_collection &tables, ts_examples_poptype &pop,
fwdpp::flagged_mutation_queue &mutation_recycling_bin)
{
return apply_neutral_mutations_details(o, rng, tables, pop, mutation_recycling_bin);
Expand Down Expand Up @@ -160,7 +159,7 @@ make_dfe(const fwdpp::uint_t N, const GSLrng &r, const double mean, const double

void
matrix_runtime_test(const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::uint_t> &mcounts)
{
auto dm = fwdpp::ts::generate_data_matrix(tables, samples, true, true, false);
Expand All @@ -183,7 +182,7 @@ matrix_runtime_test(const fwdpp::ts::table_collection &tables,

void
expensive_leaf_test(const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &sample_list)
const std::vector<fwdpp::ts::table_collection::id_type> &sample_list)
{
fwdpp::ts::tree_visitor<fwdpp::ts::table_collection> mti(
tables, sample_list, fwdpp::ts::update_samples_list(true));
Expand Down Expand Up @@ -235,8 +234,7 @@ test_serialization(const fwdpp::ts::table_collection &tables,
fwdpp::ts::io::serialize_tables(o, tables);
o.close();
std::ifstream i(filename.c_str());
auto tables2
= fwdpp::ts::io::deserialize_tables<fwdpp::ts::table_collection>()(i);
auto tables2 = fwdpp::ts::io::deserialize_tables<fwdpp::ts::table_collection>()(i);

if (tables.genome_length() != tables2.genome_length())
{
Expand Down Expand Up @@ -273,10 +271,10 @@ test_serialization(const fwdpp::ts::table_collection &tables,
}

void
execute_expensive_leaf_test(const options &o,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes)
execute_expensive_leaf_test(
const options &o, const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes)
{
if (o.leaf_test)
{
Expand All @@ -291,10 +289,10 @@ execute_expensive_leaf_test(const options &o,

template <typename poptype>
void
execute_matrix_test_detail(const options &o, const poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes)
execute_matrix_test_detail(
const options &o, const poptype &pop, const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes)
{
if (o.matrix_test)
{
Expand Down Expand Up @@ -346,13 +344,13 @@ execute_matrix_test_detail(const options &o, const poptype &pop,
std::cout << "Matrix test with respect to most recent "
"ancient sampling time point...";
sc.clear();
std::copy_if(
preserved_nodes.begin(), preserved_nodes.end(),
std::back_inserter(sc),
[&tables, &preserved_nodes](const fwdpp::ts::table_index_t n) {
return tables.nodes[n].time
== tables.nodes[preserved_nodes.back()].time;
});
std::copy_if(preserved_nodes.begin(), preserved_nodes.end(),
std::back_inserter(sc),
[&tables, &preserved_nodes](
const fwdpp::ts::table_collection::id_type n) {
return tables.nodes[n].time
== tables.nodes[preserved_nodes.back()].time;
});
mc.clear();
fwdpp::ts::count_mutations(tables, pop.mutations, sc, mc);
matrix_runtime_test(tables, sc, mc);
Expand All @@ -362,10 +360,11 @@ execute_matrix_test_detail(const options &o, const poptype &pop,
}

void
visit_sites_test(const options &o, const ts_examples_poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes)
visit_sites_test(
const options &o, const ts_examples_poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes)
{
if (o.visit_sites_test)
{
Expand All @@ -377,9 +376,14 @@ visit_sites_test(const options &o, const ts_examples_poptype &pop,
auto mc2(mc);
std::fill(begin(mc2), end(mc2), 0);
auto f =
[&mc2](const fwdpp::ts::marginal_tree &m, const fwdpp::ts::site & /*s*/,
std::vector<fwdpp::ts::mutation_record>::const_iterator b,
const std::vector<fwdpp::ts::mutation_record>::const_iterator e) {
[&mc2](
const fwdpp::ts::marginal_tree<fwdpp::ts::table_collection::id_type>
&m,
const fwdpp::ts::site & /*s*/,
std::vector<
fwdpp::ts::table_collection::mutation_record>::const_iterator b,
const std::vector<fwdpp::ts::table_collection::mutation_record>::
const_iterator e) {
for (; b < e; ++b)
{
mc2[b->key] = fwdpp::ts::num_samples(m, b->node);
Expand All @@ -395,17 +399,17 @@ visit_sites_test(const options &o, const ts_examples_poptype &pop,
}
}
void
execute_matrix_test(const options &o, const ts_examples_poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes)
execute_matrix_test(
const options &o, const ts_examples_poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes)
{
execute_matrix_test_detail(o, pop, tables, samples, preserved_nodes);
}

void
execute_serialization_test(const options &o,
const fwdpp::ts::table_collection &tables)
execute_serialization_test(const options &o, const fwdpp::ts::table_collection &tables)
{
if (!o.filename.empty())
{
Expand All @@ -414,9 +418,8 @@ execute_serialization_test(const options &o,
}

void
write_sfs(const options &o, const GSLrng &rng,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples)
write_sfs(const options &o, const GSLrng &rng, const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_collection::id_type> &samples)
{
if (!o.sfsfilename.empty())
{
Expand All @@ -427,10 +430,10 @@ write_sfs(const options &o, const GSLrng &rng,
"> 2");
}
// Simplify w.r.to 100 samples
std::vector<fwdpp::ts::table_index_t> small_sample(o.nsam);
std::vector<fwdpp::ts::table_collection::id_type> small_sample(o.nsam);
auto s(samples);
gsl_ran_choose(rng.get(), small_sample.data(), small_sample.size(), s.data(),
s.size(), sizeof(fwdpp::ts::table_index_t));
s.size(), sizeof(fwdpp::ts::table_collection::id_type));
std::iota(small_sample.begin(), small_sample.end(), 0);
auto dm = fwdpp::ts::generate_data_matrix(tables, small_sample, true, false,
true);
Expand Down
14 changes: 7 additions & 7 deletions examples/tree_sequence_examples_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ std::function<double()> make_dfe(const fwdpp::uint_t N, const GSLrng &r,

void execute_matrix_test(const options &, const ts_examples_poptype &,
const fwdpp::ts::table_collection &,
const std::vector<fwdpp::ts::table_index_t> &,
const std::vector<fwdpp::ts::table_index_t> &);
const std::vector<fwdpp::ts::table_collection::id_type> &,
const std::vector<fwdpp::ts::table_collection::id_type> &);

void execute_expensive_leaf_test(
const options &o, const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes);
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes);

void execute_serialization_test(const options &,
const fwdpp::ts::table_collection &);
Expand All @@ -52,11 +52,11 @@ void test_serialization(const fwdpp::ts::table_collection &tables,

void visit_sites_test(const options &o, const ts_examples_poptype &pop,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples,
const std::vector<fwdpp::ts::table_index_t> &preserved_nodes);
const std::vector<fwdpp::ts::table_collection::id_type> &samples,
const std::vector<fwdpp::ts::table_collection::id_type> &preserved_nodes);

void write_sfs(const options &o, const GSLrng &rng,
const fwdpp::ts::table_collection &tables,
const std::vector<fwdpp::ts::table_index_t> &samples);
const std::vector<fwdpp::ts::table_collection::id_type> &samples);

#endif
6 changes: 4 additions & 2 deletions examples/tree_sequence_examples_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fwdpp/diploid_population.hpp>
#include <fwdpp/GSLrng_t.hpp>
#include <fwdpp/types/mutation.hpp>
#include <fwdpp/ts/table_collection.hpp>

using ts_examples_poptype = fwdpp::diploid_population<fwdpp::mutation>;
using GSLrng = fwdpp::GSLrng_mt;
Expand All @@ -13,9 +14,10 @@ struct diploid_metadata
{
std::size_t individual;
double time, fitness;
fwdpp::ts::table_index_t n1, n2;
fwdpp::ts::table_collection::id_type n1, n2;
diploid_metadata(std::size_t i, double t, double w,
fwdpp::ts::table_index_t a, fwdpp::ts::table_index_t b)
fwdpp::ts::table_collection::id_type a,
fwdpp::ts::table_collection::id_type b)
: individual(i), time(t), fitness(w), n1(a), n2(b)
{
}
Expand Down
Loading

0 comments on commit 52e84fe

Please sign in to comment.