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

TTProtoWithMap. More...

#include <ttrait_with_map.h>

+ Inheritance diagram for TTProtoWithMap:
+ Collaboration diagram for TTProtoWithMap:

Public Member Functions

 TTProtoWithMap ()
 
 TTProtoWithMap (const TTProtoWithMap &TP)
 
virtual ~TTProtoWithMap ()
 
void setMapIndex (unsigned int idx)
 
unsigned int getMapIndex ()
 
bool setGeneticMapParameters (string prefix)
 
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 void reset ()
 
- Public Member Functions inherited from TraitPrototype
virtual TTraithatch ()=0
 Creates the trait of which it is the prototype, called by IndFactory::makePrototype(). More...
 
virtual TraitPrototypeclone ()=0
 Returns a copy of itself. More...
 
virtual trait_t get_type () const =0
 Type accessor. More...
 
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 void store_data (BinaryStorageBuffer *saver)=0
 Interface to store the component data (e.g. gene values) into a binary buffer. More...
 
virtual bool retrieve_data (BinaryStorageBuffer *reader)=0
 Interface to retrieve the same data from the binary buffer. More...
 
virtual ~StorableComponent ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadFileServices (FileServices *loader)=0
 Loads the component's FileHandler onto the FileServices. More...
 
virtual void loadStatServices (StatServices *loader)=0
 Loads the component's StatHandler onto the StatServices. More...
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual bool setParameters ()=0
 Default interface needed to initialize the component's variables from its input parameters value. 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...
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)=0
 

Static Public Member Functions

static void recombine (unsigned long indID)
 

Static Public Attributes

static GeneticMap _map
 

Protected Attributes

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...
 

Private Attributes

string _paramPrefix
 
bool _isRegistered
 

Friends

class TTraitWithMap
 

Detailed Description

Constructor & Destructor Documentation

◆ TTProtoWithMap() [1/2]

TTProtoWithMap::TTProtoWithMap ( )
inline
216  {}
double _mapResolution
Definition: ttrait_with_map.h:196
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:202
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:201
double _recombRate
Definition: ttrait_with_map.h:195
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:199
unsigned int _numLoci
Definition: ttrait_with_map.h:198
double _totRecombEventsMean
Definition: ttrait_with_map.h:194
unsigned int _numChromosome
Definition: ttrait_with_map.h:197
bool _isRegistered
Definition: ttrait_with_map.h:188
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:200
unsigned int _mapIndex
Definition: ttrait_with_map.h:193

◆ TTProtoWithMap() [2/2]

TTProtoWithMap::TTProtoWithMap ( const TTProtoWithMap TP)
45  :
49 {
51 
52  _recombRatePerChrmsm = new double [_numChromosome];
53  for (unsigned int i = 0; i < _numChromosome; ++i)
55 
56  _numLociPerChrmsm = new unsigned int [_numChromosome];
57  for (unsigned int i = 0; i < _numChromosome; ++i)
59 
60  _chrsmLength = new unsigned int [_numChromosome];
61  for (unsigned int i = 0; i < _numChromosome; ++i)
62  _chrsmLength[i] = TP._chrsmLength[i];
63 
64  _lociMapPositions = new unsigned int [_numLoci];
65  for (unsigned int i = 0; i < _numLoci; ++i)
67 
68 }
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:602

References _chrsmLength, _lociMapPositions, _numChromosome, _numLoci, _numLociPerChrmsm, _recombRatePerChrmsm, and reset_recombination_pointers().

◆ ~TTProtoWithMap()

TTProtoWithMap::~TTProtoWithMap ( )
virtual

Member Function Documentation

◆ addGeneticMapParameters()

void TTProtoWithMap::addGeneticMapParameters ( string  prefix)
78 {
79  add_parameter(prefix + "_recombination_rate", DBL, false, true, 0, 0.5, 0);
80  add_parameter(prefix + "_genetic_map_resolution", DBL, false, false, 0, 0, 0);
81  add_parameter(prefix + "_chromosome_num_locus", MAT, false, false, 0, 0, 0);
82  add_parameter(prefix + "_genetic_map", MAT, false, false, 0, 0, 0);
83  add_parameter(prefix + "_random_genetic_map", MAT, false, false, 0, 0, 0);
84 }
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ DBL
Definition: types.h:78
@ MAT
Definition: types.h:78

References SimComponent::add_parameter(), DBL, and MAT.

Referenced by TProtoBDMI::TProtoBDMI(), TProtoDeletMutations_bitstring::TProtoDeletMutations_bitstring(), TProtoNeutralGenes::TProtoNeutralGenes(), and TProtoQuanti::TProtoQuanti().

◆ areGeneticMapParamSet()

bool TTProtoWithMap::areGeneticMapParamSet ( string  prefix)
89 {
90  if( get_parameter(prefix + "_recombination_rate")->isSet() ) return true;
91  else if( get_parameter(prefix + "_genetic_map")->isSet() ) return true;
92  else if( get_parameter(prefix + "_random_genetic_map")->isSet() ) return true;
93  else return false;
94 }
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139

References SimComponent::get_parameter().

Referenced by isRecombinationFree().

◆ getMapIndex()

unsigned int TTProtoWithMap::getMapIndex ( )
inline
224 {return _mapIndex;}

References _mapIndex.

◆ isRecombinationFree()

bool TTProtoWithMap::isRecombinationFree ( string  prefix)
99 {
100  if( ! areGeneticMapParamSet(prefix) ) return true; //recombination rate is 0.5 by default
101 
102  string param_name = prefix + "_recombination_rate";
103 
104  if( get_parameter(param_name)->isSet() ){
105 
106 
107  if( get_parameter(param_name)->isMatrix() ) {
108 
109  if(get_parameter(param_name)->getArg() == "{{0.5}}")
110  return true;
111  else
112  return false;
113 
114  } else if( get_parameter_value(param_name) == 0.5)
115  return true;
116  else
117  return false;
118  }
119 
120  return false;
121 }
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
bool areGeneticMapParamSet(string prefix)
Definition: ttrait_with_map.cc:88

References areGeneticMapParamSet(), SimComponent::get_parameter(), and SimComponent::get_parameter_value().

Referenced by TProtoQuanti::setGeneticMapParams(), TProtoBDMI::setParameters(), and TProtoNeutralGenes::setParameters().

◆ recombine()

void TTProtoWithMap::recombine ( unsigned long  indID)
static
593 {
594  if(!_map.registerIndForRecombine(indID)) return;
595 
596  _map.recombine(MAL);
597  _map.recombine(FEM);
598 }
void recombine(sex_t SEX)
Called by TTProtoWithMap::recombine twice to create the two gametes necessary for the creation of a n...
Definition: ttrait_with_map.cc:1075
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:144
static GeneticMap _map
Definition: ttrait_with_map.h:209
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References _map, FEM, MAL, GeneticMap::recombine(), and GeneticMap::registerIndForRecombine().

Referenced by Individual::recombine().

◆ recordRandomMap()

void TTProtoWithMap::recordRandomMap ( )
534 {
535  // record positions into genetic_map parameter,
536  // will be saved with other params in log file
537  ostringstream map;
538 
539  map<<"{";
540 
541  for (unsigned int c = 0, l = 0; c < _numChromosome; c++) {
542  map<<"{";
543 
544  for (unsigned int i = 0; i < _numLociPerChrmsm[c]-1 && l < _numLoci; i++) {
545  map<<_lociMapPositions[ l++ ]<<", ";
546  }
547  map<<_lociMapPositions[ l++ ];
548  map<<"}";
549  }
550  map<<"}";
551 
552  // record the position inthe genetic map parameter
553  Param* mapParam = get_parameter( _paramPrefix + "_genetic_map" );
554  mapParam->setArg(map.str());
555  mapParam->setIsSet(true);
556 
557  //disable the random map parameter
558  mapParam = get_parameter( _paramPrefix + "_random_genetic_map" );
559  mapParam->setIsSet(false);
560 
561  //disable the chromosome num locus parameter
562  mapParam = get_parameter( _paramPrefix + "_chromosome_num_locus" );
563  mapParam->setIsSet(false);
564 
565  // set the map resolution right, must be at the same scale as recorded in the map
566  mapParam = get_parameter( _paramPrefix + "_genetic_map_resolution" );
567  mapParam->setArg(tstring::dble2str( _map.getResolution() ) ); // the local resolution is not updated after registering the trait map, other traits might have changed it
568  mapParam->setIsSet(true);
569 
570 }
double getResolution()
Definition: ttrait_with_map.h:106
This structure stores one parameter, its definition and its string argument.
Definition: param.h:54
void setArg(string value)
Sets the parameter's argument.
Definition: param.h:118
void setIsSet(bool value)
Sets the _isSet flag.
Definition: param.h:122
string _paramPrefix
Definition: ttrait_with_map.h:186
static string dble2str(const double d)
Writes a floating-point value into a string.
Definition: tstring.h:115

References _lociMapPositions, _map, _numChromosome, _numLoci, _numLociPerChrmsm, _paramPrefix, tstring::dble2str(), SimComponent::get_parameter(), GeneticMap::getResolution(), Param::setArg(), and Param::setIsSet().

◆ registerGeneticMap()

void TTProtoWithMap::registerGeneticMap ( )
576 {
579  _isRegistered = true;
580 }
unsigned int addTrait(trait_t trait, unsigned int nChrm, unsigned int nLoc, unsigned int *nLocChrm, double resolution, unsigned int *locPositions)
Returns the table index for the registered trait.
Definition: ttrait_with_map.cc:666
virtual trait_t get_type() const =0
Type accessor.

References _isRegistered, _lociMapPositions, _map, _mapIndex, _mapResolution, _numChromosome, _numLoci, _numLociPerChrmsm, GeneticMap::addTrait(), and TraitPrototype::get_type().

Referenced by setGeneticMapParameters().

◆ reset()

void TTProtoWithMap::reset ( )
virtual

Implements TraitPrototype.

Reimplemented in TProtoQuanti, TProtoNeutralGenes, and TProtoDeletMutations_bitstring.

613 {
615  _isRegistered = false;
616 }
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:624

References _isRegistered, _map, TraitPrototype::get_type(), and GeneticMap::unregisterTrait().

Referenced by TProtoDeletMutations_bitstring::reset(), TProtoNeutralGenes::reset(), and TProtoQuanti::reset().

◆ reset_recombination_pointers()

void TTProtoWithMap::reset_recombination_pointers ( )

◆ setGeneticMapParameters()

bool TTProtoWithMap::setGeneticMapParameters ( string  prefix)
126 {
127  TMatrix tmp_matx;
128  bool map_set = false;
129 
130  _paramPrefix = prefix;
131 
132  string param_name;
133 
134  _numLoci = (unsigned int)get_parameter_value(prefix + "_loci");
135 
136 //map resolution:
137  param_name = prefix + "_genetic_map_resolution";
138 
139  _mapResolution = (get_parameter(param_name)->isSet() ? get_parameter_value(param_name) : 1);
140 
141  _recombRate = 0;
142 
144 
145 // ---------------------------------------------------------------------------
146 //recombination rates --> "fixed" map
147  param_name = prefix + "_recombination_rate";
148  if( get_parameter(param_name)->isSet() ) {
149 
150  if(!get_parameter(param_name)->isMatrix()) {
151 
152  _numChromosome = 1;
153 
154  _recombRate = get_parameter_value(param_name);
155 
156  _numLociPerChrmsm = new unsigned int[1];
158 
159  _recombRatePerChrmsm = new double[1];
161 
162  } else {
163  //is a matrix parameter
164 
165  get_parameter(param_name)->getMatrix(&tmp_matx);
166 
167  if(tmp_matx.getNbRows() != 1) {
168  return error("\"%s_recombination_rate\" must be one-dimensional, with chromosome-specific recombination rates as elements.\n", prefix.c_str());
169  }
170 
171  _numChromosome = tmp_matx.getNbCols();
172 
173  if( !setNumLociPerChromosome(prefix) ) return false;
174 
175  //store the chromosome recombination rates:
176  _recombRatePerChrmsm = new double [_numChromosome];
177 
178  for (unsigned int i = 0; i < _numChromosome; ++i)
179  _recombRatePerChrmsm[i] = tmp_matx.get(0, i);
180  }
181 
182  if(_numChromosome == 1 && _recombRatePerChrmsm[0] == 0.5) { // in case "{{0.5}}" was passed as argument
183 
184  _recombRate = 0.5;
185 
186  }
187 
188  if( !setRecombinationMapFixed() ) return false;
189 
190  map_set = true;
191  }
192 
193 //---------------------------------------------------------------------------------------------
194 //non random map:
195  param_name = prefix + "_genetic_map";
196  if ( get_parameter(param_name)->isSet() ) {
197 
198  if(map_set) {
199  return error("A genetic map is already specified for trait \"%s\" while parameter \"%s\" is set.\n",prefix.c_str(), param_name.c_str());
200  }
201  //the genetic map gives the position of each locus on the map
202  vector< vector<double> > tmp_varmatx;
203 
204  get_parameter(param_name)->getVariableMatrix(&tmp_varmatx);
205 
206  _numChromosome = tmp_varmatx.size();
207 
208  param_name = prefix + "_chromosome_num_locus";
209 
210  if ( get_parameter(param_name)->isSet() ) {
211  warning("\"%s_chromosome_num_locus\" is not used with \"%s_genetic_map\", ignoring it.\n", prefix.c_str(), prefix.c_str());
212  }
213 
214  assert(_numLociPerChrmsm == NULL);
215 
216  _numLociPerChrmsm = new unsigned int[_numChromosome];
217 
218  unsigned int length = 0;
219 
220  for (unsigned int i = 0; i < _numChromosome; ++i) {
221  _numLociPerChrmsm[i] = tmp_varmatx[i].size();
222  length += _numLociPerChrmsm[i];
223  }
224 
225  if(length != _numLoci) {
226  return error("Number of loci in \"%s_genetic_map\" (%i) different from number of loci (%i) for trait \"%s\"\n",
227  prefix.c_str(), length, _numLoci, prefix.c_str());
228  }
229 
230  if( !setRecombinationMapNonRandom(&tmp_varmatx) ) return false;
231 
232  map_set = true;
233  }
234 
235 //---------------------------------------------------------------------------------------------
236 //random map:
237  param_name = prefix + "_random_genetic_map";
238  if ( get_parameter(param_name)->isSet() ) {
239 
240  if(map_set) {
241  return error("A genetic map is already specified for trait \"%s\" while parameter \"%s\" is set.\n",param_name.c_str());
242  }
243 
244  get_parameter(param_name)->getMatrix(&tmp_matx);
245 
246  if(tmp_matx.getNbRows() != 1) {
247  error("\"%s_random_genetic_map\" must have one row, with chromosome lengths as elements.\n",get_type().c_str());
248  return false;
249  }
250 
251  _numChromosome = tmp_matx.getNbCols();
252 
253  _chrsmLength = new unsigned int [_numChromosome];
254 
255  for (unsigned int i = 0; i < _numChromosome; ++i)
256  _chrsmLength[i] = tmp_matx.get(0, i);
257 
258  if( !setNumLociPerChromosome(prefix) ) return false;
259 
260  if( !setRecombinationMapRandom() ) return false;
261 
262  map_set = true;
263  }
264 
265 //---------------------------------------------------------------------------------------------
266 //the map/recombination parameters are missing in the config file, setting default map
267  if( !map_set ) {
268 
269  _recombRate = 0.5;
270  _numChromosome = 1;
271 
272  _numLociPerChrmsm = new unsigned int[1];
274 
275  _recombRatePerChrmsm = new double[1];
277 
278  if( !setRecombinationMapFixed() ) return false;
279  }
280 
281 //---------------------------------------------------------------------------------------------
282 
283  // transmit positions to the map!!
285 
286 // // record the random loci positions into the trait parameter for saving in log file
287 // if (get_parameter(prefix + "_random_genetic_map")->isSet()) {
288 //
289 // recordRandomMap();
290 // }
291 
292  return true;
293 }
void getVariableMatrix(vector< vector< double > > *mat)
Definition: param.cc:460
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:378
bool isSet()
Definition: param.h:140
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
unsigned int getNbRows() const
Gives the number of rows.
Definition: tmatrix.h:212
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:215
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
bool setNumLociPerChromosome(string param_name)
Definition: ttrait_with_map.cc:297
bool setRecombinationMapFixed()
Definition: ttrait_with_map.cc:388
void registerGeneticMap()
Definition: ttrait_with_map.cc:575
bool setRecombinationMapNonRandom(vector< vector< double > > *lociPositions)
Definition: ttrait_with_map.cc:364
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:438
int error(const char *str,...)
Definition: output.cc:77
void warning(const char *str,...)
Definition: output.cc:58

References _chrsmLength, _mapResolution, _numChromosome, _numLoci, _numLociPerChrmsm, _paramPrefix, _recombRate, _recombRatePerChrmsm, error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), TraitPrototype::get_type(), Param::getMatrix(), TMatrix::getNbCols(), TMatrix::getNbRows(), Param::getVariableMatrix(), Param::isSet(), registerGeneticMap(), reset_recombination_pointers(), setNumLociPerChromosome(), setRecombinationMapFixed(), setRecombinationMapNonRandom(), setRecombinationMapRandom(), and warning().

Referenced by TProtoQuanti::setGeneticMapParams(), TProtoBDMI::setParameters(), TProtoDeletMutations_bitstring::setParameters(), and TProtoNeutralGenes::setParameters().

◆ setMapIndex()

void TTProtoWithMap::setMapIndex ( unsigned int  idx)
inline
222 {_mapIndex = idx;}

References _mapIndex.

◆ setNumLociPerChromosome()

bool TTProtoWithMap::setNumLociPerChromosome ( string  param_name)
298 {
299  assert(_numLociPerChrmsm == NULL);
300 
301  _numLociPerChrmsm = new unsigned int[_numChromosome];
302 
303  //fill the table:
304 
305  string param_name = prefix + "_chromosome_num_locus";
306 
307  if ( !get_parameter(param_name)->isSet()) {
308 
309  if(_numLoci % _numChromosome != 0) {
310 
311  return error("Loci cannot be evenly distributed on chromosome map for trait %s\n", prefix.c_str());
312 
313  } else {
314 
315  for (unsigned int i = 0; i < _numChromosome; ++i){
317  }
318  }
319 
320  } else { //chromosome num locus provided in input
321 
322  TMatrix numlocmat;
323 
324  get_parameter(param_name)->getMatrix(&numlocmat);
325 
326  if(numlocmat.getNbRows() != 1) {
327 
328  return error("\"%s_chromosome_num_locus\" must be one-dimensional, with num. loci per chromosome as elements.\n", prefix.c_str());
329 
330  }
331 
332  if(numlocmat.getNbCols() > _numChromosome) {
333 
334  return error("\"%s_chromosome_num_locus\" must have same number of elements (chromosomes) as genetic map parameters.\n", prefix.c_str());
335 
336  }
337 
338  unsigned int cntr=0;
339 
340  for (unsigned int i = 0; i < _numChromosome; ++i) {
341 
342  if(numlocmat.get(0, i) == 0){
343 
344  return error("the genetic map doesn't accept empty chromosomes with 0 loci\n");
345 
346  }
347  _numLociPerChrmsm[i] = numlocmat.get(0, i);
348  cntr += numlocmat.get(0, i);
349  }
350 
351  if (cntr != _numLoci) {
352 
353  return error("\"%s_chromosome_num_locus\" has more loci than \"%s_loci\"\n", prefix.c_str(), prefix.c_str());
354 
355  }
356 
357  } //else chromosom num locus provided in input
358 
359  return true;
360 }

References _numChromosome, _numLoci, _numLociPerChrmsm, error(), TMatrix::get(), SimComponent::get_parameter(), Param::getMatrix(), TMatrix::getNbCols(), and TMatrix::getNbRows().

Referenced by setGeneticMapParameters().

◆ setRecombinationMapFixed()

bool TTProtoWithMap::setRecombinationMapFixed ( )
389 {
390  assert(_lociMapPositions == NULL);
391 
392  _lociMapPositions = new unsigned int [_numLoci];
393 
394 // cout << "TTProtoWithMap::setRecombinationMapFixed\n";
395 
396  double interval_scale;
397 
398  //find the minimum recombination rate, this will give the resolution of the map.
399 
400 // cout << " map resolution (start): "<<_mapResolution<<endl;
401 
402  interval_scale = 0.01 * _mapResolution; // reminder: map resolution is relative to cM = 0.01 rec rate, we rescale
403 
404  for(unsigned int i = 0; i < _numChromosome; i++){
405  interval_scale = std::min(_recombRatePerChrmsm[i], interval_scale);
406  }
407 
408  _mapResolution = interval_scale / 0.01; // rescale back from rec rate to cM
409 
410 // cout << " map resolution (min): "<<_mapResolution<<endl;
411 // cout << " interval scale = "<<interval_scale<<endl;
412 
413  //recombination rates are distance *between* loci!
414  double step;
415  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
416 
417  step = round(_recombRatePerChrmsm[i] / interval_scale); //positions are integers!
418 
419 // cout << " chrm "<<i<<" [step="<<step<<"] \n";
420 
421  _lociMapPositions[stride] = 0;
422 
423  for(unsigned int j = 1, k = 0; j < _numLociPerChrmsm[i]; ++j, ++k){
424 
425  _lociMapPositions[stride + j] = _lociMapPositions[stride + k] + step;
426 
427 // cout << "chrm "<<i<<" loc "<<j<<" pos: "<<_lociMapPositions[stride + j]<<endl;
428  }
429 
430  stride += _numLociPerChrmsm[i];
431  }
432 
433  return true;
434 }

References _lociMapPositions, _mapResolution, _numChromosome, _numLoci, _numLociPerChrmsm, and _recombRatePerChrmsm.

Referenced by setGeneticMapParameters().

◆ setRecombinationMapNonRandom()

bool TTProtoWithMap::setRecombinationMapNonRandom ( vector< vector< double > > *  lociPositions)
365 {
366  assert(_lociMapPositions == NULL);
367 
368  _lociMapPositions = new unsigned int [_numLoci];
369 
370 // cout << "TTProtoWithMap::setRecombinationMapNonRandom\n";
371 
372  //set loci position in absolute size
373  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
374 
375  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; j++){
376  _lociMapPositions[stride + j] = (unsigned int)(*lociPositions)[i][j];
377 // cout << _lociMapPositions[stride + j]<<" ";
378  }
379  stride += _numLociPerChrmsm[i];
380 // cout << endl;
381  }
382 
383  return true;
384 }

References _lociMapPositions, _numChromosome, _numLoci, and _numLociPerChrmsm.

Referenced by setGeneticMapParameters().

◆ setRecombinationMapRandom()

bool TTProtoWithMap::setRecombinationMapRandom ( )

!there might be duplicates, we don't deal with those

439 {
440  assert(_lociMapPositions == NULL);
441 
442  _lociMapPositions = new unsigned int [_numLoci];
443 
444 // cout << "TTProtoWithMap::setRecombinationMapRandom\n";
445 
446  vector<unsigned int> chr_length(_numChromosome, 0);
447 
448  for(unsigned int i = 0; i < _numChromosome; i++)
449  chr_length[i] = (unsigned int)(_chrsmLength[i] / _mapResolution);
450 
451  //draw the positions:
452  vector< unsigned int > tmp_map;
453  unsigned int **chrm_map;
454 
455  chrm_map = new unsigned int* [_numChromosome];
456 
457  for (unsigned int i = 0; i < _numChromosome; ++i) {
458  chrm_map[i] = new unsigned int [ _numLociPerChrmsm[i] ];
459  }
460 
461  for(unsigned int i = 0; i < _numChromosome; i++) {
462 
463  tmp_map.assign(_numLociPerChrmsm[i], 0);
464 
465  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; ++j)
466  tmp_map[j] = RAND::Uniform( chr_length[i] );
467 
468  vector<unsigned int>::iterator vec_first = tmp_map.begin(), vec_last = tmp_map.end();
469  //sort the vector
470  std::sort(vec_first, vec_last);
471 
473 
474  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; ++j)
475  chrm_map[i][j] = tmp_map[j];
476  }
477 
478 // cout << " loci positions:\n";
479  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
480  //offset = 0,
481  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; j++){
482  _lociMapPositions[stride + j] = chrm_map[i][j];// + offset;
483 // cout << _lociMapPositions[stride + j]<<" ";
484  }
485  //total size of chrmsm, to add to pos of next chrmsm loci
486 // offset += chr_length[i];
487 // cout << endl;
488 
489  stride += _numLociPerChrmsm[i];
490  }
491 
492 // unsigned int totLength = _lociMapPositions[numLoci -1];
493 
494  for (unsigned int i = 0; i < _numChromosome; ++i) {
495  delete [] chrm_map[i];
496  }
497  delete [] chrm_map;
498 
499  // record positions into genetic_map parameter,
500  // will be saved with other params in log file
501  ostringstream map;
502 
503  map<<"{";
504 
505  for (unsigned int c = 0, l = 0; c < _numChromosome; c++) {
506  map<<"{";
507 
508  for (unsigned int i = 0; i < _numLociPerChrmsm[c]-1 && l < _numLoci; i++) {
509  map<<_lociMapPositions[ l++ ]<<", ";
510  }
511  map<<_lociMapPositions[ l++ ];
512  map<<"}";
513  }
514  map<<"}";
515 
516  Param* mapParam = get_parameter( _paramPrefix + "_genetic_map" );
517 
518  mapParam->setArg(map.str());
519  mapParam->setIsSet(true);
520  mapParam = get_parameter( _paramPrefix + "_random_genetic_map" );
521  mapParam->setIsSet(false);
522  mapParam = get_parameter( _paramPrefix + "_chromosome_num_locus" );
523  mapParam->setIsSet(false);
524  mapParam = get_parameter( _paramPrefix + "_genetic_map_resolution" );
525  mapParam->setArg(tstring::dble2str( _mapResolution )); // the local resolution is not updated after registering the trait map, other traits might have changed it
526  mapParam->setIsSet(true);
527 
528  return true;
529 }
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:124

References _chrsmLength, _lociMapPositions, _mapResolution, _numChromosome, _numLoci, _numLociPerChrmsm, _paramPrefix, tstring::dble2str(), SimComponent::get_parameter(), Param::setArg(), Param::setIsSet(), and RAND::Uniform().

Referenced by setGeneticMapParameters().

◆ unregisterFromGeneticMap()

void TTProtoWithMap::unregisterFromGeneticMap ( )

Friends And Related Function Documentation

◆ TTraitWithMap

friend class TTraitWithMap
friend

Member Data Documentation

◆ _chrsmLength

unsigned int* TTProtoWithMap::_chrsmLength
protected

◆ _isRegistered

bool TTProtoWithMap::_isRegistered
private

◆ _lociMapPositions

◆ _map

◆ _mapIndex

◆ _mapResolution

double TTProtoWithMap::_mapResolution
protected

◆ _numChromosome

◆ _numLoci

◆ _numLociPerChrmsm

◆ _paramPrefix

string TTProtoWithMap::_paramPrefix
private

◆ _recombRate

◆ _recombRatePerChrmsm

double* TTProtoWithMap::_recombRatePerChrmsm
protected

◆ _totRecombEventsMean

double TTProtoWithMap::_totRecombEventsMean
protected

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

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