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

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::TTProtoWithMap ( )
inline
197  {}
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:180
double _totRecombEventsMean
Definition: ttrait_with_map.h:175
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
double _recombRate
Definition: ttrait_with_map.h:176
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:182
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
bool _isRegistered
Definition: ttrait_with_map.h:169
unsigned int _mapIndex
Definition: ttrait_with_map.h:174
double _mapResolution
Definition: ttrait_with_map.h:177
TTProtoWithMap::TTProtoWithMap ( const TTProtoWithMap TP)

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

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 }
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:180
double _totRecombEventsMean
Definition: ttrait_with_map.h:175
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
double _recombRate
Definition: ttrait_with_map.h:176
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:182
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:495
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
unsigned int _mapIndex
Definition: ttrait_with_map.h:174
double _mapResolution
Definition: ttrait_with_map.h:177
TTProtoWithMap::~TTProtoWithMap ( )
virtual

References reset_recombination_pointers().

71 {
73 }
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:495

Member Function Documentation

void TTProtoWithMap::addGeneticMapParameters ( string  prefix)

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

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

78 {
79  add_parameter(prefix + "_recombination_rate", DBL, false, true, 0, 0.5, 0);
80  add_parameter(prefix + "_genetic_map_resolution", DBL, false, true, 0, 1, 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 }
Definition: types.h:78
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
Definition: types.h:78
unsigned int TTProtoWithMap::getMapIndex ( )
inline

References _mapIndex.

205 {return _mapIndex;}
unsigned int _mapIndex
Definition: ttrait_with_map.h:174
void TTProtoWithMap::recombine ( unsigned long  indID)
static

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

Referenced by Individual::recombine().

486 {
487  if(!_map.registerIndForRecombine(indID)) return;
488 
489  _map.recombine(MAL);
490  _map.recombine(FEM);
491 }
static GeneticMap _map
Definition: ttrait_with_map.h:190
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:133
Definition: types.h:37
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:879
Definition: types.h:37
void TTProtoWithMap::registerGeneticMap ( )

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

Referenced by setGeneticMapParameters().

477 {
480  _isRegistered = true;
481 }
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:547
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
static GeneticMap _map
Definition: ttrait_with_map.h:190
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
bool _isRegistered
Definition: ttrait_with_map.h:169
virtual trait_t get_type() const =0
Type accessor.
unsigned int _mapIndex
Definition: ttrait_with_map.h:174
double _mapResolution
Definition: ttrait_with_map.h:177
void TTProtoWithMap::reset ( )
virtual

Implements TraitPrototype.

Reimplemented in TProtoDeletMutations_bitstring, TProtoNeutralGenes, and TProtoQuanti.

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

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

506 {
508  _isRegistered = false;
509 }
static GeneticMap _map
Definition: ttrait_with_map.h:190
bool _isRegistered
Definition: ttrait_with_map.h:169
virtual trait_t get_type() const =0
Type accessor.
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:517
void TTProtoWithMap::reset_recombination_pointers ( )

References _chrsmLength, _lociMapPositions, _numLociPerChrmsm, and _recombRatePerChrmsm.

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

496 {
498  if(_numLociPerChrmsm) {delete [] _numLociPerChrmsm; _numLociPerChrmsm = NULL;}
499  if(_chrsmLength) {delete [] _chrsmLength; _chrsmLength = NULL;}
500  if(_lociMapPositions) {delete [] _lociMapPositions; _lociMapPositions = NULL;}
501 }
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:180
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:182
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
bool TTProtoWithMap::setGeneticMapParameters ( string  prefix)

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(), TProtoQuanti::setParameters(), TProtoNeutralGenes::setParameters(), and TProtoDeletMutations_bitstring::setParameters().

89 {
90  TMatrix tmp_matx;
91  bool map_set = false;
92 
93  _paramPrefix = prefix;
94 
95  string param_name;
96 
97  _numLoci = (unsigned int)get_parameter_value(prefix + "_loci");
98 
99 //map resolution:
100  param_name = prefix + "_genetic_map_resolution";
101  _mapResolution = (get_parameter(param_name)->isSet() ? get_parameter_value(param_name) : 1);
102 
103  //set map's resolution, depends on current resolution
104  //***!! have to update current map if resolution changes !!*** <-----
105  //map_resolution = _map.setResolution(map_resolution);
106 
107 
109 
110 // ---------------------------------------------------------------------------
111 //recombination rates --> "fixed" map
112  param_name = prefix + "_recombination_rate";
113  if( get_parameter(param_name)->isSet() ) {
114 
115  if(!get_parameter(param_name)->isMatrix()) {
116 
117  _numChromosome = 1;
118 
119  _recombRate = get_parameter_value(param_name);
120 
121  _numLociPerChrmsm = new unsigned int[1];
123 
124  _recombRatePerChrmsm = new double[1];
126 
127  } else {
128  //is a matrix parameter
129 
130  get_parameter(param_name)->getMatrix(&tmp_matx);
131 
132  if(tmp_matx.getNbRows() != 1) {
133  error("\"%s_recombination_rate\" must be one-dimensional, with chromosome-specific recombination rates as elements.\n", prefix.c_str());
134  return false;
135  }
136 
137  _numChromosome = tmp_matx.getNbCols();
138 
139  if( !setNumLociPerChromosome(prefix) ) return false;
140 
141  //store the chromosome recombination rates:
142  _recombRatePerChrmsm = new double [_numChromosome];
143 
144  for (unsigned int i = 0; i < _numChromosome; ++i)
145  _recombRatePerChrmsm[i] = tmp_matx.get(0, i);
146  }
147 
148  if( !setRecombinationMapFixed() ) return false;
149 
150  map_set = true;
151  }
152 
153 //---------------------------------------------------------------------------------------------
154 //non random map:
155  param_name = prefix + "_genetic_map";
156  if ( get_parameter(param_name)->isSet() ) {
157 
158  if(map_set) {
159  error("A genetic map is already specified for trait \"%s\" while parameter \"%s\" is set.\n",prefix.c_str(), param_name.c_str());
160  return false;
161  }
162  //the genetic map gives the position of each locus on the map
163  vector< vector<double> > tmp_varmatx;
164 
165  get_parameter(param_name)->getVariableMatrix(&tmp_varmatx);
166 
167  _numChromosome = tmp_varmatx.size();
168 
169  param_name = prefix + "_chromosome_num_locus";
170 
171  if ( get_parameter(param_name)->isSet() ) {
172  warning("\"%s_chromosome_num_locus\" is not used with \"%s_genetic_map\", ignoring it.\n", prefix.c_str(), prefix.c_str());
173  }
174 
175  assert(_numLociPerChrmsm == NULL);
176 
177  _numLociPerChrmsm = new unsigned int[_numChromosome];
178 
179  unsigned int length = 0;
180 
181  for (unsigned int i = 0; i < _numChromosome; ++i) {
182  _numLociPerChrmsm[i] = tmp_varmatx[i].size();
183  length += _numLociPerChrmsm[i];
184  }
185 
186  if(length != _numLoci) {
187  return error("Number of loci in \"%s_genetic_map\" different from number of loci for trait \"%s\"\n",
188  prefix.c_str(), prefix.c_str());
189  }
190 
191  if( !setRecombinationMapNonRandom(&tmp_varmatx) ) return false;
192 
193  map_set = true;
194  }
195 
196 //---------------------------------------------------------------------------------------------
197 //random map:
198  param_name = prefix + "_random_genetic_map";
199  if ( get_parameter(param_name)->isSet() ) {
200 
201  if(map_set) {
202  error("A genetic map is already specified for trait \"%s\" while parameter \"%s\" is set.\n",param_name.c_str());
203  return false;
204  }
205 
206  get_parameter(param_name)->getMatrix(&tmp_matx);
207 
208  if(tmp_matx.getNbRows() != 1) {
209  error("\"%s_random_genetic_map\" must have one row, with chromosome lengths as elements.\n",get_type().c_str());
210  return false;
211  }
212 
213  _numChromosome = tmp_matx.getNbCols();
214 
215  _chrsmLength = new unsigned int [_numChromosome];
216 
217  for (unsigned int i = 0; i < _numChromosome; ++i)
218  _chrsmLength[i] = tmp_matx.get(0, i);
219 
220  if( !setNumLociPerChromosome(prefix) ) return false;
221 
222  if( !setRecombinationMapRandom() ) return false;
223 
224  map_set = true;
225  }
226 
227 //---------------------------------------------------------------------------------------------
228 //the map/recombination parameters are missing in the config file, setting default map
229  if( !map_set ) {
230 
231  _recombRate = 0.5;
232  _numChromosome = 1;
233 
234  _numLociPerChrmsm = new unsigned int[1];
236 
237  _recombRatePerChrmsm = new double[1];
239 
240  if( !setRecombinationMapFixed() ) return false;
241  }
242 
243 //---------------------------------------------------------------------------------------------
244 
245  // transmit positions to the map!!
247 
248  return true;
249 }
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:180
void registerGeneticMap()
Definition: ttrait_with_map.cc:476
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
bool setRecombinationMapNonRandom(vector< vector< double > > *lociPositions)
Definition: ttrait_with_map.cc:311
string _paramPrefix
Definition: ttrait_with_map.h:167
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
double _recombRate
Definition: ttrait_with_map.h:176
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:182
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:495
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void getVariableMatrix(vector< vector< double > > *mat)
Definition: param.cc:411
int error(const char *str,...)
Definition: output.cc:73
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
void warning(const char *str,...)
Definition: output.cc:56
bool setRecombinationMapFixed()
Definition: ttrait_with_map.cc:335
bool setNumLociPerChromosome(string param_name)
Definition: ttrait_with_map.cc:253
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
virtual trait_t get_type() const =0
Type accessor.
double _mapResolution
Definition: ttrait_with_map.h:177
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:381
bool isSet()
Definition: param.h:138
void TTProtoWithMap::setMapIndex ( unsigned int  idx)
inline
203 {_mapIndex = idx;}
unsigned int _mapIndex
Definition: ttrait_with_map.h:174
bool TTProtoWithMap::setNumLociPerChromosome ( string  param_name)

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

Referenced by setGeneticMapParameters().

254 {
255  assert(_numLociPerChrmsm == NULL);
256 
257  _numLociPerChrmsm = new unsigned int[_numChromosome];
258 
259  //fill the table:
260  string param_name = prefix + "_chromosome_num_locus";
261  if ( !get_parameter(param_name)->isSet()) {
262 
263  if(_numLoci % _numChromosome != 0) {
264 
265  error("Loci cannot be evenly distributed on chromosome map for trait %s\n", prefix.c_str());
266  return false;
267 
268  } else {
269 
270  for (unsigned int i = 0; i < _numChromosome; ++i){
272  }
273  }
274 
275  } else {
276 
277  TMatrix numlocmat;
278 
279  get_parameter(param_name)->getMatrix(&numlocmat);
280 
281  if(numlocmat.getNbRows() != 1) {
282  error("\"%s_chromosome_num_locus\" must be one-dimensional, with num. loci per chromosome as elements.\n", prefix.c_str());
283  return false;
284  }
285 
286  if(numlocmat.getNbCols() > _numChromosome) {
287  error("\"%s_chromosome_num_locus\" must have same number of elements (chromosomes) as genetic map parameters.\n", prefix.c_str());
288  return false;
289  }
290 
291  unsigned int cntr=0;
292  for (unsigned int i = 0; i < _numChromosome; ++i) {
293  if(numlocmat.get(0, i) == 0){
294  error("the genetic map doesn't accept empty chromosomes with 0 loci\n");
295  return false;
296  }
297  _numLociPerChrmsm[i] = numlocmat.get(0, i);
298  cntr += numlocmat.get(0, i);
299  }
300  if (cntr != _numLoci) {
301  error("\"%s_chromosome_num_locus\" has more loci than \"%s_loci\"\n", prefix.c_str(), prefix.c_str());
302  return false;
303  }
304  }
305 
306  return true;
307 }
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
int error(const char *str,...)
Definition: output.cc:73
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
bool TTProtoWithMap::setRecombinationMapFixed ( )

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

Referenced by setGeneticMapParameters().

336 {
337  assert(_lociMapPositions == NULL);
338 
339  _lociMapPositions = new unsigned int [_numLoci];
340 
341 // cout << "TTProtoWithMap::setRecombinationMapFixed\n";
342 
343  double interval_scale;
344 
345  //find the minimum recombination rate, this will give the resolution of the map.
346  for(unsigned int i = 0; i < _numChromosome; i++)
347  _mapResolution = (_recombRatePerChrmsm[i] / (_mapResolution * 0.01) < 1 ?
348  pow(10.0, floor( log10(_recombRatePerChrmsm[i]) ) + 2 ) : //+2 because relative to cM (0.01 rec rate)
349  _mapResolution);
350 
351 // cout << " map resolution: "<<_mapResolution<<endl;
352 
353  interval_scale = 0.01 * _mapResolution;
354 
355 // cout << " interval scale = "<<interval_scale<<endl;
356 
357  //recombination rates are distance *between* loci!
358  double step;
359  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
360 
361  step = round(_recombRatePerChrmsm[i] / interval_scale);
362 
363 // cout << " chrm "<<i<<" [step="<<step<<"] \n";
364 
365  _lociMapPositions[stride] = 0;
366 
367  for(unsigned int j = 1, k = 0; j < _numLociPerChrmsm[i]; ++j, ++k){
368 
369  _lociMapPositions[stride + j] = _lociMapPositions[stride + k] + step;
370 
371  }
372 
373  stride += _numLociPerChrmsm[i];
374  }
375 
376  return true;
377 }
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:180
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
double _mapResolution
Definition: ttrait_with_map.h:177
bool TTProtoWithMap::setRecombinationMapNonRandom ( vector< vector< double > > *  lociPositions)

References _lociMapPositions, _numChromosome, _numLoci, and _numLociPerChrmsm.

Referenced by setGeneticMapParameters().

312 {
313  assert(_lociMapPositions == NULL);
314 
315  _lociMapPositions = new unsigned int [_numLoci];
316 
317 // cout << "TTProtoWithMap::setRecombinationMapNonRandom\n";
318 
319  //set loci position in absolute size
320  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
321 
322  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; j++){
323  _lociMapPositions[stride + j] = (unsigned int)(*lociPositions)[i][j];
324 // cout << _lociMapPositions[stride + j]<<" ";
325  }
326  stride += _numLociPerChrmsm[i];
327 // cout << endl;
328  }
329 
330  return true;
331 }
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
bool TTProtoWithMap::setRecombinationMapRandom ( )

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

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

Referenced by setGeneticMapParameters().

382 {
383  assert(_lociMapPositions == NULL);
384 
385  _lociMapPositions = new unsigned int [_numLoci];
386 
387 // cout << "TTProtoWithMap::setRecombinationMapRandom\n";
388 
389  vector<unsigned int> chr_length(_numChromosome, 0);
390 
391  for(unsigned int i = 0; i < _numChromosome; i++)
392  chr_length[i] = (unsigned int)(_chrsmLength[i] / _mapResolution);
393 
394  //draw the positions:
395  vector< unsigned int > tmp_map;
396  unsigned int **chrm_map;
397 
398  chrm_map = new unsigned int* [_numChromosome];
399 
400  for (unsigned int i = 0; i < _numChromosome; ++i) {
401  chrm_map[i] = new unsigned int [ _numLociPerChrmsm[i] ];
402  }
403 
404  for(unsigned int i = 0; i < _numChromosome; i++) {
405 
406  tmp_map.assign(_numLociPerChrmsm[i], 0);
407 
408  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; ++j)
409  tmp_map[j] = RAND::Uniform( chr_length[i] );
410 
411  vector<unsigned int>::iterator vec_first = tmp_map.begin(), vec_last = tmp_map.end();
412  //sort the vector
413  std::sort(vec_first, vec_last);
414 
416 
417  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; ++j)
418  chrm_map[i][j] = tmp_map[j];
419  }
420 
421 // cout << " loci positions:\n";
422  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
423  //offset = 0,
424  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; j++){
425  _lociMapPositions[stride + j] = chrm_map[i][j];// + offset;
426 // cout << _lociMapPositions[stride + j]<<" ";
427  }
428  //total size of chrmsm, to add to pos of next chrmsm loci
429 // offset += chr_length[i];
430 // cout << endl;
431 
432  stride += _numLociPerChrmsm[i];
433  }
434 
435 // unsigned int totLength = _lociMapPositions[numLoci -1];
436 
437  for (unsigned int i = 0; i < _numChromosome; ++i) {
438  delete [] chrm_map[i];
439  }
440  delete [] chrm_map;
441 
442  // record positions into genetic_map parameter,
443  // will be saved with other params in log file
444  ostringstream map;
445 
446  map<<"{";
447 
448  for (unsigned int c = 0, l = 0; c < _numChromosome; c++) {
449  map<<"{";
450 
451  for (unsigned int i = 0; i < _numLociPerChrmsm[c]-1 && l < _numLoci; i++) {
452  map<<_lociMapPositions[ l++ ]<<", ";
453  }
454  map<<_lociMapPositions[ l++ ];
455  map<<"}";
456  }
457  map<<"}";
458 
459  Param* mapParam = get_parameter( _paramPrefix + "_genetic_map" );
460 
461  mapParam->setArg(map.str());
462  mapParam->setIsSet(true);
463  mapParam = get_parameter( _paramPrefix + "_random_genetic_map" );
464  mapParam->setIsSet(false);
465  mapParam = get_parameter( _paramPrefix + "_chromosome_num_locus" );
466  mapParam->setIsSet(false);
467  mapParam = get_parameter( _paramPrefix + "_genetic_map_resolution" );
468  mapParam->setArg(tstring::dble2str(_map.getResolution())); // the local resolution is not updated after registering the trait map, other traits might have changed it
469  mapParam->setIsSet(true);
470 
471  return true;
472 }
string _paramPrefix
Definition: ttrait_with_map.h:167
void setArg(string value)
Sets the parameter's argument.
Definition: param.h:118
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:183
static GeneticMap _map
Definition: ttrait_with_map.h:190
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:182
unsigned int _numLoci
Definition: ttrait_with_map.h:179
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:181
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
unsigned int _numChromosome
Definition: ttrait_with_map.h:178
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
void setIsSet(bool value)
Sets the _isSet flag.
Definition: param.h:122
double getResolution()
Definition: ttrait_with_map.h:98
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
double _mapResolution
Definition: ttrait_with_map.h:177
static string dble2str(const double d)
Writes a floating-point value into a string.
Definition: tstring.h:115

Friends And Related Function Documentation

friend class TTraitWithMap
friend

Member Data Documentation

unsigned int* TTProtoWithMap::_chrsmLength
protected
bool TTProtoWithMap::_isRegistered
private

Referenced by registerGeneticMap(), and reset().

double TTProtoWithMap::_mapResolution
protected
string TTProtoWithMap::_paramPrefix
private
double* TTProtoWithMap::_recombRatePerChrmsm
protected
double TTProtoWithMap::_totRecombEventsMean
protected

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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR