Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
servicenotifiers.h
Go to the documentation of this file.
1 
28 #include "types.h"
29 #include "lifecycleevent.h"
30 #include "fileservices.h"
31 #include "statservices.h"
32 #include "updaterservices.h"
33 #include "filehandler.h"
34 #include "stathandler.h"
35 #include <map>
36 
37 //LCE_ParamUpdaterNotifier
38 //
41 
42 private:
44 
45 public:
46 
47  LCE_ParamUpdaterNotifier () : LifeCycleEvent("param_updater",""), _manager(0) { }
49 
50  void setManager (UpdaterServices* mng) {_manager = mng;}
51  virtual void execute ();
52  virtual bool setParameters () {return true;}
53 
54  virtual LifeCycleEvent* clone ( ) {return new LCE_ParamUpdaterNotifier();}
55 
56  //SimComponent overrides:
57  virtual void loadFileServices ( FileServices* loader ) {}
58  virtual void loadStatServices ( StatServices* loader ) {}
59  virtual void loadUpdaters ( UpdaterServices* loader) {_manager = loader;}
60  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
61  virtual age_t removeAgeClass ( ) {return 0;}
62  virtual age_t addAgeClass ( ) {return 0;}
63  virtual age_t requiredAgeClass () {return 0;}
64 };
65 
66 // LCE_FileServicesNotifier
67 //
68 // forward decl
69 class GenotyperFH;
72 {
73 
76  unsigned int _sample_patch_num;
79 
80  vector< GenotyperFH* > _genotypers;
81 
82 public:
83  LCE_FileServicesNotifier(); //: LifeCycleEvent("save_files",""), _service(0) { }
84  virtual ~LCE_FileServicesNotifier( );
85 
86  virtual void execute ();
87  virtual bool setParameters ();
88 
89  bool setSamplingParameters ();
90  bool setGenotyperParameters ();
91 
92  virtual LifeCycleEvent* clone ( ) {return new LCE_FileServicesNotifier();}
93 
94  //SimComponent implementation
95  virtual void loadFileServices ( FileServices* loader );
96  virtual void loadStatServices ( StatServices* loader ) {}
97  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
98  virtual age_t removeAgeClass ( ) {return 0;}
99  virtual age_t addAgeClass ( ) {return 0;}
100  virtual age_t requiredAgeClass () {return 0;}
101 };
102 
103 // ----------------------------------------------------------------------------------------
104 
105 // GenotyperFH
106 
107 // ----------------------------------------------------------------------------------------
109 class GenotyperFH : public EventFileHandler < LCE_FileServicesNotifier > {
110 
111  vector< trait_t > _traits; // which traits are selected
112  vector< unsigned int > _trait_index;
113  string _format;
114  string _logtime;
117  double _trim_maf;
118 
119 public:
121 
122  virtual ~GenotyperFH() {}
123 
124  virtual void FHwrite();
125  virtual void FHread (string& filename) {}
126 
127  void setTraits (vector< trait_t >& traits);
128 
129  void setTraitIndex (vector< unsigned int>& indices);
130 
131  void setFormat (string format) {_format = format;}
132 
133  void setLogtime (string logtime) {_logtime = logtime;}
134 
135  void set_isDiallelic (bool test) {_is_diallelic = test;}
136 
137  void set_trimFixedLoci (bool test, double maf) {_trim_loci = test; _trim_maf = maf;}
138 
139  void prepare_data_table (map< unsigned int, vector<unsigned int> >& trait_locus, vector<string>& col_names);
140  void collate_trait_map_positions (vector< unsigned int >& positions, map< unsigned int, vector<unsigned int> >& table);
141  void print_genotypes (ofstream& FH, map< unsigned int, vector<unsigned int> >& table);
142  void print_snp_genotypes (ofstream& FH, map< unsigned int, vector<unsigned int> >& table);
143  void print_snp_id (ofstream& FH, map< unsigned int, vector<unsigned int> >& table);
144  void print_map_positions (ofstream& FH, vector< unsigned int >& positions, vector<string>& col_names);
145 };
146 
147 // ----------------------------------------------------------------------------------------
148 
149 // LCE_StatFH
150 //
152 class LCE_StatFH : public FileHandler {
153 
155 
156 public:
157 
159 : FileHandler(".txt"), _statService(0)
160 {
161  FileHandler::set(false,false,0,0,0,"");
162  set_isMasterExec(true);
163 }
164 
165  ~LCE_StatFH() { };
166 
167  virtual vector< string > ifExist();
168 
170 
171  virtual void FHwrite();
172  virtual void FHread (string& filename) {}
173 
174  void PrintStat_byGen ( );
175 };
176 
177 
178 // LCE_StatServiceNotifier
179 //
183 {
184 
186 
187  unsigned int _occurrence;
188 
189  string _arg, _dir;
190 
192 
193 public:
194 
196 
197  virtual ~LCE_StatServiceNotifier ( ) { }
198 
200  bool setOccurence ();
201  bool dummyUpdate (){return true;}
202 
203  virtual bool setParameters ();
204  virtual void execute ();
205 
207 
208  //SimComponent overrides:
209  virtual void loadFileServices ( FileServices* loader ) {loader->attach(&_fileHandler);}
210  virtual void loadStatServices ( StatServices* loader );
211  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
212  virtual age_t removeAgeClass ( ) {return 0;}
213  virtual age_t addAgeClass ( ) {return 0;}
214  virtual age_t requiredAgeClass () {return 0;}
215 
216 };
Template class for the LCEs StatHandler classes.
Definition: filehandler.h:257
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:52
void set_isMasterExec(bool is)
Definition: filehandler.h:185
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:196
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60
FileHandler to write joint genotype files for multiple mappable traits.
Definition: servicenotifiers.h:109
GenotyperFH(LCE_FileServicesNotifier *event)
Definition: servicenotifiers.h:120
virtual ~GenotyperFH()
Definition: servicenotifiers.h:122
virtual void FHwrite()
Definition: servicenotifiers.cc:398
void setLogtime(string logtime)
Definition: servicenotifiers.h:133
void prepare_data_table(map< unsigned int, vector< unsigned int > > &trait_locus, vector< string > &col_names)
Definition: servicenotifiers.cc:503
bool _is_diallelic
Definition: servicenotifiers.h:115
void collate_trait_map_positions(vector< unsigned int > &positions, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:480
double _trim_maf
Definition: servicenotifiers.h:117
string _format
Definition: servicenotifiers.h:113
void set_trimFixedLoci(bool test, double maf)
Definition: servicenotifiers.h:137
void setTraits(vector< trait_t > &traits)
Definition: servicenotifiers.cc:384
void setFormat(string format)
Definition: servicenotifiers.h:131
virtual void FHread(string &filename)
Definition: servicenotifiers.h:125
vector< unsigned int > _trait_index
Definition: servicenotifiers.h:112
vector< trait_t > _traits
Definition: servicenotifiers.h:111
void setTraitIndex(vector< unsigned int > &indices)
Definition: servicenotifiers.cc:391
void set_isDiallelic(bool test)
Definition: servicenotifiers.h:135
string _logtime
Definition: servicenotifiers.h:114
void print_snp_genotypes(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:639
bool _trim_loci
Definition: servicenotifiers.h:116
void print_map_positions(ofstream &FH, vector< unsigned int > &positions, vector< string > &col_names)
void print_genotypes(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:593
void print_snp_id(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:685
Event used to notify all file handlers to update their state through the FileServices::notify() inter...
Definition: servicenotifiers.h:72
unsigned int _sample_patch_num
Definition: servicenotifiers.h:76
TMatrix _sample_age
Definition: servicenotifiers.h:78
TMatrix _sample_size
Definition: servicenotifiers.h:77
virtual void loadStatServices(StatServices *loader)
Definition: servicenotifiers.h:96
LCE_FileServicesNotifier()
Definition: servicenotifiers.cc:62
bool setSamplingParameters()
Definition: servicenotifiers.cc:133
TMatrix _sample_patch
Definition: servicenotifiers.h:75
virtual void loadFileServices(FileServices *loader)
Definition: servicenotifiers.cc:348
virtual bool setParameters()
Definition: servicenotifiers.cc:93
virtual age_t removeAgeClass()
Definition: servicenotifiers.h:98
FileServices * _service
Definition: servicenotifiers.h:74
virtual ~LCE_FileServicesNotifier()
Definition: servicenotifiers.cc:82
virtual void execute()
Definition: servicenotifiers.cc:366
virtual age_t requiredAgeClass()
Definition: servicenotifiers.h:100
bool setGenotyperParameters()
Definition: servicenotifiers.cc:232
virtual age_t addAgeClass()
Definition: servicenotifiers.h:99
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: servicenotifiers.h:97
vector< GenotyperFH * > _genotypers
Definition: servicenotifiers.h:80
virtual LifeCycleEvent * clone()
Definition: servicenotifiers.h:92
Calls the UpdaterServices to notify its components of a generation change.
Definition: servicenotifiers.h:40
void setManager(UpdaterServices *mng)
Definition: servicenotifiers.h:50
virtual LifeCycleEvent * clone()
Definition: servicenotifiers.h:54
virtual ~LCE_ParamUpdaterNotifier()
Definition: servicenotifiers.h:48
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: servicenotifiers.h:60
LCE_ParamUpdaterNotifier()
Definition: servicenotifiers.h:47
virtual void loadFileServices(FileServices *loader)
Definition: servicenotifiers.h:57
virtual bool setParameters()
Definition: servicenotifiers.h:52
virtual void loadUpdaters(UpdaterServices *loader)
Definition: servicenotifiers.h:59
UpdaterServices * _manager
Definition: servicenotifiers.h:43
virtual age_t requiredAgeClass()
Definition: servicenotifiers.h:63
virtual age_t removeAgeClass()
Definition: servicenotifiers.h:61
virtual void loadStatServices(StatServices *loader)
Definition: servicenotifiers.h:58
virtual void execute()
Definition: servicenotifiers.cc:45
virtual age_t addAgeClass()
Definition: servicenotifiers.h:62
FileHandler of the LCE_StatServiceNotifier class, writes the recorded stats to txt files.
Definition: servicenotifiers.h:152
virtual void FHread(string &filename)
Definition: servicenotifiers.h:172
virtual vector< string > ifExist()
Definition: servicenotifiers.cc:893
~LCE_StatFH()
Definition: servicenotifiers.h:165
LCE_StatFH()
Definition: servicenotifiers.h:158
StatServices * _statService
Definition: servicenotifiers.h:154
virtual void FHwrite()
Definition: servicenotifiers.cc:928
void PrintStat_byGen()
Definition: servicenotifiers.cc:965
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:169
Initiates the StatServices' parameters (log time) when registering, calls StatServices::notify() when...
Definition: servicenotifiers.h:183
virtual age_t addAgeClass()
Definition: servicenotifiers.h:213
virtual age_t requiredAgeClass()
Definition: servicenotifiers.h:214
FileHandler & getFH()
Definition: servicenotifiers.h:199
virtual void execute()
Definition: servicenotifiers.cc:878
string _dir
Definition: servicenotifiers.h:189
virtual void loadStatServices(StatServices *loader)
Definition: servicenotifiers.cc:858
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:191
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:733
virtual void loadFileServices(FileServices *loader)
Definition: servicenotifiers.h:209
bool setOccurence()
Definition: servicenotifiers.cc:805
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: servicenotifiers.h:211
unsigned int _occurrence
Definition: servicenotifiers.h:187
string _arg
Definition: servicenotifiers.h:189
virtual bool setParameters()
Definition: servicenotifiers.cc:761
virtual age_t removeAgeClass()
Definition: servicenotifiers.h:212
StatServices * _service
Definition: servicenotifiers.h:185
bool dummyUpdate()
Definition: servicenotifiers.h:201
virtual ~LCE_StatServiceNotifier()
Definition: servicenotifiers.h:197
virtual LCE_StatServiceNotifier * clone()
Definition: servicenotifiers.h:206
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
The Service class used to manage the StatHandler objects.
Definition: statservices.h:49
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
Class to update the simulation components' state during a simulation.
Definition: updaterservices.h:63
Nemo2.
unsigned int age_t
Age class flags.
Definition: types.h:45

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR