Simulating Mating Alliances as a Reproductive Tactic for Populations
 All Classes Functions Variables Friends
simulation.h
1 /*** SMARTPOP, Simulating Mating Alliances as a Reproductive Tactic for POPuplations
2  Copyright (C) 2013 E.G.Guillot
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17  Contact: e.guillot@massey.ac.nz
18 ***/
19 
20 #ifndef DEF_SIMULATION
21 #define DEF_SIMULATION
22 #include "genetics.h"
23 
24 
26 {
27  public:
28  Simulation();
29  explicit Simulation(unsigned randomSeed);
30  Simulation(Simulation const &);
31  ~Simulation();
33  // main operations
34  int run();
35  int print_help();
36  void load_file(std::string);
37  void load_directory(std::string);
38  void export_file(std::string filename);
39  // get /set
40  void set_seed(int);
41  void set_popsize(int);
42  void set_sample(int);
43  void set_step(int);
44  void set_nstep(int);
45  void set_matsys(int);
46  void set_inbreeding(int);
47  void set_nSimu(int);
48  void set_sizeMt(int);
49  void set_sizeY(int);
50  void set_sizePerX(int);
51  void set_sizePerA(int);
52  void set_nbLociA(int);
53  void set_nbLociX(int);
54  void set_mu(double,double);
55  void set_mu(double,double,double,double);
56  void set_mu(double,double,double,double,double,double,double,double);
57  void set_growthFactor(double,double,double);
58  void set_burninT(double);
59  void set_dnaComplexity(int a);
60  void set_diversityX(int a);
61  void set_fileoutput(std::string);
62  void set_verbose_on();
63  void set_fasta_on();
64  void set_save_on(std::string dirName);
65  void set_arlequin_on();
66  void set_genealogy_on();
67  void set_header_on();
68  int get_nSimu();
69  bool get_verbose();
70  void header_write();
71  void check_parameters();
72  private:
73  unsigned seed;
74  int popsize;
75  int sample;
76  int step;
77  int nstep;
78  int matsys;
79  int inbreeding;
80  int nSimu;
81  int counter;
82  int sizeMt;
83  int sizeY;
84  int sizePerA;
85  int sizePerX;
86  int nbLociA;
87  int nbLociX;
88  double muMt1;
89  double muMt2;
90  double muX1;
91  double muX2;
92  double muY1;
93  double muY2;
94  double muA1;
95  double muA2;
96  std::vector<double> growthFactor;
97  double burninT;
98  double dnaComplexity; // if 0 complete DNA, if 1, mitochondrial, if 2 only human (-> genealogy)
99  std::vector<int> diversityX; // if 0 complete DNA, if 1 mtDNA, if 3 Y chr, if 2 X, if 4 autosome
100  std::string fileoutput;
101  std::string directoryLoad;
102  std::string directorySave;
103  // booleans
104  bool verbose;
105  bool genealogy;
106  bool fasta;
107  bool smartSave;
108  bool arlequin;
109  bool header;
110  bool load;
111  double maxpop;
112  // hidden functions
113  int classic();
114  int successive_classic();
115  int mito();
116  int successive_mito();
117  int indiv_nodna();
118  int successive_indiv_nodna();
119  int output_main(int X, Population<Humandna> & epsilon);
120  int output_main(int X, Population<Humanmt> & epsilon);
121  int output_main(int X, Population<Human> & epsilon);
122  int verbose_start();
123  int verbose_end();
124  template <class T>
125  void save(Population<T> epsilon);
126  template <class T>
127  void evolve(Population<T> &epsilon);
128 };
129 
130 template <class T>
131 void Simulation::save(Population<T> epsilon)
132 {
133  epsilon.write_smartFormat(directorySave + "_" + to_string(counter) + ".sim");
134 }
135 
136 template <class T>
137 void Simulation::evolve(Population<T>& epsilon)
138 {
139  std::string fileGenealogy = fileoutput + ".gene";
140  epsilon.set_mating_system(matsys);
141  epsilon.set_growthFactor(growthFactor);
142  if(burninT>0)
143  {
144  epsilon.burnin(burninT,100,10);
145  }
146  for(int j(0);j<nstep;++j)
147  {
148  if(genealogy)
149  epsilon.evolve_gene(step,fileGenealogy);
150  else
151  epsilon.evolve(step);
152  for (unsigned k(0); k<diversityX.size();++k)
153  if(diversityX[k]>-1)
154  output_main(diversityX[k],epsilon);
155  }
156  if (smartSave)
157  {
158  save(epsilon);
159  }
160 }
161 
162 #endif
void set_dnaComplexity(int a)
Definition: simulation.cpp:596
void set_save_on(std::string dirName)
Definition: simulation.cpp:653
void set_sample(int)
Definition: simulation.cpp:470
void set_verbose_on()
Definition: simulation.cpp:643
void evolve(int gen)
Definition: population.h:528
void write_smartFormat(std::string const &filename) const
void set_fileoutput(std::string)
Definition: simulation.cpp:638
void set_arlequin_on()
Definition: simulation.cpp:659
Definition: population.h:14
Definition: simulation.h:25
void set_matsys(int)
Definition: simulation.cpp:485
void set_inbreeding(int)
Definition: simulation.cpp:490
void set_sizeMt(int)
Definition: simulation.cpp:500
~Simulation()
Definition: simulation.cpp:136
void load_directory(std::string)
Definition: simulation.cpp:356
void set_header_on()
Definition: simulation.cpp:669
void set_seed(int)
Definition: simulation.cpp:458
void export_file(std::string filename)
Definition: simulation.cpp:362
void header_write()
Definition: simulation.cpp:684
void set_growthFactor(double, double, double)
Definition: simulation.cpp:584
void load_file(std::string)
Definition: simulation.cpp:181
bool get_verbose()
Definition: simulation.cpp:679
void set_fasta_on()
Definition: simulation.cpp:648
Simulation & operator=(Simulation const &)
Definition: simulation.cpp:140
void set_popsize(int)
Definition: simulation.cpp:463
void evolve_gene(int gen, std::string filename)
Definition: population.h:539
int get_nSimu()
Definition: simulation.cpp:674
void set_nstep(int)
Definition: simulation.cpp:480
void set_growthFactor(double, double, double)
Definition: population.h:268
void set_burninT(double)
Definition: simulation.cpp:591
void set_genealogy_on()
Definition: simulation.cpp:664
void check_parameters()
Definition: simulation.cpp:412
void set_nSimu(int)
Definition: simulation.cpp:495
int print_help()
Definition: simulation.cpp:819
void set_diversityX(int a)
Definition: simulation.cpp:625
void set_step(int)
Definition: simulation.cpp:475

Home