Nemo  2.3.56
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 void reset ()=0
 Called at the end of a simulation to reset the Traits' prototypes (e.g. More...
 
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
208 {}
double _mapResolution
Definition: ttrait_with_map.h:188
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:194
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:193
double _recombRate
Definition: ttrait_with_map.h:187
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:191
unsigned int _numLoci
Definition: ttrait_with_map.h:190
double _totRecombEventsMean
Definition: ttrait_with_map.h:186
unsigned int _numChromosome
Definition: ttrait_with_map.h:189
bool _isRegistered
Definition: ttrait_with_map.h:180
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:192
unsigned int _mapIndex
Definition: ttrait_with_map.h:185

◆ TTProtoWithMap() [2/2]

TTProtoWithMap::TTProtoWithMap ( const TTProtoWithMap TP)
45 :
49{
51
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:601

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

+ Here is the caller graph for this function:

◆ 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().

+ Here is the caller graph for this function:

◆ getMapIndex()

unsigned int TTProtoWithMap::getMapIndex ( )
inline
216{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 TProtoNeutralGenes::setParameters(), and TProtoQuanti::setParameters().

+ Here is the caller graph for this function:

◆ recombine()

void TTProtoWithMap::recombine ( unsigned long  indID)
static
592{
593 if(!_map.registerIndForRecombine(indID)) return;
594
597}
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:1048
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:141
static GeneticMap _map
Definition: ttrait_with_map.h:201
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

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

Referenced by Individual::recombine().

+ Here is the caller graph for this function:

◆ recordRandomMap()

void TTProtoWithMap::recordRandomMap ( )
533{
534 // record positions into genetic_map parameter,
535 // will be saved with other params in log file
536 ostringstream map;
537
538 map<<"{";
539
540 for (unsigned int c = 0, l = 0; c < _numChromosome; c++) {
541 map<<"{";
542
543 for (unsigned int i = 0; i < _numLociPerChrmsm[c]-1 && l < _numLoci; i++) {
544 map<<_lociMapPositions[ l++ ]<<", ";
545 }
546 map<<_lociMapPositions[ l++ ];
547 map<<"}";
548 }
549 map<<"}";
550
551 // record the position inthe genetic map parameter
552 Param* mapParam = get_parameter( _paramPrefix + "_genetic_map" );
553 mapParam->setArg(map.str());
554 mapParam->setIsSet(true);
555
556 //disable the random map parameter
557 mapParam = get_parameter( _paramPrefix + "_random_genetic_map" );
558 mapParam->setIsSet(false);
559
560 //disable the chromosome num locus parameter
561 mapParam = get_parameter( _paramPrefix + "_chromosome_num_locus" );
562 mapParam->setIsSet(false);
563
564 // set the map resolution right, must be at the same scale as recorded in the map
565 mapParam = get_parameter( _paramPrefix + "_genetic_map_resolution" );
566 mapParam->setArg(tstring::dble2str( _map.getResolution() ) ); // the local resolution is not updated after registering the trait map, other traits might have changed it
567 mapParam->setIsSet(true);
568
569}
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:178
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 ( )
575{
578 _isRegistered = true;
579}
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:655
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().

+ Here is the caller graph for this function:

◆ reset()

void TTProtoWithMap::reset ( )
virtual

Implements TraitPrototype.

Reimplemented in TProtoDeletMutations_bitstring, TProtoNeutralGenes, and TProtoQuanti.

612{
614 _isRegistered = false;
615}
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:623

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

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

+ Here is the caller graph for this function:

◆ reset_recombination_pointers()

void TTProtoWithMap::reset_recombination_pointers ( )
602{
605 if(_chrsmLength) {delete [] _chrsmLength; _chrsmLength = NULL;}
607}

References _chrsmLength, _lociMapPositions, _numLociPerChrmsm, and _recombRatePerChrmsm.

Referenced by setGeneticMapParameters(), TTProtoWithMap(), and ~TTProtoWithMap().

+ Here is the caller graph for this function:

◆ 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:
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\" different from number of loci for trait \"%s\"\n",
227 prefix.c_str(), 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:439
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:357
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:49
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:166
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:169
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:574
bool setRecombinationMapNonRandom(vector< vector< double > > *lociPositions)
Definition: ttrait_with_map.cc:364
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:437
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 TProtoBDMI::setParameters(), TProtoDeletMutations_bitstring::setParameters(), TProtoNeutralGenes::setParameters(), and TProtoQuanti::setParameters().

+ Here is the caller graph for this function:

◆ setMapIndex()

void TTProtoWithMap::setMapIndex ( unsigned int  idx)
inline
214{_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().

+ Here is the caller graph for this function:

◆ 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 }
428
429 stride += _numLociPerChrmsm[i];
430 }
431
432 return true;
433}

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

Referenced by setGeneticMapParameters().

+ Here is the caller graph for this function:

◆ 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().

+ Here is the caller graph for this function:

◆ setRecombinationMapRandom()

bool TTProtoWithMap::setRecombinationMapRandom ( )

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

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

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

Referenced by setGeneticMapParameters().

+ Here is the caller graph for this function:

◆ 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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR