Empirical
SystematicsAnalysis.h
Go to the documentation of this file.
1 
10 #ifndef EMP_EVO_SYSTEMATICS_ANALYSIS_H
11 #define EMP_EVO_SYSTEMATICS_ANALYSIS_H
12 
13 #include "Systematics.h"
14 
15 
16 // Mutation info functions. Assumes each taxon has a struct containing an unordered map
17 // with keys that are strings indicating types of mutations and keys that are numbers
18 // indicating the number of that type of mutation that occurred to make this taxon from
19 // the parent.
20 
21 namespace emp {
22 
27  template <typename taxon_t>
29  int count = 0;
30 
31  while (taxon) {
32  count++;
33  taxon = taxon->GetParent();
34  }
35 
36  return count;
37  }
38 
43  template <typename taxon_t>
44  int CountMutSteps(Ptr<taxon_t> taxon, std::string type="substitution") {
45  int count = 0;
46 
47  while (taxon) {
48  count += (int)(taxon->GetData().mut_counts[type] > 0);
49  taxon = taxon->GetParent();
50  }
51 
52  return count;
53  }
54 
59  template <typename taxon_t>
61  int count = 0;
62 
63  while (taxon) {
64  for (std::string type : types) {
65  count += (int)(taxon->GetData().mut_counts[type] > 0);
66  }
67  taxon = taxon->GetParent();
68  }
69 
70  return count;
71  }
72 
75  template <typename taxon_t>
76  int CountMuts(Ptr<taxon_t> taxon, std::string type="substitution") {
77  int count = 0;
78 
79  while (taxon) {
80  count += taxon->GetData().mut_counts[type];
81  taxon = taxon->GetParent();
82  }
83 
84  return count;
85  }
86 
89  template <typename taxon_t>
91  int count = 0;
92 
93  while (taxon) {
94  for (std::string type : types) {
95  count += taxon->GetData().mut_counts[type];
96  }
97  taxon = taxon->GetParent();
98  }
99 
100  return count;
101  }
102 
107  template <typename taxon_t>
109  int count = 0;
110  Ptr<taxon_t> parent = taxon->GetParent();
111 
112  while (parent) {
113  if (taxon->GetData().GetFitness() < parent->GetData().GetFitness()) {
114  count++;
115  }
116  taxon = parent;
117  parent = taxon->GetParent();
118  }
119 
120  return count;
121  }
122 
125  template <typename taxon_t>
127  int count = 0; // Start with current phenotype
128  Ptr<taxon_t> parent = taxon->GetParent();
129 
130  while (parent) {
131  if (taxon->GetData().phenotype != parent->GetData().phenotype) {
132  count++;
133  }
134  taxon = parent;
135  parent = taxon->GetParent();
136  }
137 
138  return count;
139  }
140 
143  template <typename taxon_t>
145  int count = 0;
146  std::set<decltype(taxon->GetData().phenotype)> seen;
147 
148  while (taxon) {
149  if (!Has(seen, taxon->GetData().phenotype)) {
150  count++;
151  seen.insert(taxon->GetData().phenotype);
152  }
153  taxon = taxon->GetParent();
154  }
155 
156  return count;
157  }
158 
159 };
160 
161 #endif
int CountDeleteriousSteps(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:108
int LineageLength(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:28
int CountUniquePhenotypes(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:144
bool Has(const MAP_T &in_map, const KEY_T &key)
Take any map type, and run find to determine if a key is present.
Definition: map_utils.h:21
int CountPhenotypeChanges(Ptr< taxon_t > taxon)
Definition: SystematicsAnalysis.h:126
If we are in emscripten, make sure to include the header.
Definition: array.h:37
int CountMuts(Ptr< taxon_t > taxon, std::string type="substitution")
Definition: SystematicsAnalysis.h:76
Definition: Ptr.h:711
int CountMutSteps(Ptr< taxon_t > taxon, std::string type="substitution")
Definition: SystematicsAnalysis.h:44
Track genotypes, species, clades, or lineages of organisms in a world.