From 015c90b67d2537e60376032233ec13ebefd70746 Mon Sep 17 00:00:00 2001 From: Dariusz Murakowski Date: Mon, 15 Jun 2015 18:20:28 -0400 Subject: [PATCH] Remove two-site Hamiltonian. --- hamiltonian.cpp | 120 ---------------------------- hamiltonian.h | 10 --- population.cpp | 37 --------- population.h | 1 - wf.cpp | 241 ++++++++++++++++++++------------------------------------ wf.h | 10 --- 6 files changed, 87 insertions(+), 332 deletions(-) diff --git a/hamiltonian.cpp b/hamiltonian.cpp index 70951c8..71378f7 100644 --- a/hamiltonian.cpp +++ b/hamiltonian.cpp @@ -352,7 +352,6 @@ double EpitopeHamiltonian::get_energy(const std::set &mutated_site } // helper function to test whether vector contains a value -// based on http://stackoverflow.com/questions/6194797/what-is-a-c-container-with-a-contains-operation template inline bool contains(const std::vector &vec, const T &value) { @@ -360,7 +359,6 @@ inline bool contains(const std::vector &vec, const T &value) } // helper function to test whether set contains a value -// based on http://stackoverflow.com/questions/6194797/what-is-a-c-container-with-a-contains-operation template inline bool contains(const std::set &container, const T &value) { @@ -384,121 +382,3 @@ void EpitopeHamiltonian::generate_allsites_set() } - -/*********************************************** - * my simple 2-site 2-allele system - ***********************************************/ - -// Return the energy for a given set of mutated sites - -TwoSiteHamiltonian::TwoSiteHamiltonian(double h1, double h2, double J12) { - - this->bh=1.0; - this->bJ=1.0; - - this->size = 2; - - J.resize(size); - - for(int i=0; ibh=1.0; - this->bJ=1.0; - - FILE* input; - input = fopen(FILENAME.c_str(),"r"); - if (input == NULL) { perror((std::string("ERROR: ") + FILENAME).c_str()); exit(1); } - - typedef std::vector Key; - std::map JIndex; - char o; - int site=0; - - fscanf(input,"%d",&size); - - while (fscanf(input,"%d",&site)==1) { - - Key inputKey(2,site); - while (fscanf(input,"%c",&o)==1) { - - if (o==';') break; - - else { - - int neighborSite=0; - double neighborJ=0; - fscanf(input,"%d %c %lf",&neighborSite,&o,&neighborJ); - - if (neighborSite==site) { - - inputKey[1]=site; - JIndex[inputKey]=neighborJ; - - } - else { - - inputKey[1]=neighborSite; - JIndex[inputKey]=neighborJ; - - } - //std::cout << site << " " << neighborSite << " " << neighborJ << "\n"; - - } - - } - - } - - fclose(input); - Key inputKey(2,0); - J.resize(size); - - for(int i=0;i v00_set (v00_arr, v00_arr+sizeof(v00_arr)/sizeof(v00_arr[0])); - std::set v10_set (v10_arr, v10_arr+sizeof(v10_arr)/sizeof(v10_arr[0])); - std::set v01_set (v01_arr, v01_arr+sizeof(v01_arr)/sizeof(v01_arr[0])); - std::set v11_set (v11_arr, v11_arr+sizeof(v11_arr)/sizeof(v11_arr[0])); - - Virus v00_vir (H, mu);//, v00_set); - Virus v10_vir (H, mu, v10_set); - Virus v01_vir (H, mu, v01_set); - Virus v11_vir (H, mu, v11_set); - - fprintf(output,"\t%d",pop[v00_vir]); - fprintf(output,"\t%d",pop[v10_vir]); - fprintf(output,"\t%d",pop[v01_vir]); - fprintf(output,"\t%d",pop[v11_vir]); - fprintf(output,"\n"); - - fflush(output); - -} - - - diff --git a/population.h b/population.h index 358f07b..bf9c70a 100644 --- a/population.h +++ b/population.h @@ -28,7 +28,6 @@ public: void next_generation(const Hamiltonian &H, gsl_rng* r, bool useRelative, bool useVerbose); void write_population(std::string filepath); void write_population(FILE *output, unsigned int generation); - void write_two_site_population(FILE *output, const Hamiltonian &H, unsigned int generation); unsigned int compute_population_size(); void print_population_size(); void mutate_population(const Hamiltonian &H, gsl_rng* r); diff --git a/wf.cpp b/wf.cpp index 8867c13..bd72472 100644 --- a/wf.cpp +++ b/wf.cpp @@ -48,163 +48,127 @@ void run(RunParameters &r, unsigned seed) { r.setFiles(); FILE *popout=fopen(r.trajectoryOutfile.c_str(),"w"); // .dat - FILE *supout=r.useTwoSite ? NULL : fopen(r.supplementaryOutfile.c_str(),"w"); // .sum + FILE *supout=fopen(r.supplementaryOutfile.c_str(),"w"); // .sum if (popout == NULL) { perror("File error"); exit(1); } - if (r.useTwoSite && supout == NULL) { perror("File error"); exit(1); } + if (supout == NULL) { perror("File error"); exit(1); } if (r.importState) importState(r); // .st if (r.useEpitope) importEpitope(r); // .ep fflush(stdout); - if(r.useTwoSite) { - - fprintf(popout,"gen\tV00\tV10\tV01\tV11\n"); - - for (unsigned int n=0;n esc_var; - unsigned int esc_num = 0; - if (!r.runUntilEscape && !r.runUntilEscape_all) esc_num = P.escape_variant(H, esc_var); // default behavior for backwards compatibility - if (r.runUntilEscape_all) esc_num = P.escape_variant_all(H, esc_var); - if (r.runUntilEscape) esc_num = P.escape_variant(H, esc_var); - // should behave better if both are true - // but more likely to escape one than all, so that one is output - - fprintf(supout,"%d\t%d",i,esc_num); + + if (r.runUntilEscape && P.escaped(H)) break; - //for (std::set::iterator iter=esc_var.begin(); iter!=esc_var.end(); ++iter) fprintf(supout,"\t%d",*iter); + if (r.runUntilEscape_all && P.escaped_all(H)) break; + + } + + std::set esc_var; + unsigned int esc_num = 0; + if (!r.runUntilEscape && !r.runUntilEscape_all) esc_num = P.escape_variant(H, esc_var); // default behavior for backwards compatibility + if (r.runUntilEscape_all) esc_num = P.escape_variant_all(H, esc_var); + if (r.runUntilEscape) esc_num = P.escape_variant(H, esc_var); + // should behave better if both are true + // but more likely to escape one than all, so that one is output + + fprintf(supout,"%d\t%d",i,esc_num); - // print sequence as CSV (comma-separated) - fprintf(supout,"\t"); - std::set::iterator ms_iter=esc_var.begin(); - if (ms_iter != esc_var.end()) { - fprintf(supout,"%d",*ms_iter); - ++ms_iter; - } - for (; ms_iter!=esc_var.end(); ++ms_iter) - fprintf(supout,",%d",*ms_iter); + //for (std::set::iterator iter=esc_var.begin(); iter!=esc_var.end(); ++iter) fprintf(supout,"\t%d",*iter); - fprintf(supout,"\n"); - - fflush(supout); - + // print sequence as CSV (comma-separated) + fprintf(supout,"\t"); + std::set::iterator ms_iter=esc_var.begin(); + if (ms_iter != esc_var.end()) { + fprintf(supout,"%d",*ms_iter); + ++ms_iter; } + for (; ms_iter!=esc_var.end(); ++ms_iter) + fprintf(supout,",%d",*ms_iter); + + fprintf(supout,"\n"); - } - + fflush(supout); - // Run (w/out targeted epitope) + } - else { + } + + + // Run (w/out targeted epitope) + + else { - for (unsigned int n=0;n tempSet; - if (s1) tempSet.insert(0); - if (s2) tempSet.insert(1); - r.initPop.push_back(tempSet); - -} - - void usage() { std::cout << @@ -346,13 +296,6 @@ void usage() " -v flag for verbose output\n" " -numruns (int) number of trajectories to simulate\n" "\n" -" -2site flag for two-site two-allele system\n" -" -h1 (double) value of field at site 1\n" -" -h2 (double) value of field at site 2\n" -" -J12 (double) value of coupling between sites 1 and 2\n" -" (note the sign convention on these is P ~ exp(-H),\n" -" H = sum_i h_i s_i + sum_{i > initPop; // Initial population sequences @@ -144,11 +139,6 @@ public: useRelative=false; useVerbose=false; - useTwoSite = false; - h1 = 0.0; - h2 = 0.0; - J12 = 0.0; - write_mod = 1; numEpitopes = 0; -- 2.7.4