Skip to content

Commit

Permalink
all tests pass but I worry that this is fragile somehow
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Jul 18, 2024
1 parent 7b49f48 commit 685d91b
Showing 1 changed file with 51 additions and 54 deletions.
105 changes: 51 additions & 54 deletions lib/evolve_discrete_demes/evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 685d91b

Please sign in to comment.