Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
ttrait_with_map.h
Go to the documentation of this file.
1 
28 #ifndef TTRAIT_WITH_MAP_H
29 #define TTRAIT_WITH_MAP_H
30 
31 #include <string>
32 #include <vector>
33 #include <map>
34 #include <utility>
35 #include "ttrait.h"
36 
37 
38 // ------------------------------------------------------------------------------
42 // ------------------------------------------------------------------------------
43 
44 class GeneticMap {
45 
46 private:
47 
48  unsigned long _currentIndividual;
49 
51  map< trait_t, unsigned int > _traits;
52 
54  unsigned int _nTrait;
55 
59  vector< unsigned int* > _lociLookupTable; //this is the actual map, for each trait
61  vector< unsigned int > _numChrsmPerTrait;
63  vector< unsigned int > _numLociPerTrait;
65  vector< unsigned int* > _numLociPerChrsmPerTrait;
68  vector< unsigned int* > _locPositionsPerTrait;
69 
73  vector< vector < unsigned int > > _recPositions[2];
74 
77  vector< bool > _chrsmFirstRecombPosition[2];
78 
80  vector< unsigned int > _junctions;
81 
82  unsigned int _numChromosome;
83  unsigned int *_perChrsmLength; //array length is _numChromosome
84  unsigned int *_chrsmFirstLocusPosition; //array length is _numChromosome
85  unsigned int _totalLength; // total map length
86  unsigned int _recombLength; // this is _totalLength + 1; used to draw the x-over spots
87  unsigned int _totalNumLoci;
88  double _resolution;
91 
92 
93 public:
94 
99 
101 
102  bool getGeneticMap (trait_t trait, double** table, unsigned int table_length);
103 
104  double getResolution ( ) {return _resolution;}
105 
106  double setResolution (double val)
107  {
108  _resolution = (val < _resolution ? val : _resolution);
109  return _resolution;
110  }
111 
112  void rescaleMap (double val);
113  void reset_tables ();
114  void clear ();
115 
121  void setLookupTable (unsigned int idx);
122 
130  void recombine (sex_t SEX);
131 
142  void placeRecombinationEvents (sex_t SEX, vector<unsigned int> junctions,
143  const vector<bool>& firstRecPos);
144 
150  void placeRecombinationEvents (sex_t SEX);
151 
153  vector< pair<unsigned int, unsigned int> > reduceJunctions (sex_t SEX, unsigned int trait_idx);
154 
162  bool registerIndForRecombine (unsigned long ID)
163  {
164  if (ID == _currentIndividual) return false;
165  else _currentIndividual = ID;
166  return true;
167  }
168 
170  unsigned int addTrait (trait_t trait, unsigned int nChrm, unsigned int nLoc, unsigned int* nLocChrm,
171  double resolution, unsigned int* locPositions);
172 
173  void unregisterTrait (trait_t trait);
174 
178  bool checkRegisteredTrait (trait_t trait);
179 
180 // void unregisterTrait_at (unsigned int traitIdx);
181 
183  vector< unsigned int>& getRecLoci (sex_t SEX, unsigned int trait)
184  {
185  return _recPositions[SEX][trait];
186  }
187 
189  vector< bool >& getFirstRecPosition (sex_t SEX)
190  { return _chrsmFirstRecombPosition[SEX]; }
191 
192  unsigned int* getLocusPositionTable (const trait_t trait)
193  {return _locPositionsPerTrait[ _traits[ trait ] ];}
194 };
195 
196 
197 // ------------------------------------------------------------------------------
201 // ------------------------------------------------------------------------------
203 
204  string _paramPrefix;
205 
207 
208 protected:
209 
210  //recombination:
211  unsigned int _mapIndex;
213  double _recombRate;
215  unsigned int _numChromosome;
216  unsigned int _numLoci;
218  unsigned int *_numLociPerChrmsm;
219  unsigned int *_chrsmLength;
220  unsigned int *_lociMapPositions;
221 
222  friend class TTraitWithMap;
223 
224 public:
225 
226 
227  static GeneticMap _map;
228 
229 
234  {}
235 
236  TTProtoWithMap(const TTProtoWithMap& TP);
237 
238  virtual ~TTProtoWithMap();
239 
242 
243  virtual bool is_mappable () {return true;}
245  virtual bool is_mapped () {return _map.checkRegisteredTrait(this->get_type());}
247  virtual vector< unsigned int > get_locus_map_positions ();
249 
250  void setMapIndex (unsigned int idx) {_mapIndex = idx;}
251 
252  unsigned int getMapIndex () {return _mapIndex;}
253 
254  static GeneticMap& getGeneticMapRef () {return _map;}
255 
256  double getRecombRate () const {return _recombRate;}
257 
258  bool setGeneticMapParameters (string prefix, unsigned int numLoci = 0);
259 
260  void addGeneticMapParameters (string prefix);
261 
263 
264  bool setRecombinationMapNonRandom (vector< vector<double> >& lociPositions);
265 
266  bool setRecombinationMapFixed ();
267 
268  bool setNumLociPerChromosome (string param_name);
269 
271 
272  void registerGeneticMap ();
273 
274  void unregisterFromGeneticMap ();
275 
276  bool areGeneticMapParamSet(string prefix);
277 
278  bool isRecombinationFree(string prefix);
279 
280  void recordRandomMap ();
281 
282  static void recombine (unsigned long indID);
283 
284  virtual void reset ();
285 
286 };
287 
288 
289 // ------------------------------------------------------------------------------
293 // ------------------------------------------------------------------------------
294 class TTraitWithMap : public TTrait {
295 
296 protected:
297 
299 
300 public:
301 
303 
304  virtual ~TTraitWithMap() {}
305 
306 };
307 
308 #endif
GeneticMap.
Definition: ttrait_with_map.h:44
void setLookupTable(unsigned int idx)
Bbuilds the lookup table for each trait.
Definition: ttrait_with_map.cc:982
vector< bool > & getFirstRecPosition(sex_t SEX)
Returns the vector of the first chromosome position for recombination, used for all traits.
Definition: ttrait_with_map.h:189
unsigned int * getLocusPositionTable(const trait_t trait)
Definition: ttrait_with_map.h:192
void reset_tables()
Definition: ttrait_with_map.cc:1403
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:63
vector< unsigned int * > _lociLookupTable
A list of tables that map the map position (cM) to a locus, for each trait.
Definition: ttrait_with_map.h:59
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:54
unsigned int _recombLength
Definition: ttrait_with_map.h:86
vector< pair< unsigned int, unsigned int > > reduceJunctions(sex_t SEX, unsigned int trait_idx)
Remove multiple x-over at the same locus when traits differ in number of loci.
Definition: ttrait_with_map.cc:1312
double setResolution(double val)
Definition: ttrait_with_map.h:106
double _recombinationRate
Definition: ttrait_with_map.h:90
vector< unsigned int > _numChrsmPerTrait
Vector of number of chromosomes for each trait.
Definition: ttrait_with_map.h:61
vector< bool > _chrsmFirstRecombPosition[2]
Two vectors holding the starting copy of each chromosome to use when creating the two gametes that ar...
Definition: ttrait_with_map.h:77
double _totRecombEventsMean
Definition: ttrait_with_map.h:89
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
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:84
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
unsigned int _totalLength
Definition: ttrait_with_map.h:85
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:68
vector< vector< unsigned int > > _recPositions[2]
Vector of tables containing, for each trait, the locus number at which x-overs happen.
Definition: ttrait_with_map.h:73
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:83
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:65
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:923
GeneticMap()
Definition: ttrait_with_map.h:95
~GeneticMap()
Definition: ttrait_with_map.h:100
unsigned int _numChromosome
Definition: ttrait_with_map.h:82
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:87
void placeRecombinationEvents(sex_t SEX, vector< unsigned int > junctions, const vector< bool > &firstRecPos)
Deterministic counterpart of recombine(sex_t): instead of drawing the x-over map positions and per-ch...
Definition: ttrait_with_map.cc:1165
double _resolution
Definition: ttrait_with_map.h:88
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:672
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:648
vector< unsigned int > & getRecLoci(sex_t SEX, unsigned int trait)
Returns a vector of the loci where crossing-overs take place.
Definition: ttrait_with_map.h:183
void clear()
Definition: ttrait_with_map.cc:681
unsigned long _currentIndividual
Definition: ttrait_with_map.h:48
double getResolution()
Definition: ttrait_with_map.h:104
vector< unsigned int > _junctions
A vector to store the position of the recombination events.
Definition: ttrait_with_map.h:80
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:51
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:162
void rescaleMap(double val)
Definition: ttrait_with_map.cc:953
TTProtoWithMap.
Definition: ttrait_with_map.h:202
double _mapResolution
Definition: ttrait_with_map.h:214
static GeneticMap _map
Definition: ttrait_with_map.h:227
static GeneticMap & getGeneticMapRef()
Definition: ttrait_with_map.h:254
bool setNumLociPerChromosome(string param_name)
Definition: ttrait_with_map.cc:296
void unregisterFromGeneticMap()
Definition: ttrait_with_map.cc:583
virtual vector< unsigned int > get_locus_map_positions()
Returns the map positions of the loci in vector.
Definition: ttrait_with_map.cc:601
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:220
string _paramPrefix
Definition: ttrait_with_map.h:204
bool setRecombinationMapFixed()
Definition: ttrait_with_map.cc:387
bool setRecombinationMapNonRandom(vector< vector< double > > &lociPositions)
Definition: ttrait_with_map.cc:363
void recordRandomMap()
Definition: ttrait_with_map.cc:532
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
bool areGeneticMapParamSet(string prefix)
Definition: ttrait_with_map.cc:87
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:219
virtual bool is_mapped()
Checks if the trait's loci are placed on a genetic map.
Definition: ttrait_with_map.h:245
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
TTProtoWithMap()
Definition: ttrait_with_map.h:230
unsigned int getMapIndex()
Definition: ttrait_with_map.h:252
bool setGeneticMapParameters(string prefix, unsigned int numLoci=0)
Definition: ttrait_with_map.cc:124
double _totRecombEventsMean
Definition: ttrait_with_map.h:212
unsigned int _numChromosome
Definition: ttrait_with_map.h:215
bool isRecombinationFree(string prefix)
Definition: ttrait_with_map.cc:97
virtual void reset()
Definition: ttrait_with_map.cc:636
bool _isRegistered
Definition: ttrait_with_map.h:206
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:218
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:626
void registerGeneticMap()
Definition: ttrait_with_map.cc:574
void addGeneticMapParameters(string prefix)
Definition: ttrait_with_map.cc:76
unsigned int _mapIndex
Definition: ttrait_with_map.h:211
void setMapIndex(unsigned int idx)
Definition: ttrait_with_map.h:250
virtual ~TTProtoWithMap()
Definition: ttrait_with_map.cc:69
static void recombine(unsigned long indID)
Definition: ttrait_with_map.cc:591
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:437
double getRecombRate() const
Definition: ttrait_with_map.h:256
TTraitWithMap.
Definition: ttrait_with_map.h:294
TTProtoWithMap * _myProto
Definition: ttrait_with_map.h:298
virtual ~TTraitWithMap()
Definition: ttrait_with_map.h:304
TTraitWithMap()
Definition: ttrait_with_map.h:302
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:44
TTrait setter.
Definition: ttrait.h:129
virtual trait_t get_type() const =0
Type accessor.
Nemo2.
std::string trait_t
Trait types.
Definition: types.h:61
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR