-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #646 Add extensive tests of ancient samples w/ and w/o neutral mutations. Change test to trigger more failures. Add run time checks of mutation table consistency. For final mutation counting, always use tables when simulating neutral mutations. After simplification, build recycling queue from simplification results if simulating neutral mutations. index_and_count_mutations removes mutations from tables whose counts are adjusted to zero if reset_treeseqs_to_alive_nodes_after_simplification is true. Only adjust mcounts_from_preserved_nodes using last_preserved_generation_counts if reset_treeseqs_to_alive_nodes_after_simplification is false. Only adjust mutation counts by last_preserved_generation_counts if not simulating neutral mutations.
- Loading branch information
Showing
9 changed files
with
280 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 26 additions & 9 deletions
35
fwdpy11/src/evolve_population/index_and_count_mutations.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
#include <numeric> | ||
#include <algorithm> | ||
#include <fwdpy11/types/DiploidPopulation.hpp> | ||
#include <fwdpp/ts/table_collection_functions.hpp> | ||
#include <fwdpp/ts/count_mutations.hpp> | ||
#include <fwdpp/internal/sample_diploid_helpers.hpp> | ||
#include "index_and_count_mutations.hpp" | ||
|
||
void | ||
index_and_count_mutations(const bool suppress_edge_table_indexing, | ||
index_and_count_mutations(bool suppress_edge_table_indexing, | ||
bool simulating_neutral_variants, | ||
bool reset_treeseqs_to_alive_nodes_after_simplification, | ||
fwdpy11::DiploidPopulation& pop) | ||
{ | ||
pop.mcounts_from_preserved_nodes.resize(pop.mutations.size(), 0); | ||
if (!suppress_edge_table_indexing) | ||
if (!suppress_edge_table_indexing && !simulating_neutral_variants) | ||
{ | ||
return; | ||
} | ||
if (pop.tables->preserved_nodes.empty()) | ||
if (pop.tables->preserved_nodes.empty() || simulating_neutral_variants) | ||
{ | ||
pop.tables->build_indexes(); | ||
pop.fill_alive_nodes(); | ||
fwdpp::ts::count_mutations(*pop.tables, pop.mutations, | ||
pop.alive_nodes, pop.mcounts); | ||
fwdpp::ts::count_mutations(*pop.tables, pop.mutations, pop.alive_nodes, | ||
pop.mcounts, pop.mcounts_from_preserved_nodes); | ||
} | ||
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); | ||
} | ||
if (reset_treeseqs_to_alive_nodes_after_simplification) | ||
{ | ||
auto itr = std::remove_if( | ||
begin(pop.tables->mutations), end(pop.tables->mutations), | ||
[&pop](const auto& mr) { | ||
return pop.mcounts[mr.key] + 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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#ifndef FWDPP_TSEVOLUTION_INDEX_AND_COUNT_HPP | ||
#define FWDPP_TSEVOLUTION_INDEX_AND_COUNT_HPP | ||
|
||
#include <vector> | ||
#include <cstdint> | ||
#include <fwdpy11/types/DiploidPopulation.hpp> | ||
|
||
void index_and_count_mutations(const bool suppress_edge_table_indexing, | ||
void index_and_count_mutations(bool suppress_edge_table_indexing, | ||
bool simulating_neutral_variants, | ||
bool reset_treeseqs_to_alive_nodes_after_simplification, | ||
fwdpy11::DiploidPopulation& pop); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <sstream> | ||
#include <fwdpy11/types/DiploidPopulation.hpp> | ||
|
||
static std::string | ||
strip_unix_path(const std::string file) | ||
{ | ||
auto pos = file.find_last_of('/'); | ||
if (pos != std::string::npos) | ||
{ | ||
return std::string(begin(file) + static_cast<std::ptrdiff_t>(pos) + 1, | ||
end(file)); | ||
} | ||
return file; | ||
} | ||
|
||
void | ||
check_mutation_table_consistency_with_count_vectors(const fwdpy11::Population& pop, | ||
std::string file, int line) | ||
{ | ||
for (auto& mr : pop.tables->mutations) | ||
{ | ||
if (pop.mcounts[mr.key] + pop.mcounts_from_preserved_nodes[mr.key] == 0) | ||
{ | ||
std::ostringstream msg; | ||
msg << "mutation table is inconsistent with count vectors: " | ||
<< strip_unix_path(file) << ", line " << line; | ||
throw std::runtime_error(msg.str()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <string> | ||
#include <fwdpy11/types/Population.hpp> | ||
|
||
void check_mutation_table_consistency_with_count_vectors(const fwdpy11::Population& pop, | ||
std::string file, int line); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.