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 ()
 
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
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)
46  :
50 {
52 
53  _recombRatePerChrmsm = new double [_numChromosome];
54  for (unsigned int i = 0; i < _numChromosome; ++i)
56 
57  _numLociPerChrmsm = new unsigned int [_numChromosome];
58  for (unsigned int i = 0; i < _numChromosome; ++i)
60 
61  _chrsmLength = new unsigned int [_numChromosome];
62  for (unsigned int i = 0; i < _numChromosome; ++i)
63  _chrsmLength[i] = TP._chrsmLength[i];
64 
65  _lociMapPositions = new unsigned int [_numLoci];
66  for (unsigned int i = 0; i < _numLoci; ++i)
68 
69 }
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:628

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

◆ ~TTProtoWithMap()

TTProtoWithMap::~TTProtoWithMap ( )
virtual

Member Function Documentation

◆ addGeneticMapParameters()

void TTProtoWithMap::addGeneticMapParameters ( string  prefix)
79 {
80  add_parameter(prefix + "_recombination_rate", DBL, false, true, 0, 0.5, 0);
81  add_parameter(prefix + "_genetic_map_resolution", DBL, false, false, 0, 0, 0);
82  add_parameter(prefix + "_chromosome_num_locus", MAT, false, false, 0, 0, 0);
83  add_parameter(prefix + "_genetic_map", MAT, false, false, 0, 0, 0);
84  add_parameter(prefix + "_random_genetic_map", MAT, false, false, 0, 0, 0);
85 }
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)
90 {
91  if( get_parameter(prefix + "_recombination_rate")->isSet() ) return true;
92  else if( get_parameter(prefix + "_genetic_map")->isSet() ) return true;
93  else if( get_parameter(prefix + "_random_genetic_map")->isSet() ) return true;
94  else return false;
95 }
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139

References SimComponent::get_parameter().

Referenced by isRecombinationFree().

◆ get_locus_map_positions()

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

Returns the map positions of the loci in vector.

Implements TraitPrototype.

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

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
236 {return _map;}

References _map.

Referenced by TTNeutralGenes_bitstring::inherit_low().

◆ getMapIndex()

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

References _mapIndex.

◆ getRecombRate()

double TTProtoWithMap::getRecombRate ( ) const
inline
238 {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.

225 {return true;}

Referenced by get_locus_map_positions().

◆ is_mapped()

virtual bool TTProtoWithMap::is_mapped ( )
inlinevirtual

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

Implements TraitPrototype.

227 {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:674

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

Referenced by get_locus_map_positions().

◆ isRecombinationFree()

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

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
594 {
595  if(!_map.registerIndForRecombine(indID)) return;
596 
597  _map.recombine(MAL);
598  _map.recombine(FEM);
599 }
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:1101
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:144
@ 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 ( )
535 {
536  // record positions into genetic_map parameter,
537  // will be saved with other params in log file
538  ostringstream map;
539 
540  map<<"{";
541 
542  for (unsigned int c = 0, l = 0; c < _numChromosome; c++) {
543  map<<"{";
544 
545  for (unsigned int i = 0; i < _numLociPerChrmsm[c]-1 && l < _numLoci; i++) {
546  map<<_lociMapPositions[ l++ ]<<", ";
547  }
548  map<<_lociMapPositions[ l++ ];
549  map<<"}";
550  }
551  map<<"}";
552 
553  // record the position inthe genetic map parameter
554  Param* mapParam = get_parameter( _paramPrefix + "_genetic_map" );
555  mapParam->setArg(map.str());
556  mapParam->setIsSet(true);
557 
558  //disable the random map parameter
559  mapParam = get_parameter( _paramPrefix + "_random_genetic_map" );
560  mapParam->setIsSet(false);
561 
562  //disable the chromosome num locus parameter
563  mapParam = get_parameter( _paramPrefix + "_chromosome_num_locus" );
564  mapParam->setIsSet(false);
565 
566  // set the map resolution right, must be at the same scale as recorded in the map
567  mapParam = get_parameter( _paramPrefix + "_genetic_map_resolution" );
568  mapParam->setArg(tstring::dble2str( _map.getResolution() ) ); // the local resolution is not updated after registering the trait map, other traits might have changed it
569  mapParam->setIsSet(true);
570 
571 }
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 ( )
577 {
580  _isRegistered = true;
581 }
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:692

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.

639 {
641  _isRegistered = false;
642 }
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:650

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

References _mapIndex.

◆ setNumLociPerChromosome()

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

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

Referenced by setGeneticMapParameters().

◆ setRecombinationMapFixed()

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

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

Referenced by setGeneticMapParameters().

◆ setRecombinationMapNonRandom()

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

References _lociMapPositions, _numChromosome, _numLoci, and _numLociPerChrmsm.

Referenced by setGeneticMapParameters().

◆ setRecombinationMapRandom()

bool TTProtoWithMap::setRecombinationMapRandom ( )

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

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

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