Empirical
World_output.h
Go to the documentation of this file.
1 
9 #ifndef EMP_EVO_WORLD_OUTPUT_H
10 #define EMP_EVO_WORLD_OUTPUT_H
11 
12 #include "base/vector.h"
13 #include "data/DataFile.h" // Helper to determine when specific events should occur.
14 #include "SystematicsAnalysis.h"
15 #include "tools/string_utils.h"
16 
17 namespace emp {
18 
19  template <typename WORLD_TYPE>
20  DataFile & AddPhylodiversityFile(WORLD_TYPE & world, int systematics_id=0, const std::string & fpath="phylodiversity.csv"){
21  auto & file = world.SetupFile(fpath);
22  auto sys = world.GetSystematics(systematics_id);
23 
24  sys->AddEvolutionaryDistinctivenessDataNode();
25  sys->AddPairwiseDistanceDataNode();
26  sys->AddPhylogeneticDiversityDataNode();
27 
28  std::function<size_t(void)> get_update = [&world](){return world.GetUpdate();};
29 
30  file.AddFun(get_update, "update", "Update");
31  file.AddStats(*sys->GetDataNode("evolutionary_distinctiveness") , "evolutionary_distinctiveness", "evolutionary distinctiveness for a single update", true, true);
32  file.AddStats(*sys->GetDataNode("pairwise_distance"), "pairwise_distance", "pairwise distance for a single update", true, true);
33  file.AddCurrent(*sys->GetDataNode("phylogenetic_diversity"), "current_phylogenetic_diversity", "current phylogenetic_diversity", true, true);
34  file.PrintHeaderKeys();
35  return file;
36  }
37 
38  template <typename WORLD_TYPE>
39  DataFile & AddLineageMutationFile(WORLD_TYPE & world, int systematics_id=0, const std::string & fpath="lineage_mutations.csv", emp::vector<std::string> mut_types = {"substitution"}){
40  auto & file = world.SetupFile(fpath);
41  auto sys = world.GetSystematics(systematics_id);
42 
43  for (size_t i = 0; i < mut_types.size(); i++) {
44  sys->AddMutationCountDataNode(mut_types[i]+"_mut_count", mut_types[i]);
45  }
46 
47  auto node = sys->AddDeleteriousStepDataNode();
48  sys->AddVolatilityDataNode();
49  sys->AddUniqueTaxaDataNode();
50 
51  std::function<size_t(void)> get_update = [&world](){return world.GetUpdate();};
52 
53  file.AddFun(get_update, "update", "Update");
54  for (size_t i = 0; i < mut_types.size(); i++) {
55  file.AddStats(*sys->GetDataNode(mut_types[i]+"_mut_count"), mut_types[i] + "_mutations_on_lineage", "counts of" + mut_types[i] + "mutations along each lineage", true, true);
56  }
57 
58  file.AddStats(*sys->GetDataNode("deleterious_steps"), "deleterious_steps", "counts of deleterious steps along each lineage", true, true);
59  file.AddStats(*sys->GetDataNode("volatility"), "taxon_volatility", "counts of changes in taxon along each lineage", true, true);
60  file.AddStats(*sys->GetDataNode("unique_taxa"), "unique_taxa", "counts of unique taxa along each lineage", true, true);
61  file.PrintHeaderKeys();
62  return file;
63  }
64 
65 };
66 
67 #endif
DataFile & AddPhylodiversityFile(WORLD_TYPE &world, int systematics_id=0, const std::string &fpath="phylodiversity.csv")
Definition: World_output.h:20
Simple functions to manipulate strings.
DataFile objects use DataNode objects to dynamically fill out file contents.
A drop-in wrapper for std::vector; adds on bounds checking in debug mode.
If we are in emscripten, make sure to include the header.
Definition: array.h:37
DataFile & AddLineageMutationFile(WORLD_TYPE &world, int systematics_id=0, const std::string &fpath="lineage_mutations.csv", emp::vector< std::string > mut_types={"substitution"})
Definition: World_output.h:39
size_t AddFun(const std::function< T()> &fun, const std::string &key="", const std::string &desc="")
Add a function that returns a value to be printed to the file.
Definition: DataFile.h:163
Definition: DataFile.h:32