Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TProtoNeutralGenes Class Reference

Prototype class for the TTNeutralGenes trait class. More...

#include <ttneutralgenes.h>

+ Inheritance diagram for TProtoNeutralGenes:
+ Collaboration diagram for TProtoNeutralGenes:

Public Member Functions

 TProtoNeutralGenes ()
 
 TProtoNeutralGenes (const TProtoNeutralGenes &T)
 
virtual ~TProtoNeutralGenes ()
 
unsigned int get_ploidy ()
 
unsigned int get_locus_num ()
 
unsigned int get_allele_num ()
 
double get_mut_rate ()
 
unsigned int get_genome_size ()
 
unsigned int get_num_mutations ()
 
unsigned int get_init_model ()
 
TTNeutralGenesSHget_stater ()
 
void inherit_low (sex_t SEX, unsigned char *seq, const unsigned char **parent)
 
void inherit_free (sex_t SEX, unsigned char *seq, const unsigned char **parent)
 
TraitPrototype implementations
virtual void init ()
 
virtual void reset ()
 
virtual TTNeutralGeneshatch ()
 
virtual TProtoNeutralGenesclone ()
 
virtual trait_t get_type () const
 
virtual int get_phenotype_dimension ()
 
virtual int get_allele_number ()
 
virtual int get_locus_number ()
 Returns the number of locus. More...
 
SimComponent implementation
virtual bool setParameters ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
StorableComponent implementation
virtual void store_data (BinaryStorageBuffer *saver)
 
virtual bool retrieve_data (BinaryStorageBuffer *reader)
 
- Public Member Functions inherited from TTProtoWithMap
 TTProtoWithMap ()
 
 TTProtoWithMap (const TTProtoWithMap &TP)
 
virtual ~TTProtoWithMap ()
 
void setMapIndex (unsigned int idx)
 
unsigned int getMapIndex ()
 
double getRecombRate () const
 
bool setGeneticMapParameters (string prefix, unsigned int numLoci=0)
 
void addGeneticMapParameters (string prefix)
 
bool setRecombinationMapRandom ()
 
bool setRecombinationMapNonRandom (vector< vector< double > > &lociPositions)
 
bool setRecombinationMapFixed ()
 
bool setNumLociPerChromosome (string param_name)
 
void reset_recombination_pointers ()
 
void registerGeneticMap ()
 
void unregisterFromGeneticMap ()
 
bool areGeneticMapParamSet (string prefix)
 
bool isRecombinationFree (string prefix)
 
void recordRandomMap ()
 
virtual bool is_mappable ()
 Checks if the trait is mappable, i.e., if the loci can be placed on a genetic map. More...
 
virtual bool is_mapped ()
 Checks if the trait's loci are placed on a genetic map. More...
 
virtual vector< unsigned int > get_locus_map_positions ()
 Returns the map positions of the loci in vector. More...
 
- Public Member Functions inherited from TraitPrototype
virtual void set_index (int idx)
 Sets the traits index. More...
 
virtual int get_index ()
 Index getter. More...
 
- Public Member Functions inherited from StorableComponent
virtual ~StorableComponent ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 Sets a new ParamSet and name it. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Private Attributes

unsigned int _allele_num
 
unsigned int _locus_num
 
unsigned int _ploidy
 
double _mut_rate
 
int _mut_model
 
unsigned int _2L
 
unsigned int _init_model
 
double _recomb_rate
 
void(TTNeutralGenes_byte::* _mutate_func_ptr )(void)
 
void(TProtoNeutralGenes::* _inherit_func_ptr )(sex_t, unsigned char *, const unsigned char **)
 
vector< TTNeutralGenesFH * > _writers
 
TTNOhtaStats_ohtaStats
 
TTNeutralGenesSH_stats
 
const trait_t _type
 

Additional Inherited Members

- Static Public Member Functions inherited from TTProtoWithMap
static GeneticMapgetGeneticMapRef ()
 
static void recombine (unsigned long indID)
 
- Static Public Attributes inherited from TTProtoWithMap
static GeneticMap _map
 
- Protected Attributes inherited from TTProtoWithMap
unsigned int _mapIndex
 
double _totRecombEventsMean
 
double _recombRate
 
double _mapResolution
 
unsigned int _numChromosome
 
unsigned int _numLoci
 
double * _recombRatePerChrmsm
 
unsigned int * _numLociPerChrmsm
 
unsigned int * _chrsmLength
 
unsigned int * _lociMapPositions
 
- Protected Attributes inherited from TraitPrototype
int _index
 The trait index in the Individual traits table. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

Prototype class for the TTNeutralGenes trait class.

Constructor & Destructor Documentation

◆ TProtoNeutralGenes() [1/2]

TProtoNeutralGenes::TProtoNeutralGenes ( )
51  :_allele_num(0), _locus_num(0), _ploidy(2), _mut_rate(0),
53  _ohtaStats(0),_stats(0), _type(NTRL)
54 {
55  set_paramset("neutralgenes", false, this);
56 
57  add_parameter("ntrl_loci", INT, true, false, 0, 0);
58  add_parameter("ntrl_init_model", INT, false, true, 0, 2);
59  add_parameter("ntrl_all", INT, true, true, 2, 256);
60  add_parameter("ntrl_mutation_rate", DBL, true, true, 0, 1);
61  add_parameter("ntrl_mutation_model", INT, true, true, 0, 2);
62 
63  //genetic map parameters:
65 
66  //output
67  add_parameter("ntrl_save_genotype", STR, false, false, 0, 0);
68  add_parameter("ntrl_save_fsti", BOOL, false, false, 0, 0);
69  add_parameter("ntrl_save_freq", STR, false, false, 0, 0);
70  add_parameter("ntrl_output_dir", STR, false, false, 0, 0);
71  add_parameter("ntrl_output_logtime", INT, false, false, 0, 0);
72  add_parameter("ntrl_ohta_output", BOOL,false,false,0,0);
73  add_parameter("ntrl_ohta_logtime", INT,false,false,0,0);
74 }
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:85
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
TTNOhtaStats * _ohtaStats
Definition: ttneutralgenes.h:186
TTNeutralGenesSH * _stats
Definition: ttneutralgenes.h:187
unsigned int _allele_num
Definition: ttneutralgenes.h:174
const trait_t _type
Definition: ttneutralgenes.h:188
double _mut_rate
Definition: ttneutralgenes.h:177
unsigned int _2L
Definition: ttneutralgenes.h:179
double _recomb_rate
Definition: ttneutralgenes.h:181
unsigned int _locus_num
Definition: ttneutralgenes.h:175
void(TProtoNeutralGenes::* _inherit_func_ptr)(sex_t, unsigned char *, const unsigned char **)
Definition: ttneutralgenes.h:183
unsigned int _ploidy
Definition: ttneutralgenes.h:176
unsigned int _init_model
Definition: ttneutralgenes.h:180
int _mut_model
Definition: ttneutralgenes.h:178
void(TTNeutralGenes_byte::* _mutate_func_ptr)(void)
Definition: ttneutralgenes.h:182
void addGeneticMapParameters(string prefix)
Definition: ttrait_with_map.cc:77
#define NTRL
Definition: types.h:69
@ DBL
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

References SimComponent::add_parameter(), TTProtoWithMap::addGeneticMapParameters(), BOOL, DBL, INT, SimComponent::set_paramset(), and STR.

Referenced by clone().

+ Here is the caller graph for this function:

◆ TProtoNeutralGenes() [2/2]

TProtoNeutralGenes::TProtoNeutralGenes ( const TProtoNeutralGenes T)
82  _ohtaStats(0)
83 {
84  _paramSet = new ParamSet( *(T._paramSet) ) ;
85 }
Parameters container, implemented in each SimComponent.
Definition: param.h:205
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47

References SimComponent::_paramSet.

◆ ~TProtoNeutralGenes()

TProtoNeutralGenes::~TProtoNeutralGenes ( )
virtual
90 {
91  if(_stats != NULL) {delete _stats; _stats = NULL;}
92  for(unsigned int i = 0; i < _writers.size(); i++)
93  delete _writers[i];
94  _writers.clear();
95 
96  if(_ohtaStats) delete _ohtaStats;
97 }
vector< TTNeutralGenesFH * > _writers
Definition: ttneutralgenes.h:185

References _ohtaStats, _stats, and _writers.

Member Function Documentation

◆ clone()

virtual TProtoNeutralGenes* TProtoNeutralGenes::clone ( )
inlinevirtual

Implements TraitPrototype.

219 {return new TProtoNeutralGenes(*this);}
TProtoNeutralGenes()
Definition: ttneutralgenes.cc:51

References TProtoNeutralGenes().

◆ get_allele_num()

◆ get_allele_number()

virtual int TProtoNeutralGenes::get_allele_number ( )
inlinevirtual

Implements TraitPrototype.

225 {return _allele_num;}

References _allele_num.

◆ get_genome_size()

unsigned int TProtoNeutralGenes::get_genome_size ( )
inline
202 {return _2L;}

References _2L.

◆ get_init_model()

unsigned int TProtoNeutralGenes::get_init_model ( )
inline
204 {return _init_model;}

References _init_model.

Referenced by TTNeutralGenes_byte::init_sequence().

+ Here is the caller graph for this function:

◆ get_locus_num()

unsigned int TProtoNeutralGenes::get_locus_num ( )
inline
199 {return _locus_num;}

References _locus_num.

Referenced by TTNeutralGenesFH::FHread(), TTNOhtaStats::FHwrite(), TTNeutralGenes_byte::get_allele(), TTNeutralGenes_byte::get_allele_value(), TTNeutralGenesSH::getDxyPerPatch(), TTNeutralGenes_byte::init(), TTNeutralGenesSH::init(), TTNeutralGenes_byte::init_sequence(), TTNeutralGenes_byte::mutate_2all(), TTNeutralGenes_byte::mutate_KAM(), TTNeutralGenes_byte::mutate_SSM(), TTNeutralGenes_byte::operator=(), TTNeutralGenes::operator==(), TTNeutralGenesFH::print_PLINK_PED(), TTNeutralGenes_byte::retrieve_data(), TTNeutralGenes_byte::set_sequence(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setFreqRecorders(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstat(), TTNeutralGenesSH::setFstat_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_bitstring(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setHeteroTable(), TTNeutralGenesSH::setHeterozygosity(), TTNeutralGenesSH::setHo(), TTNeutralGenesSH::setHo2(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTNeutralGenesSH::setHt(), TTNeutralGenesSH::setHt2(), TTNeutralGenesSH::setLociDivCounter(), TTNeutralGenesSH::setNeiGeneticDistance(), LCE_NtrlInit::setParameters(), TTNeutralGenes_byte::show_up(), TTNeutralGenes_byte::store_data(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_patch_FSTAT(), TTNeutralGenesFH::write_patch_GENEPOP(), TTNeutralGenesFH::write_patch_TAB(), TTNeutralGenesFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().

◆ get_locus_number()

virtual int TProtoNeutralGenes::get_locus_number ( )
inlinevirtual

Returns the number of locus.

Implements TraitPrototype.

227 {return _locus_num;}

References _locus_num.

◆ get_mut_rate()

double TProtoNeutralGenes::get_mut_rate ( )
inline
201 {return _mut_rate;}

References _mut_rate.

◆ get_num_mutations()

unsigned int TProtoNeutralGenes::get_num_mutations ( )
inline
203 {return RAND::Binomial( _mut_rate, _2L );}
static double Binomial(double p, unsigned int n)
Definition: Uniform.h:489

References _2L, _mut_rate, and RAND::Binomial().

Referenced by TTNeutralGenes_byte::mutate_2all(), TTNeutralGenes_byte::mutate_KAM(), and TTNeutralGenes_byte::mutate_SSM().

+ Here is the caller graph for this function:

◆ get_phenotype_dimension()

virtual int TProtoNeutralGenes::get_phenotype_dimension ( )
inlinevirtual

Implements TraitPrototype.

223 {return 0;}

◆ get_ploidy()

◆ get_stater()

TTNeutralGenesSH* TProtoNeutralGenes::get_stater ( )
inline
206 {return _stats;}

References _stats.

Referenced by TTNeutralGenesFH::write_Fst_i(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ get_type()

virtual trait_t TProtoNeutralGenes::get_type ( ) const
inlinevirtual

Implements TraitPrototype.

221 {return _type;}

References _type.

Referenced by TTNeutralGenesFH::write_PLINK().

+ Here is the caller graph for this function:

◆ hatch()

TTNeutralGenes * TProtoNeutralGenes::hatch ( )
virtual

Implements TraitPrototype.

377 {
378  TTNeutralGenes* kid;
379 
380  if (_allele_num == 2) {
381  kid = new TTNeutralGenes_bitstring();
382  } else {
386  kid = bkid;
387  }
388 
389  kid->set_proto(this);
390 
391  return kid;
392 }
TTNeutralGenes_bitstring : diallelic neutral loci encoded as bitstrings.
Definition: ttneutralgenes_bitstring.h:39
Byte-encoded neutral gene trait (unsigned char per allele).
Definition: ttneutralgenes.h:110
void set_inherit_func_ptr(void(TProtoNeutralGenes::*theFunc)(sex_t, unsigned char *, const unsigned char **))
Definition: ttneutralgenes.h:132
void set_mut_func_ptr(void(TTNeutralGenes_byte::*theFunc)(void))
Definition: ttneutralgenes.h:130
Abstract base class for neutral gene traits.
Definition: ttneutralgenes.h:56
void set_proto(TProtoNeutralGenes *proto)
Definition: ttneutralgenes.h:73

References _allele_num, _inherit_func_ptr, _mutate_func_ptr, TTNeutralGenes_byte::set_inherit_func_ptr(), TTNeutralGenes_byte::set_mut_func_ptr(), and TTNeutralGenes::set_proto().

◆ inherit_free()

void TProtoNeutralGenes::inherit_free ( sex_t  SEX,
unsigned char *  seq,
const unsigned char **  parent 
)
inline
397 {
398  for(unsigned int i = 0; i < _locus_num; ++i)
399  seq[i] = parent[RAND::RandBool()][i];
400 }
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:164

References _locus_num, and RAND::RandBool().

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ inherit_low()

void TProtoNeutralGenes::inherit_low ( sex_t  SEX,
unsigned char *  seq,
const unsigned char **  parent 
)
inline
405 {
406  unsigned int prevLoc = 0, cEnd;
407 
408  vector< pair<unsigned int, unsigned int> > recTable = _map.reduceJunctions(SEX, _mapIndex);
409 
410  //number of x-overs
411  unsigned int nbRec = recTable.size();
412 
413 #ifdef _REC_DEBUG_
414  cout << "TProtoNeutralGenes::inherit_low; nb Rec = "<<nbRec - 1<<endl;
415  cout << " --sex = "<<SEX<<"\n";
416 #endif
417 
418 
419  vector< pair<unsigned int, unsigned int> >::const_iterator xover = recTable.begin();
420 
421  while(xover != recTable.end()) {
422 
423 #ifdef _REC_DEBUG_
424  cout<< " copy seq from "<<prevLoc<<" to "<<xover->first
425  <<" ("<<(xover->first - prevLoc)<<" loc) ("
426  <<(xover->first - prevLoc)<<"B) on side "<<xover->second<<std::endl;
427 #endif
428 
429  memcpy(&seq[prevLoc], &parent[xover->second][prevLoc], (xover->first - prevLoc));
430 
431  prevLoc = xover->first;
432 
433  xover++;
434  }
435 
436 #ifdef _REC_DEBUG_
437  // cout << "parent chromosomes:\n --0:";
438  // unsigned int loc = 0;
439  // for (unsigned int c = 0; c < _numChromosome; ++c) {
440  // cout<<" ";
441  // for(unsigned int i = 0; i < _numLociPerChrmsm[c] && loc < _locus_num; ++i)
442  // cout << (int)parent[0][loc++];
443  // }
444  // cout << "\n --1:";
445  // loc = 0;
446  // for (unsigned int c = 0; c < _numChromosome; ++c) {
447  // cout<<" ";
448  // for(unsigned int i = 0; i < _numLociPerChrmsm[c] && loc < _locus_num; ++i)
449  // cout << (int)parent[1][loc++];
450  // }
451  //
452  // cout << "\ngamete:\n --0:";
453  // loc = 0;
454  // for (unsigned int c = 0; c < _numChromosome; ++c) {
455  // cout<<" ";
456  // for(unsigned int i = 0; i < _numLociPerChrmsm[c] && loc < _locus_num; ++i)
457  // cout << (int)seq[loc++];
458  // }
459  // cout << "\n\n";
460 #endif
461 
462 }
vector< pair< unsigned int, unsigned int > > reduceJunctions(sex_t SEX, unsigned int trait_idx)
Remove multiple x-over at the same locus when traits differ in number of loci.
Definition: ttrait_with_map.cc:1209
static GeneticMap _map
Definition: ttrait_with_map.h:208
unsigned int _mapIndex
Definition: ttrait_with_map.h:192

References TTProtoWithMap::_map, TTProtoWithMap::_mapIndex, and GeneticMap::reduceJunctions().

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ init()

virtual void TProtoNeutralGenes::init ( )
inlinevirtual
213 {}

◆ loadFileServices()

void TProtoNeutralGenes::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

162 {
163  TTNeutralGenesFH* writer;
164 
165  if(_writers.size() != 0) {
166  for(unsigned int i = 0; i < _writers.size(); i++)
167  delete _writers[i];
168  _writers.clear();
169  }
170 
171  // --- THE READER ---
172  // note that this reader only reads in FSTAT format
173  //always add the reader:
174  //NOTE: the default extension is ".txt", will not accept ".dat" FSTAT files in input
175  writer = new TTNeutralGenesFH(this);
176 
177  //set to read mode:
178  writer->set_isInputHandler(true);
179 
180  //attach to file manager:
181  loader->attach_reader(writer);
182 
183  //add to list of FileHandlers, will be deleted upon destruction
184  _writers.push_back( writer );
185 
186  // Add a reader for ".dat" FSTAT files:
187  writer = new TTNeutralGenesFH(this);
188  writer->set_isInputHandler(true);
189  writer->set_extension(".dat");
190  loader->attach_reader(writer);
191 
192  _writers.push_back( writer );
193 
194  // --- WRITERS ---
195  Param* param_logtime = get_parameter("ntrl_output_logtime");
196 
197  TMatrix logtime_matrix;
198  bool logtime_isMatrix = 0;
199 
200  if(param_logtime->isMatrix()) {
201  param_logtime->getMatrix(&logtime_matrix);
202  logtime_isMatrix = 1;
203  }
204 
205  if( get_parameter("ntrl_save_genotype")->isSet() ) {
206 
207  if(!param_logtime->isSet() )
208  fatal("ntrl trait::parameter \"ntrl_output_logtime\" is required to set the periodicity of the output file\n");
209 
210  // create a new File handler:
211  writer = new TTNeutralGenesFH(this);
212 
213  if(logtime_isMatrix)
214  writer->set_multi(true, true, 1, &logtime_matrix, get_parameter("ntrl_output_dir")->getArg(), this);
215 
216  else
217  writer->set(true, param_logtime->isSet(), 1, (int)param_logtime->getValue(), 0, get_parameter("ntrl_output_dir")->getArg(), this);
218  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
219 
220  // check the output file type
221  string file_type = get_parameter("ntrl_save_genotype")->getArg();
222 
223  // lowercase the arg string:
224  std::for_each(file_type.begin(), file_type.end(), [](char& c){c = ::tolower(c);});
225 
226  if(file_type.length() == 0 || //default mode is tabular
227  file_type == "tab")
228  {
229  writer->setOutputOption("allele");
231  }
232  else if(file_type == "snp_tab")
233  {
234  writer->setOutputOption("snp");
236  }
237  else if(file_type == "fstat")
238  {
239 
241  writer->set_extension(".dat");
242 
243  }
244  else if(file_type == "genepop")
245  {
247  }
248  else if(file_type == "plink")
249  {
251  }
252 
253  else
254  fatal("parameter \"ntrl_save_genotype\" options are \"TAB\", \"SNP_TAB\", \"FSTAT\", \"GENEPOP\" or \"PLINK\".\n");
255 
256  loader->attach(writer);
257 
258  _writers.push_back( writer );
259  }
260 
261  // new writer
262  if( get_parameter("ntrl_save_fsti")->isSet() ) {
263 
264  writer = new TTNeutralGenesFH(this);
265 
266  if(logtime_isMatrix)
267  writer->set_multi(true, true, 1, &logtime_matrix, get_parameter("ntrl_output_dir")->getArg(), this);
268  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
269  else writer->set(true, param_logtime->isSet(), 1, (int)param_logtime->getValue(), 0, get_parameter("ntrl_output_dir")->getArg(), this);
270 
272 
273  writer->set_extension(".fsti");
274 
275  loader->attach(writer);
276 
277  _writers.push_back( writer );
278  }
279 
280  // new writer
281  if( get_parameter("ntrl_save_freq")->isSet() ) {
282 
283  writer = new TTNeutralGenesFH(this);
284 
285  writer->set_extension(".freq");
286 
287  if (logtime_isMatrix)
288  writer->set_multi(true, true, 1, &logtime_matrix, get_parameter("ntrl_output_dir")->getArg(), this);
289  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
290  else writer->set(true, param_logtime->isSet(), 1, (int)param_logtime->getValue(), 0, get_parameter("ntrl_output_dir")->getArg(), this);
291 
292  //check validity of output option:
293 
294  if(get_parameter("ntrl_save_freq")->getArg() == "allfreq") {
295 
296  warning("option \"allfreq\" to \"ntrl_save_freq\" is deprecated, using \"locus\" instead\n");
297 
298  writer->setOutputOption("locus");
299 
300  } else if(get_parameter("ntrl_save_freq")->getArg() == "vcomp") {
301 
302  warning("option \"vcomp\" to \"ntrl_save_freq\" is deprecated, using \"allele\" instead\n");
303 
304  writer->setOutputOption("allele");
305 
306  } else if( get_parameter("ntrl_save_freq")->getArg() != "1" &&
307  get_parameter("ntrl_save_freq")->getArg() != "locus" &&
308  get_parameter("ntrl_save_freq")->getArg() != "allele") {
309 
310  fatal("parameter \"ntrl_save_freq\" options are \"locus\" or \"allele\".\n");
311 
312  } else
313  writer->setOutputOption(get_parameter("ntrl_save_freq")->getArg());
314 
316 
317  loader->attach(writer);
318 
319  _writers.push_back( writer );
320  }
321 
322 
323  // Ohta's (1982) D statistics
324  if(get_parameter("ntrl_ohta_output")->isSet()) {
325 
326  // Output Ohta stats :
327  // Only if pop alive
328  // Only for diallelic mutation models
329  // Only for multi-population scenarios
330  if ((_allele_num > 2) || (SIMenv::MainSim->get_pop()->getPatchNbr() < 2)) {
331  fatal("output option \"ntrl_ohta_output\" is only valid for diallelic neutral markers and multiple patches!\n");
332  }
333 
334  if(_ohtaStats == NULL) _ohtaStats = new TTNOhtaStats(this);
335 
336  Param* param = get_parameter("ntrl_ohta_logtime");
337 
338  if(!param->isSet() )
339  fatal("ntrl trait::parameter \"ntrl_ohta_logtime\" is required to set the periodicity of the output file\n");
340 
341  if(param->isMatrix()) {
342 
343  TMatrix temp;
344  param->getMatrix(&temp);
345  _ohtaStats->set_multi(true, true, 1, &temp, get_parameter("ntrl_output_dir")->getArg(), this);
346 
347  } else // rpl_per, gen_per, rpl_occ, gen_occ, rank (0), path, self-ref
348  _ohtaStats->set(true, true, 1, (int)param->getValue(),
349  0, get_parameter("ntrl_output_dir")->getArg(),this);
350 
351  loader->attach(_ohtaStats);
352  }
353  else if(_ohtaStats != NULL) {
354  delete _ohtaStats;
355  _ohtaStats = NULL;
356  }
357 
358 }
void set_extension(const char *ext)
Definition: filehandler.h:148
void set_isInputHandler(bool val)
Definition: filehandler.h:154
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:73
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
double getValue()
Returns the argument value according to its type.
Definition: param.cc:367
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:171
string getArg()
Definition: param.h:137
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:377
bool isSet()
Definition: param.h:139
static SimRunner * MainSim
Definition: simenv.h:41
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
TTNOhtaStats.
Definition: ttneutralgenes.h:300
A file handler to save the neutral markers genotypes in the FSTAT format (extended).
Definition: ttneutralgenes.h:261
void write_GENEPOP()
Definition: ttneutralgenes.cc:1123
void write_Fst_i()
Definition: ttneutralgenes.cc:1396
void setOutputOption(string opt)
Definition: ttneutralgenes.cc:759
void write_FSTAT()
Definition: ttneutralgenes.cc:1042
void write_TAB()
Definition: ttneutralgenes.cc:789
void write_varcompWC()
Definition: ttneutralgenes.cc:1462
void write_PLINK()
Definition: ttneutralgenes.cc:885
void set_write_fct(void(TTNeutralGenesFH::*fct_ptr)())
Definition: ttneutralgenes.h:291
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path, TP *trait_proto)
Definition: filehandler.h:247
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, TP *trait_proto)
Definition: filehandler.h:240
void fatal(const char *str,...)
Definition: output.cc:99
void warning(const char *str,...)
Definition: output.cc:57

References _allele_num, _ohtaStats, _writers, FileServices::attach(), FileServices::attach_reader(), fatal(), SimComponent::get_parameter(), Param::getArg(), Param::getMatrix(), Param::getValue(), Param::isMatrix(), Param::isSet(), SIMenv::MainSim, TraitFileHandler< TP >::set(), FileHandler::set_extension(), FileHandler::set_isInputHandler(), TraitFileHandler< TP >::set_multi(), TTNeutralGenesFH::set_write_fct(), TTNeutralGenesFH::setOutputOption(), warning(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().

◆ loadStatServices()

void TProtoNeutralGenes::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

363 {
364  //allocate the stat handler
365  if(_stats) delete _stats;
366 
367  // this makes sure that the trait index is reset correctly between simulations
368  _stats = new TTNeutralGenesSH(this);
369 
370  loader->attach(_stats);
371 
372 }
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:176
The stat handler for neutral markers.
Definition: ttneutralgenes.h:320

References _stats, and StatServices::attach().

◆ reset()

virtual void TProtoNeutralGenes::reset ( )
inlinevirtual

Reimplemented from TTProtoWithMap.

virtual void reset()
Definition: ttrait_with_map.cc:637

References TTProtoWithMap::reset().

◆ resetParameterFromSource()

bool TProtoNeutralGenes::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
virtual

Implements SimComponent.

478 {
479  TProtoNeutralGenes *srcProto = dynamic_cast< TProtoNeutralGenes* >(cmpt);
480 
481  if( param != "ntrl_genetic_map" ) return false;
482 
483  Param *srcMap = srcProto->get_parameter(param);
484 
485  if(!srcMap->isSet()) return error("parameter \"ntrl_genetic_map\" not set in source.\n");
486 
487 
488  //@TODO need to implement a way to update the genetic map of a trait in GeneticMap
489  return false;
490 }
Prototype class for the TTNeutralGenes trait class.
Definition: ttneutralgenes.h:171
int error(const char *str,...)
Definition: output.cc:78

References error(), SimComponent::get_parameter(), and Param::isSet().

◆ retrieve_data()

bool TProtoNeutralGenes::retrieve_data ( BinaryStorageBuffer reader)
virtual

Implements StorableComponent.

467 {
468  unsigned int dummy;
469  reader->read(&dummy, sizeof(int));
470  if(dummy != _locus_num ){
471  warning("Neutral mutation trait::locus number in binary source file differs from parameter value!\n\
472  >>>> adjusting locus number to match source population: %i set to %i\n", _locus_num, dummy);
473  _locus_num = dummy;
474  }
475  return true;
476 }
void read(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:220

References _locus_num, BinaryStorageBuffer::read(), and warning().

◆ setParameters()

bool TProtoNeutralGenes::setParameters ( )
virtual

Implements SimComponent.

102 {
103  _locus_num = (unsigned int)get_parameter_value("ntrl_loci");
104  _allele_num = (unsigned int)get_parameter_value("ntrl_all");
105  _ploidy = 2;
106  _mut_rate = get_parameter_value("ntrl_mutation_rate");
107  _mut_model = (unsigned int)get_parameter_value("ntrl_mutation_model");
108  _2L = _ploidy * _locus_num; // genome size
109 
110  if(get_parameter("ntrl_init_model")->isSet())
111  _init_model = (unsigned short)get_parameter_value("ntrl_init_model");
112  else
113  _init_model = 1; //maximum variance
114 
115  switch(_mut_model) {
116  case 0:
117  {
119  break;
120  }
121  case 1:
122  {
124  break;
125  }
126  case 2:
127  {
129  break;
130  }
131  default:
132  {
133  return error("wrong parameter value for parameter \"ntrl_mutation_model\", max is 2\n");
134  break;
135  }
136  }
137  //special case:
139 
140  // we want to bypass the genetic map if loci are not linked
141  if( TTProtoWithMap::isRecombinationFree("ntrl")) { //test all possible options to set recomb rate = 0.5
142 
144 
146 
147  } else {
148 
149  // register the locus positions on the genetic map
150  if( ! TTProtoWithMap::setGeneticMapParameters ("ntrl") ) return false;
151 
153 
154  }
155 
156  return true;
157 }
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
void inherit_low(sex_t SEX, unsigned char *seq, const unsigned char **parent)
Definition: ttneutralgenes.cc:404
void inherit_free(sex_t SEX, unsigned char *seq, const unsigned char **parent)
Definition: ttneutralgenes.cc:396
void mutate_KAM()
Definition: ttneutralgenes.cc:721
void mutate_SSM()
Definition: ttneutralgenes.cc:698
void mutate_2all()
Definition: ttneutralgenes.cc:740
void mutate_NULL()
Definition: ttneutralgenes.h:142
double _recombRate
Definition: ttrait_with_map.h:194
bool setGeneticMapParameters(string prefix, unsigned int numLoci=0)
Definition: ttrait_with_map.cc:125
bool isRecombinationFree(string prefix)
Definition: ttrait_with_map.cc:98

References _2L, _allele_num, _inherit_func_ptr, _init_model, _locus_num, _mut_model, _mut_rate, _mutate_func_ptr, _ploidy, TTProtoWithMap::_recombRate, error(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), inherit_free(), inherit_low(), TTProtoWithMap::isRecombinationFree(), Param::isSet(), TTNeutralGenes_byte::mutate_2all(), TTNeutralGenes_byte::mutate_KAM(), TTNeutralGenes_byte::mutate_NULL(), TTNeutralGenes_byte::mutate_SSM(), and TTProtoWithMap::setGeneticMapParameters().

◆ store_data()

virtual void TProtoNeutralGenes::store_data ( BinaryStorageBuffer saver)
inlinevirtual

Implements StorableComponent.

243 {saver->store(&_locus_num,sizeof(int));}
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.cc:37

References _locus_num, and BinaryStorageBuffer::store().

Member Data Documentation

◆ _2L

unsigned int TProtoNeutralGenes::_2L
private

◆ _allele_num

unsigned int TProtoNeutralGenes::_allele_num
private

◆ _inherit_func_ptr

void(TProtoNeutralGenes::* TProtoNeutralGenes::_inherit_func_ptr) (sex_t, unsigned char *, const unsigned char **)
private

Referenced by hatch(), and setParameters().

◆ _init_model

unsigned int TProtoNeutralGenes::_init_model
private

Referenced by get_init_model(), and setParameters().

◆ _locus_num

unsigned int TProtoNeutralGenes::_locus_num
private

◆ _mut_model

int TProtoNeutralGenes::_mut_model
private

Referenced by setParameters().

◆ _mut_rate

double TProtoNeutralGenes::_mut_rate
private

◆ _mutate_func_ptr

void(TTNeutralGenes_byte::* TProtoNeutralGenes::_mutate_func_ptr) (void)
private

Referenced by hatch(), and setParameters().

◆ _ohtaStats

TTNOhtaStats* TProtoNeutralGenes::_ohtaStats
private

◆ _ploidy

unsigned int TProtoNeutralGenes::_ploidy
private

Referenced by get_ploidy(), and setParameters().

◆ _recomb_rate

double TProtoNeutralGenes::_recomb_rate
private

◆ _stats

TTNeutralGenesSH* TProtoNeutralGenes::_stats
private

◆ _type

const trait_t TProtoNeutralGenes::_type
private

Referenced by get_type().

◆ _writers

vector< TTNeutralGenesFH* > TProtoNeutralGenes::_writers
private

The documentation for this class was generated from the following files:

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