Skip to content

Commit 9057a00

Browse files
committed
Add R0 tracking
1 parent 1e38797 commit 9057a00

7 files changed

Lines changed: 100 additions & 5 deletions

File tree

source/ConfigSetup.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ EMP_BUILD_CONFIG(SymConfigBase,
5959
VALUE(WRITE_CURRENT_INTERACTION_COUNTS, bool, 0, "Should the world write the count of only-currently-present interactions? (0 for no, 1 for yes)"),
6060
VALUE(PHYLOGENY_SNAPSHOT_INTERVAL, int, 10001, "How often to output phylogeny snapshots"),
6161
VALUE(NUM_PHYLO_BINS, size_t, 5, "How many bins should organisms be separated into if phylogeny is on?"),
62-
VALUE(PHYLOGENY_TAXON_TYPE, std::string, "interaction-value-binned", "What are phylogeny taxa based on? Options: interaction-value-binned, interaction-value-exact, tag, individual"),
62+
VALUE(PHYLOGENY_TAXON_TYPE, std::string, "interaction-value-binned", "What are phylogeny taxa based on? Options: interaction-value-binned, interaction-value-exact, tag, individual, horizontal-clade"),
6363
VALUE(STORE_EXTINCT, bool, 0, "Should extinct taxa be stored? (0 for no, 1 for yes)"),
6464

6565
GROUP(MUTATION, "Mutation"),
@@ -95,6 +95,9 @@ EMP_BUILD_CONFIG(SymConfigBase,
9595
VALUE(TAG_MUTATION_SIZE, double, 0.01, "What is the probability that any given position in the bitstring tag flips during mutation?"),
9696
VALUE(WRITE_TAG_MATRIX, bool, 0, "At the end of the experiment, should a similarity matrix of all persisting tags be generated?"),
9797
VALUE(TAG_MATRIX_SAMPLE_PROPORTION, double, 0.1, "What proportion of positions in the world should be sampled to produce the tag matrix from?"),
98-
VALUE(HOST_STARTING_TAGS_ONE_PROB, double, 0, "What probability should initializing bits in tags have of being 1s? Hosted symbionts will be assigned their host's tag. (0 for basic, all-0 only tags)")
98+
VALUE(HOST_STARTING_TAGS_ONE_PROB, double, 0, "What probability should initializing bits in tags have of being 1s? Hosted symbionts will be assigned their host's tag. (0 for basic, all-0 only tags)"),
99+
100+
GROUP(ANTIBIOTIC_RESISTANCE, "Settings for antibiotic resistance"),
101+
VALUE(R0_WINDOW, double, 100, "How many updates should be used to calculate R0?")
99102
)
100103
#endif

source/Organism.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Organism {
2929
return !(*this == other);
3030
}
3131

32+
uint64_t taxon_id;
33+
3234
virtual std::string const GetName() const {
3335
std::cout << "GetName called from Organism" << std::endl;
3436
throw "Organism method called!";

source/default_mode/DataNodes.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void SymWorld::CreateDataFiles() {
2121
SetupTransmissionFile(my_config->FILE_PATH()+"TransmissionRates"+my_config->FILE_NAME()+file_ending).SetTimingRepeat(TIMING_REPEAT);
2222
SetupSymDiversityFile(my_config->FILE_PATH()+"SymDiversity"+my_config->FILE_NAME()+file_ending).SetTimingRepeat(TIMING_REPEAT);
2323
SetupReproHistFile(my_config->FILE_PATH() + "ReproHist" + my_config->FILE_NAME() + file_ending).SetTimingRepeat(TIMING_REPEAT);
24+
SetupAntibioticResistanceFile(my_config->FILE_PATH() + "AntibioticResistance" + my_config->FILE_NAME() + file_ending).SetTimingRepeat(TIMING_REPEAT);
2425
if (my_config->FREE_LIVING_SYMS() == 1) {
2526
SetupFreeLivingSymFile(my_config->FILE_PATH()+"FreeLivingSyms_"+my_config->FILE_NAME()+file_ending).SetTimingRepeat(TIMING_REPEAT);
2627
}
@@ -228,6 +229,50 @@ emp::DataFile& SymWorld::SetupReproHistFile(const std::string& filename) {
228229
return file;
229230
}
230231

232+
emp::DataFile & SymWorld::SetupAntibioticResistanceFile(const std::string & filename) {
233+
auto & file = SetupFile(filename);
234+
// auto & node = GetR0();
235+
236+
file.AddVar(update, "update", "Update");
237+
238+
// node.Reset();
239+
file.AddFun((std::function<double()>) [this](){
240+
sym_sys->RemoveAncestorsBefore(GetUpdate() - GetConfig()->R0_WINDOW());
241+
sym_sys->RemoveOutsideBefore(GetUpdate() - GetConfig()->R0_WINDOW());
242+
243+
double numerator = 0;
244+
double denominator = 0;
245+
// This is going to bias R0 to be high, since we're not counting horizontal transmissions that
246+
// quickly died out
247+
for (auto sym_taxon : sym_sys->GetActive()) {
248+
denominator += sym_taxon->GetNumOffEver();
249+
numerator += 1;
250+
}
251+
// std::cout << numerator << " " << denominator << std::endl;
252+
for (auto sym_taxon : sym_sys->GetAncestors()) {
253+
denominator += sym_taxon->GetNumOffEver();
254+
numerator += 1;
255+
}
256+
// std::cout << numerator << " " << denominator << std::endl;
257+
for (auto sym_taxon : sym_sys->GetOutside()) {
258+
denominator += sym_taxon->GetNumOffEver();
259+
numerator += 1;
260+
}
261+
// std::cout << numerator << " " << denominator << std::endl <<std::endl;
262+
return numerator / denominator;
263+
}, "R0", "R0");
264+
// node.AddDatum(numerator / denominator);
265+
266+
// file.AddMean(node, "R0", "R0");
267+
// file.AddMax(node, "max_intval", "Maximum symbiont interaction value");
268+
// file.AddMin(node, "min_intval", "Minimum symbiont interaction value");
269+
// file.AddTotal(node1, "count", "Total number of symbionts");
270+
271+
file.PrintHeaderKeys();
272+
273+
return file;
274+
}
275+
231276

232277
/**
233278
* Input: The address of the string representing the suffixes for the files to be created.
@@ -1413,4 +1458,20 @@ emp::DataMonitor<double>& SymWorld::GetHostTagPermissiveness() {
14131458
return *data_node_symbiont_tag_shannon;
14141459
}
14151460

1461+
/**
1462+
* Input: None
1463+
*
1464+
* Output: The DataMonitor<double>& that has the information representing
1465+
* the symbiont R0 this update.
1466+
*
1467+
* Purpose: To retrieve the data node that is tracking the
1468+
* R0.
1469+
*/
1470+
emp::DataMonitor<double>& SymWorld::GetR0() {
1471+
if (!data_node_R0) {
1472+
data_node_R0.New();
1473+
}
1474+
return *data_node_R0;
1475+
}
1476+
14161477
#endif

source/default_mode/SymWorld.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SymWorld : public emp::World<Organism> {
4646
enum class SPATIAL_STRUCT_MODE { WELL_MIXED, GRID, LOAD };
4747
static const std::unordered_map<std::string, SPATIAL_STRUCT_MODE> spatial_struct_mode_cfg_mapping;
4848

49-
enum class PHYLO_TAXON_TYPE { INTERACTION_VALUE_BINNED, INTERACTION_VALUE_EXACT, TAG, INDIVIDUAL };
49+
enum class PHYLO_TAXON_TYPE { INTERACTION_VALUE_BINNED, INTERACTION_VALUE_EXACT, TAG, INDIVIDUAL, HORIZONTAL_CLADE };
5050
static const std::unordered_map<std::string, PHYLO_TAXON_TYPE> phylo_taxon_type_cfg_mapping;
5151

5252
enum class TAG_METRIC_TYPE { HAMMING, STREAK, HASH };
@@ -190,6 +190,7 @@ class SymWorld : public emp::World<Organism> {
190190
emp::Ptr<emp::DataMonitor<int>> data_node_freesymcount;
191191
emp::Ptr<emp::DataMonitor<int>> data_node_hostedsymcount;
192192
emp::Ptr<emp::DataMonitor<int>> data_node_uninf_hosts;
193+
emp::Ptr<emp::DataMonitor<double>> data_node_R0;
193194
emp::Ptr<emp::DataMonitor<double, emp::data::Histogram>> data_node_attempts_horiztrans;
194195
emp::Ptr<emp::DataMonitor<double, emp::data::Histogram>> data_node_tagfail_horiztrans;
195196
emp::Ptr<emp::DataMonitor<double, emp::data::Histogram>> data_node_sizefail_horiztrans;
@@ -343,6 +344,7 @@ class SymWorld : public emp::World<Organism> {
343344
if (data_node_successes_horiztrans) data_node_successes_horiztrans.Delete();
344345
if (data_node_attempts_verttrans) data_node_attempts_verttrans.Delete();
345346
if (data_node_successes_verttrans) data_node_successes_verttrans.Delete();
347+
if (data_node_R0) data_node_R0.Delete();
346348

347349
for (size_t i = 0; i < sym_pop.size(); i++) { //host population deletion is handled by empirical world destructor
348350
if (sym_pop[i]) {
@@ -1040,6 +1042,7 @@ class SymWorld : public emp::World<Organism> {
10401042
emp::DataFile& SetupTransmissionFile(const std::string& filename);
10411043
emp::DataFile& SetupTagDistFile(const std::string& filename);
10421044
emp::DataFile& SetupSymDiversityFile(const std::string& filename);
1045+
emp::DataFile& SetupAntibioticResistanceFile(const std::string& filename);
10431046
virtual void SetupTransmissionFileColumns(emp::DataFile& file);
10441047
virtual void SetupHostFileColumns(emp::DataFile& file);
10451048
emp::DataMonitor<int>& GetHostCountDataNode();
@@ -1064,6 +1067,7 @@ class SymWorld : public emp::World<Organism> {
10641067
emp::DataMonitor<double>& GetHostTagShannonDiversity();
10651068
emp::DataMonitor<int>& GetSymbiontTagRichness();
10661069
emp::DataMonitor<double>& GetSymbiontTagShannonDiversity();
1070+
emp::DataMonitor<double>& GetR0();
10671071
emp::DataMonitor<double, emp::data::Histogram>& GetTagDistanceDataNode();
10681072
emp::DataMonitor<double, emp::data::Histogram>& GetHostIntValDataNode();
10691073
emp::DataMonitor<double, emp::data::Histogram>& GetSymIntValDataNode();
@@ -1503,7 +1507,8 @@ const std::unordered_map<
15031507
{"interaction-value-binned", PHYLO_TAXON_TYPE::INTERACTION_VALUE_BINNED},
15041508
{"interaction-value-exact", PHYLO_TAXON_TYPE::INTERACTION_VALUE_EXACT},
15051509
{"tag", PHYLO_TAXON_TYPE::TAG},
1506-
{"individual", PHYLO_TAXON_TYPE::INDIVIDUAL}
1510+
{"individual", PHYLO_TAXON_TYPE::INDIVIDUAL},
1511+
{"horizontal-clade", PHYLO_TAXON_TYPE::HORIZONTAL_CLADE}
15071512
};
15081513

15091514
const std::unordered_map<

source/default_mode/Symbiont.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ class Symbiont: public Organism {
123123
*/
124124
emp::WorldPosition location;
125125

126+
/**
127+
*
128+
* Purpose: Janky approach to tracking R0
129+
*/
130+
bool next_reproduction_is_horizontal = false;
131+
uint64_t taxon_id;
132+
126133
public:
127134
/**
128135
* The constructor for symbiont
@@ -698,6 +705,12 @@ class Symbiont: public Organism {
698705
sym_baby->Mutate();
699706
sym_baby->SetReproCount(reproductions + 1);
700707
if(my_config->PHYLOGENY() == 1) {
708+
if (next_reproduction_is_horizontal) {
709+
sym_baby->taxon_id = my_world->GetSymSys()->GetNextID();
710+
} else {
711+
sym_baby->taxon_id = my_taxon->GetID();
712+
}
713+
701714
my_world->AddSymToSystematic(sym_baby, my_taxon);
702715
//baby's taxon will be set in AddSymToSystematic
703716
}
@@ -860,7 +873,9 @@ class Symbiont: public Organism {
860873
*/
861874
void IndependentReproduction(emp::WorldPosition location) {
862875
if (AttemptIndependentReproduction(location)) {
876+
next_reproduction_is_horizontal = true;
863877
emp::Ptr<Organism> sym_baby = Reproduce();
878+
next_reproduction_is_horizontal = false;
864879
if (my_config->TAG_MATCHING() || my_config->FREE_HT_FAILURE()) sym_baby->SetPoints(0);
865880
emp::WorldPosition new_pos = my_world->SymDoBirth(sym_baby, location);
866881

source/default_mode/WorldSetup.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ void SymWorld::SetupPhylogenyTracking() {
214214
return (long unsigned) sym_sys->GetNextID();
215215
};
216216
break;
217+
case PHYLO_TAXON_TYPE::HORIZONTAL_CLADE:
218+
calc_host_info_fun = [&](Organism& org) {
219+
return 0;
220+
};
221+
222+
calc_sym_info_fun = [&](Organism& org) {
223+
return org.taxon_id;
224+
};
225+
break;
217226
default:
218227
emp_error("Unimplemented phylogeny taxon type.");
219228
break;

0 commit comments

Comments
 (0)