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

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

Locations of visitors to this page
Catalogued on GSR