Skip to content

Commit

Permalink
When indexing/counting mutations at the end of a simulation, use
Browse files Browse the repository at this point in the history
tables to count if neutral variants are present.
  • Loading branch information
molpopgen committed Jan 24, 2021
1 parent a7abc47 commit 6281d12
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions fwdpy11/src/evolve_population/index_and_count_mutations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,58 @@
#include <fwdpy11/types/DiploidPopulation.hpp>
#include <fwdpp/ts/count_mutations.hpp>
#include <fwdpp/internal/sample_diploid_helpers.hpp>
#include <stdexcept>
#include "index_and_count_mutations.hpp"

void
index_and_count_mutations(const bool suppress_edge_table_indexing,
fwdpy11::DiploidPopulation& pop)
{
pop.mcounts_from_preserved_nodes.resize(pop.mutations.size(), 0);
if (!suppress_edge_table_indexing)
bool neutral_variants_present = false;
for (auto& m : pop.tables->mutations)
{
if (m.neutral)
{
neutral_variants_present = true;
break;
}
}

// FIXME: there must be a way to remove this awkward check?
if (!suppress_edge_table_indexing && !neutral_variants_present)
{
return;
}
if (pop.tables->preserved_nodes.empty())
if (pop.tables->preserved_nodes.empty() || neutral_variants_present)
{
pop.tables->build_indexes();
pop.fill_alive_nodes();
fwdpp::ts::count_mutations(*pop.tables, pop.mutations,
pop.alive_nodes, pop.mcounts);
if (pop.tables->preserved_nodes.empty())
{
fwdpp::ts::count_mutations(*pop.tables, pop.mutations,
pop.alive_nodes, pop.mcounts);
}
else
{
fwdpp::ts::count_mutations(*pop.tables, pop.mutations,
pop.alive_nodes, pop.mcounts,
pop.mcounts_from_preserved_nodes);
}
for (auto& mr : pop.tables->mutations)
{
if (pop.mcounts[mr.key] + pop.mcounts_from_preserved_nodes[mr.key]
== 0)
{
throw std::runtime_error(
"mutation in table has count of zero.");
}
}
}
else
{
fwdpp::fwdpp_internal::process_haploid_genomes(
pop.haploid_genomes, pop.mutations, pop.mcounts);
fwdpp::fwdpp_internal::process_haploid_genomes(pop.haploid_genomes,
pop.mutations, pop.mcounts);
}
}

0 comments on commit 6281d12

Please sign in to comment.