From d8d4560184404b4b0aa1581764ce58f818255999 Mon Sep 17 00:00:00 2001 From: Dariusz Murakowski Date: Tue, 21 Apr 2015 15:37:56 -0400 Subject: [PATCH] Print virus species sequence when verbose. --- pop_ss.h | 4 ++++ ss.cpp | 25 +++++++++++++++++++------ ss.h | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pop_ss.h b/pop_ss.h index 8f35f16..6bacf5e 100644 --- a/pop_ss.h +++ b/pop_ss.h @@ -61,6 +61,10 @@ public: Species(long c) : count(c), name("") {} Species(std::string x) : count(0), name(x) {} Species(std::string x, long c) : count(c), name(x) {} + + // necessary otherwise compiler complains 'source type is not polymorphic' + // ...should probably have a virtual destructor.... + virtual void allow_dynamic_cast() {} }; class SimpleSpecies : public Species { diff --git a/ss.cpp b/ss.cpp index f13069e..094bba7 100644 --- a/ss.cpp +++ b/ss.cpp @@ -111,7 +111,7 @@ void run(RunParameters_SS &r, unsigned seed) { //double t_end = 1000.0; //long max_steps = LONG_MAX; //double sample_interval = 1.0; - simulate(reactions, species, r.t_end, r.max_steps, r.sample_interval, print_spec); + simulate(reactions, species, r.t_end, r.max_steps, r.sample_interval, print_spec, r.useVerbose); gsl_rng_free(rnd); //Free up memory from random number generator @@ -147,21 +147,34 @@ void print_species_header(const Species_parray &print_spec) std::cout << '\n'; } -void print_species_traj(double t, const Species_parray &print_spec) +void print_species_traj(double t, const Species_parray &print_spec, bool verbose) { std::cout << t; for (Species_parray::const_iterator spec = print_spec.begin(), - end = print_spec.end(); + end = print_spec.end(); spec != end; ++spec) { // TODO: prettier representation std::cout << '\t' << (*spec)->count; + + if (verbose) { + VirusSpecies *V = dynamic_cast (*spec); + if (V) { + virus_map::iterator it = V->pop.begin(), + end = V->pop.end(); + for (; it != end; ++it) { + std::cout << ' ' << it->second + << '(' << it->first.mutated_sites << ')'; + } + } + } + } std::cout << '\n'; } -void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long max_steps, double sample_interval, const Species_parray &print_spec) +void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long max_steps, double sample_interval, const Species_parray &print_spec, bool verbose) { long step = 0; @@ -216,13 +229,13 @@ void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long // print copy numbers if (t_next_sample <= t) { t_next_sample += sample_interval; - print_species_traj(t,print_spec); + print_species_traj(t,print_spec,verbose); } } if (t_end == HUGE_VAL) - print_species_traj(t,print_spec); + print_species_traj(t,print_spec,verbose); } diff --git a/ss.h b/ss.h index 8d7f02b..da25a2e 100644 --- a/ss.h +++ b/ss.h @@ -238,7 +238,7 @@ public: void run(RunParameters_SS &r); void importState(RunParameters_SS &r); void importEpitope(RunParameters_SS &r, Species_parray &species, Rxn_parray &reactions, VirusSpecies *V, Species_parray &print_spec); -void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long max_steps, double sample_interval, const Species_parray &print_spec); +void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long max_steps, double sample_interval, const Species_parray &print_spec, bool verbose); #endif -- 2.7.4