Nemo  2.4.2
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 ()
 
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 void reset ()
 
Implements TraitPrototype
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 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...
 
virtual int get_phenotype_dimension ()=0
 Returns the dimension of the phenotype of the trait (size of the array accessed with TTrait::getValue() More...
 
virtual int get_allele_number ()=0
 Returns the number of allele per locus. More...
 
virtual int get_locus_number ()=0
 Returns the number of locus. 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 GeneticMapgetGeneticMapRef ()
 
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
234  {}
double _mapResolution
Definition: ttrait_with_map.h:214
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:220
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:219
double _recombRate
Definition: ttrait_with_map.h:213
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:217
unsigned int _numLoci
Definition: ttrait_with_map.h:216
double _totRecombEventsMean
Definition: ttrait_with_map.h:212
unsigned int _numChromosome
Definition: ttrait_with_map.h:215
bool _isRegistered
Definition: ttrait_with_map.h:206
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:218
unsigned int _mapIndex
Definition: ttrait_with_map.h:211

◆ TTProtoWithMap() [2/2]

TTProtoWithMap::TTProtoWithMap ( const TTProtoWithMap TP)
44  :
48 {
50 
51  _recombRatePerChrmsm = new double [_numChromosome];
52  for (unsigned int i = 0; i < _numChromosome; ++i)
54 
55  _numLociPerChrmsm = new unsigned int [_numChromosome];
56  for (unsigned int i = 0; i < _numChromosome; ++i)
58 
59  _chrsmLength = new unsigned int [_numChromosome];
60  for (unsigned int i = 0; i < _numChromosome; ++i)
61  _chrsmLength[i] = TP._chrsmLength[i];
62 
63  _lociMapPositions = new unsigned int [_numLoci];
64  for (unsigned int i = 0; i < _numLoci; ++i)
66 
67 }
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:626

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

◆ ~TTProtoWithMap()

TTProtoWithMap::~TTProtoWithMap ( )
virtual

Member Function Documentation

◆ addGeneticMapParameters()

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

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)
88 {
89  if( get_parameter(prefix + "_recombination_rate")->isSet() ) return true;
90  else if( get_parameter(prefix + "_genetic_map")->isSet() ) return true;
91  else if( get_parameter(prefix + "_random_genetic_map")->isSet() ) return true;
92  else return false;
93 }
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:137

References SimComponent::get_parameter().

Referenced by isRecombinationFree().

+ Here is the caller graph for this function:

◆ get_locus_map_positions()

vector< unsigned int > TTProtoWithMap::get_locus_map_positions ( )
virtual

Returns the map positions of the loci in vector.

Implements TraitPrototype.

602 {
603  vector< unsigned int > positions(this->get_locus_number(), 0);
604 
605  if( is_mapped() ) {
606 
607  unsigned int * map_pos = _map.getLocusPositionTable(this->get_type());
608 
609  positions.assign(map_pos, map_pos + this->get_locus_number());
610 
611  } else if ( is_mappable() ) {
612  // trait can be placed on the map but has not been placed because of free recombination
613  // generate fake positions:; get a starting position based on the trait index
614  // positions are returned in ~Mbase
615  unsigned int start = (this->get_index()+1) * 10;
616  std::iota(positions.begin(),positions.end(), start);
617  std::transform(positions.begin(), positions.end(), positions.begin(), [](unsigned int i) {return i * 100000;});
618  }
619  // if the trati is non-mappable, then positions remain undefined (all 0)
620 
621  return positions;
622 }
unsigned int * getLocusPositionTable(const trait_t trait)
Definition: ttrait_with_map.h:192
static GeneticMap _map
Definition: ttrait_with_map.h:227
virtual bool is_mappable()
Checks if the trait is mappable, i.e., if the loci can be placed on a genetic map.
Definition: ttrait_with_map.h:243
virtual bool is_mapped()
Checks if the trait's loci are placed on a genetic map.
Definition: ttrait_with_map.h:245
virtual int get_locus_number()=0
Returns the number of locus.
virtual trait_t get_type() const =0
Type accessor.
virtual int get_index()
Index getter.
Definition: ttrait.h:150

References _map, TraitPrototype::get_index(), TraitPrototype::get_locus_number(), TraitPrototype::get_type(), GeneticMap::getLocusPositionTable(), is_mappable(), and is_mapped().

◆ getGeneticMapRef()

static GeneticMap& TTProtoWithMap::getGeneticMapRef ( )
inlinestatic
254 {return _map;}

References _map.

Referenced by TTNeutralGenes_bitstring::inherit_low().

+ Here is the caller graph for this function:

◆ getMapIndex()

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

References _mapIndex.

◆ getRecombRate()

double TTProtoWithMap::getRecombRate ( ) const
inline
256 {return _recombRate;}

References _recombRate.

◆ is_mappable()

virtual bool TTProtoWithMap::is_mappable ( )
inlinevirtual

Checks if the trait is mappable, i.e., if the loci can be placed on a genetic map.

Implements TraitPrototype.

243 {return true;}

Referenced by get_locus_map_positions().

+ Here is the caller graph for this function:

◆ is_mapped()

virtual bool TTProtoWithMap::is_mapped ( )
inlinevirtual

Checks if the trait's loci are placed on a genetic map.

Implements TraitPrototype.

245 {return _map.checkRegisteredTrait(this->get_type());}
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:672

References _map, GeneticMap::checkRegisteredTrait(), and TraitPrototype::get_type().

Referenced by get_locus_map_positions().

+ Here is the caller graph for this function:

◆ isRecombinationFree()

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

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

Referenced by TProtoQuanti::setGeneticMapParams(), TProtoBDMI::setParameters(), and TProtoNeutralGenes::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 
595  _map.recombine(MAL);
596  _map.recombine(FEM);
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:1114
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:162
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35

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:104
This structure stores one parameter, its definition and its string argument.
Definition: param.h:52
void setArg(string value)
Sets the parameter's argument.
Definition: param.h:122
void setIsSet(bool value)
Sets the _isSet flag.
Definition: param.h:126
string _paramPrefix
Definition: ttrait_with_map.h:204
static string dble2str(const double d)
Writes a floating-point value into a string.
Definition: tstring.h:113

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:690

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 TProtoQuanti, TProtoNeutralGenes, and TProtoDeletMutations_bitstring.

637 {
639  _isRegistered = false;
640 }
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:648

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 ( )
627 {
629  if(_numLociPerChrmsm) {delete [] _numLociPerChrmsm; _numLociPerChrmsm = NULL;}
630  if(_chrsmLength) {delete [] _chrsmLength; _chrsmLength = NULL;}
631  if(_lociMapPositions) {delete [] _lociMapPositions; _lociMapPositions = NULL;}
632 }

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

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

+ Here is the caller graph for this function:

◆ setMapIndex()

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

References _mapIndex.

◆ setNumLociPerChromosome()

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

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 ( )
388 {
389  assert(_lociMapPositions == NULL);
390 
391  _lociMapPositions = new unsigned int [_numLoci];
392 
393 // cout << "TTProtoWithMap::setRecombinationMapFixed\n";
394 
395  double interval_scale;
396 
397  //find the minimum recombination rate, this will give the resolution of the map.
398 
399 // cout << " map resolution (start): "<<_mapResolution<<endl;
400 
401  interval_scale = 0.01 * _mapResolution; // reminder: map resolution is relative to cM = 0.01 rec rate, we rescale
402 
403  for(unsigned int i = 0; i < _numChromosome; i++){
404  interval_scale = std::min(_recombRatePerChrmsm[i], interval_scale);
405  }
406 
407  _mapResolution = interval_scale / 0.01; // rescale back from rec rate to cM
408 
409 // cout << " map resolution (min): "<<_mapResolution<<endl;
410 // cout << " interval scale = "<<interval_scale<<endl;
411 
412  //recombination rates are distance *between* loci!
413  double step;
414  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
415 
416  step = round(_recombRatePerChrmsm[i] / interval_scale); //positions are integers!
417 
418 // cout << " chrm "<<i<<" [step="<<step<<"] \n";
419 
420  _lociMapPositions[stride] = 0;
421 
422  for(unsigned int j = 1, k = 0; j < _numLociPerChrmsm[i]; ++j, ++k){
423 
424  _lociMapPositions[stride + j] = _lociMapPositions[stride + k] + step;
425 
426 // cout << "chrm "<<i<<" loc "<<j<<" pos: "<<_lociMapPositions[stride + j]<<endl;
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)
364 {
365  assert(_lociMapPositions == NULL);
366 
367  _lociMapPositions = new unsigned int [_numLoci];
368 
369 // cout << "TTProtoWithMap::setRecombinationMapNonRandom\n";
370 
371  //set loci position in absolute size
372  for(unsigned int i = 0, stride = 0; i < _numChromosome; i++) {
373 
374  for(unsigned int j = 0; j < _numLociPerChrmsm[i]; j++){
375  _lociMapPositions[stride + j] = (unsigned int)lociPositions[i][j];
376 // cout << _lociMapPositions[stride + j]<<" ";
377  }
378  stride += _numLociPerChrmsm[i];
379 // cout << endl;
380  }
381 
382  return true;
383 }

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.4.2 by  doxygen 1.9.1

Catalogued on GSR