#include "hamiltonian.h"
-//Constructor for loading couplings from John Barton's Ising Inversion code
-//Code for this function derived from John Barton's code
+// code for loading couplings adapted from John Barton via Tom Butler
Hamiltonian::Hamiltonian(std::string &FILENAME) {
}
-//Constructor for loading couplings from John Barton's Ising Inversion code
-//Code for this function derived from John Barton's code
+// code for loading couplings adapted from John Barton via Tom Butler
EpitopeHamiltonian::EpitopeHamiltonian(std::string &FILENAME) {
std::set<unsigned int>::iterator iter1;
std::set<unsigned int>::iterator iter2;
- for (iter1=mutated_sites.begin();iter1!=mutated_sites.end();++iter1) {
+ for (iter1=mutated_sites.begin(); iter1!=mutated_sites.end(); ++iter1) {
efield -= J[*iter1][*iter1];
iter2 = iter1;
++iter2;
- for (;iter2!=mutated_sites.end();iter2++) ecoupling -= J[*iter1][*iter2];
+ for (; iter2!=mutated_sites.end(); iter2++)
+ ecoupling -= J[*iter1][*iter2];
}
bool EpitopeHamiltonian::escaped(const std::set<unsigned int> &mutated_sites, const std::vector<unsigned int> &eWT, const std::vector<unsigned int> &eMut) const {
- bool escape=false;
+ bool escape = false;
- for (unsigned i=0;i<eWT.size();i++) {
+ for (unsigned i=0; i<eWT.size(); i++) {
if (mutated_sites.count(eWT[i])==1) { escape=true; break; }
if (!escape) {
- for (unsigned i=0;i<eMut.size();i++) {
+ for (unsigned i=0; i<eMut.size(); i++) {
if (mutated_sites.count(eMut[i])==0) { escape=true; break; }
std::set<unsigned int>::iterator iter1;
std::set<unsigned int>::iterator iter2;
- for (iter1=mutated_sites.begin();iter1!=mutated_sites.end();++iter1) {
+ for (iter1=mutated_sites.begin(); iter1!=mutated_sites.end(); ++iter1) {
efield -= J[*iter1][*iter1];
iter2 = iter1;
++iter2;
- for (;iter2!=mutated_sites.end();iter2++) ecoupling -= J[*iter1][*iter2];
+ for (; iter2!=mutated_sites.end(); iter2++)
+ ecoupling -= J[*iter1][*iter2];
}
#include "population.h"
-//Constructor that assembles a population of N viruses of wild type
+// constructor that assembles a population of N viruses of wild type
Population::Population(const Hamiltonian &H, unsigned int N, double mu) {
}
-//Constructor that assembles a population of N viruses given starting population fractions
+// constructor that assembles a population of N viruses given starting population fractions
Population::Population(const Hamiltonian &H, unsigned int N, double mu, const std::vector<std::set<unsigned int> > &initPop, const std::vector<double> &initFrac) {
- for (unsigned i=0;i<initPop.size();i++) {
+ for (unsigned i=0; i<initPop.size(); i++) {
Virus V(H, mu, initPop[i]);
pop[V] = (unsigned int) N * initFrac[i];
}
-//Step population forward a generation.
+// Step population forward a generation.
void Population::next_generation(const Hamiltonian &H, gsl_rng* r, bool useRelative, bool useVerbose) {
virus_map::iterator iter=pop.begin();
- for(;iter!=pop.end();++iter){
+ for(; iter!=pop.end(); ++iter){
if (useRelative) num_survive = gsl_ran_binomial(r,iter->first.survival(Eavg),iter->second);
else num_survive = gsl_ran_binomial(r,iter->first.survival(),iter->second);
new_Eavg += iter->first.energy * num_survive;
- // Report survival
+ // report survival
if (useVerbose) {
if (useVerbose) { std::cout << "checkpoint, " << "total_deaths = " << total_deaths << std::endl; }
- //delete zero population strains
+ // delete zero population strains
iter=pop.begin();
}
-// Output population to file
+// Output population to file.
void Population::write_population(std::string filename) {
}
-// Output population to file
+// Output population to file.
void Population::write_population(FILE *output, unsigned int generation) {
}
-// Compute the total population size
+// Compute the total population size.
unsigned int Population::compute_population_size() {
unsigned int i=0;
- for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter) i+=iter->second;
+ for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter)
+ i+=iter->second;
return i;
}
-// Print population size to standard out
+// Print population size to standard output.
void Population::print_population_size() {
}
-//Mutate every virus in the population
+// Mutate every virus in the population.
void Population::mutate_population(const Hamiltonian &H, gsl_rng* r) {
}
-// Compute the number of escaped viruses in the population
+// Compute the number of escaped viruses in the population.
unsigned int Population::compute_num_escaped(Hamiltonian &H) {
unsigned int i=0;
- for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter) { if (H.escaped(iter->first)) i+=iter->second; }
+ for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter) {
+ if (H.escaped(iter->first))
+ i += iter->second;
+ }
return i;
}
-// Check whether most of the population has escaped from immune pressure
+// Check whether most of the population has escaped from immune pressure.
bool Population::escaped(Hamiltonian &H) {
}
-// Compute the number of escaped viruses in the population
+// Compute the number of escaped viruses in the population.
unsigned int Population::escape_variant(Hamiltonian &H, std::set<unsigned int> &mutant) {
if (H.escaped(iter->first) && (iter->second)>i) {
- i=iter->second;
- mutant=iter->first.mutated_sites;
+ i = iter->second;
+ mutant = iter->first.mutated_sites;
}
-// Compute the number of escaped viruses in the population
+// Compute the number of escaped viruses in the population.
unsigned int Population::compute_num_escaped_all(Hamiltonian &H) {
unsigned int i=0;
- for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter) { if (H.escaped_all(iter->first)) i+=iter->second; }
+ for (virus_map::iterator iter=pop.begin(); iter!=pop.end(); ++iter) {
+ if (H.escaped_all(iter->first))
+ i+=iter->second;
+ }
return i;
}
-// Check whether most of the population has escaped from *all* immune pressure
+// Check whether most of the population has escaped from *all* immune pressure.
bool Population::escaped_all(Hamiltonian &H) {
}
-// Compute the number of escaped viruses in the population
+// Compute the number of escaped viruses in the population.
unsigned int Population::escape_variant_all(Hamiltonian &H, std::set<unsigned int> &mutant) {
typedef std::map<Virus, unsigned int> virus_map;
-class Population{
+class Population {
public:
#include "virus.h"
-//Constuct a virus object of wildtype
+// Constuct a virus object of wildtype.
Virus::Virus(const Hamiltonian &H, double mu) {
this->mutated_sites.clear();
- this->mu=mu;
- L=H.size;
- energy=0;
+ this->mu = mu;
+ L = H.size;
+ energy = 0;
}
-//Construct a virus and compute its energy.
+// Construct a virus and compute its energy.
Virus::Virus(const Hamiltonian &H, double mu, const std::set<unsigned int> &mutated_sites) {
this->mutated_sites=mutated_sites;
- this->mu=mu;
- L=H.size;
+ this->mu = mu;
+ L = H.size;
update_energy(H);
}
-//Print key numerical parameters of the object to the terminal for diagnostics.
+// Print key numerical parameters of the object to the terminal for diagnostics.
void Virus::print_parameters() {
}
-//Mutate the entire virus. Takes a Hamiltonian object and a pointer
-//to an instance of a gsl_rng random number generator
+// Mutate the entire virus. Takes a Hamiltonian object and a pointer
+// to an instance of a gsl_rng random number generator
void Virus::mutate(const Hamiltonian &H, gsl_rng* r) {
- unsigned int n=gsl_ran_binomial(r,mu,L);
+ unsigned int n = gsl_ran_binomial(r,mu,L);
- while (n<1) n=gsl_ran_binomial(r,mu,L);
+ while (n<1)
+ n = gsl_ran_binomial(r,mu,L);
- for (unsigned i=0;i<n;i++) {
+ for (unsigned i=0; i<n; i++) {
unsigned int x=gsl_rng_uniform_int(r,H.size);
}
-//Computes the odds of survival
+// Computes the odds of survival.
double Virus::survival() const {
}
-//Computes the odds of survival
+// Computes the odds of survival.
double Virus::survival(double Eavg) const {
}
-//Update the energy of the virus object. Takes as an argument the
-//Hamiltonian that determines the energy
+// Update the energy of the virus object.
+// Takes as an argument the Hamiltonian that determines the energy.
void Virus::update_energy(const Hamiltonian &H) {
- energy=H.get_energy(mutated_sites);
+ energy = H.get_energy(mutated_sites);
}
+// required by virus_map (std::map<Virus, unsigned int>) in Population
+
bool operator<(const Virus& lhs, const Virus& rhs) {
return lhs.mutated_sites < rhs.mutated_sites;
}
-// Run the program
+// Run the program.
void run(RunParameters &r, unsigned seed) {
fflush(stdout);
- // Run (w/ targeted epitope)
+ // Run (with targeted epitope)
if (r.useEpitope) {
else {
- for (unsigned int n=0;n<r.num_runs;n++) {
+ for (unsigned int n=0; n<r.num_runs; n++) {
Hamiltonian H(r.couplingsInfile);
H.set_temp(r.bh, r.bJ);
gsl_rng_free(rnd); //Free up memory from random number generator
- fclose(popout); // close file handles
+ // close file handles
+ fclose(popout);
fclose(supout);
}
-// Import initial state from a state file
+// Import initial state from a state file.
void importState(RunParameters &r) {