diff --git a/lib/evolve_discrete_demes/evolvets.cc b/lib/evolve_discrete_demes/evolvets.cc index bca5d8df1..20fc1a8cf 100644 --- a/lib/evolve_discrete_demes/evolvets.cc +++ b/lib/evolve_discrete_demes/evolvets.cc @@ -451,6 +451,7 @@ evolve_with_tree_sequences( ++gen) { auto fixations_removed = false; + auto mutations_counted = false; if (demography.in_error_state()) { throw std::runtime_error("forward graph is in an error state"); @@ -519,8 +520,8 @@ evolve_with_tree_sequences( next_index = pop.tables->num_nodes(); if (options.track_mutation_counts_during_sim) { - track_mutation_counts(pop, simplified, - options.suppress_edge_table_indexing); + mutations_counted = track_mutation_counts( + pop, simplified, options.suppress_edge_table_indexing); } // The user may now analyze the pop'n and record ancient samples @@ -581,66 +582,62 @@ evolve_with_tree_sequences( pop.mcounts_from_preserved_nodes); } } - else - { - genetics.mutation_recycling_bin = fwdpp::ts::make_mut_queue( - simplification_output.preserved_mutations, - pop.mutations.size()); - } + //else + // { + // genetics.mutation_recycling_bin = fwdpp::ts::make_mut_queue( + // simplification_output.preserved_mutations, + // pop.mutations.size()); + // } } - else + if (options.preserve_selected_fixations == false) { - if (options.preserve_selected_fixations == false) + if (options.track_mutation_counts_during_sim == true) { - if (options.track_mutation_counts_during_sim == true) + if (fixations_removed == false) { - if (fixations_removed == false) + if (mutations_counted == false) { - auto itr = std::remove_if( - pop.tables->mutations.begin(), - pop.tables->mutations.end(), - [&pop](const fwdpp::ts::mutation_record - &mr) { - return pop.mcounts[mr.key] - == 2 * pop.diploids.size() - && pop.mcounts_from_preserved_nodes - [mr.key] - == 0; - }); - auto d = std::distance( - itr, end(pop.tables->mutations)); - pop.tables->mutations.erase( - itr, end(pop.tables->mutations)); - if (d) - { - fwdpp::ts::rebuild_site_table( - *pop.tables); - } - fwdpp::ts:: - remove_fixations_from_haploid_genomes( - pop.haploid_genomes, pop.mutations, - pop.mcounts, - pop.mcounts_from_preserved_nodes, - 2 * pop.diploids.size(), - options.preserve_selected_fixations); - fixations_removed = true; - // NOTE: this is hacky and should be better-handled upstream - for (std::size_t i = 0; - i < pop.mcounts.size(); ++i) + throw std::runtime_error( + "mutations not counted"); + } + auto itr = std::remove_if( + pop.tables->mutations.begin(), + pop.tables->mutations.end(), + [&pop](const fwdpp::ts::mutation_record &mr) { + return pop.mcounts[mr.key] + == 2 * pop.diploids.size() + && pop.mcounts_from_preserved_nodes + [mr.key] + == 0; + }); + auto d + = std::distance(itr, end(pop.tables->mutations)); + pop.tables->mutations.erase( + itr, end(pop.tables->mutations)); + if (d) + { + fwdpp::ts::rebuild_site_table(*pop.tables); + } + fwdpp::ts::remove_fixations_from_haploid_genomes( + pop.haploid_genomes, pop.mutations, pop.mcounts, + pop.mcounts_from_preserved_nodes, + 2 * pop.diploids.size(), + options.preserve_selected_fixations); + fixations_removed = true; + // NOTE: this is hacky and should be better-handled upstream + for (std::size_t i = 0; i < pop.mcounts.size(); ++i) + { + if (pop.mcounts[i] == 2 * pop.N + && pop.mcounts_from_preserved_nodes[i] + == 0) { - if (pop.mcounts[i] == 2 * pop.N - && pop.mcounts_from_preserved_nodes - [i] - == 0) - { - pop.mcounts[i] = 0; - } + pop.mcounts[i] = 0; } - genetics.mutation_recycling_bin - = fwdpp::ts::make_mut_queue( - pop.mcounts, - pop.mcounts_from_preserved_nodes); } + genetics.mutation_recycling_bin + = fwdpp::ts::make_mut_queue( + pop.mcounts, + pop.mcounts_from_preserved_nodes); } } }