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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR