Nemo  2.4.1
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 
29 #ifndef TTRAIT_WITH_MAP_H
30 #define TTRAIT_WITH_MAP_H
31 
32 #include <string>
33 #include <vector>
34 #include <map>
35 #include <utility>
36 #include "ttrait.h"
37 
38 
39 // ------------------------------------------------------------------------------
43 // ------------------------------------------------------------------------------
44 
45 class GeneticMap {
46 
47 private:
48 
49  unsigned long _currentIndividual;
50 
52  map< trait_t, unsigned int > _traits;
53 
55  unsigned int _nTrait;
56 
60  vector< unsigned int* > _lociLookupTable; //this is the actual map, for each trait
62  vector< unsigned int > _numChrsmPerTrait;
64  vector< unsigned int > _numLociPerTrait;
66  vector< unsigned int* > _numLociPerChrsmPerTrait;
69  vector< unsigned int* > _locPositionsPerTrait;
70 
74  vector< vector < unsigned int > > _recPositions[2];
75 
78  vector< bool > _chrsmFirstRecombPosition[2];
79 
81  vector< unsigned int > _junctions;
82 
83  unsigned int _numChromosome;
84  unsigned int *_perChrsmLength; //array length is _numChromosome
85  unsigned int *_chrsmFirstLocusPosition; //array length is _numChromosome
86  unsigned int _totalLength; // total map length
87  unsigned int _recombLength; // this is _totalLength + 1; used to draw the x-over spots
88  unsigned int _totalNumLoci;
89  double _resolution;
92 
93 
94 public:
95 
100 
102 
103  bool getGeneticMap (trait_t trait, double** table, unsigned int table_length);
104 
105  double getResolution ( ) {return _resolution;}
106 
107  double setResolution (double val)
108  {
109  _resolution = (val < _resolution ? val : _resolution);
110  return _resolution;
111  }
112 
113  void rescaleMap (double val);
114  void reset_tables ();
115  void clear ();
116 
122  void setLookupTable (unsigned int idx);
123 
131  void recombine (sex_t SEX);
132 
143  void placeRecombinationEvents (sex_t SEX, vector<unsigned int> junctions,
144  const vector<bool>& firstRecPos);
145 
151  void placeRecombinationEvents (sex_t SEX);
152 
154  vector< pair<unsigned int, unsigned int> > reduceJunctions (sex_t SEX, unsigned int trait_idx);
155 
163  bool registerIndForRecombine (unsigned long ID)
164  {
165  if (ID == _currentIndividual) return false;
166  else _currentIndividual = ID;
167  return true;
168  }
169 
171  unsigned int addTrait (trait_t trait, unsigned int nChrm, unsigned int nLoc, unsigned int* nLocChrm,
172  double resolution, unsigned int* locPositions);
173 
174  void unregisterTrait (trait_t trait);
175 
179  bool checkRegisteredTrait (trait_t trait);
180 
181 // void unregisterTrait_at (unsigned int traitIdx);
182 
184  vector< unsigned int>& getRecLoci (sex_t SEX, unsigned int trait)
185  {
186  return _recPositions[SEX][trait];
187  }
188 
190  vector< bool >& getFirstRecPosition (sex_t SEX)
191  { return _chrsmFirstRecombPosition[SEX]; }
192 
193  unsigned int* getLocusPositionTable (const trait_t trait)
194  {return _locPositionsPerTrait[ _traits[ trait ] ];}
195 };
196 
197 
198 // ------------------------------------------------------------------------------
202 // ------------------------------------------------------------------------------
204 
205  string _paramPrefix;
206 
208 
209 protected:
210 
211  //recombination:
212  unsigned int _mapIndex;
214  double _recombRate;
216  unsigned int _numChromosome;
217  unsigned int _numLoci;
219  unsigned int *_numLociPerChrmsm;
220  unsigned int *_chrsmLength;
221  unsigned int *_lociMapPositions;
222 
223  friend class TTraitWithMap;
224 
225 public:
226 
227 
228  static GeneticMap _map;
229 
230 
235  {}
236 
237  TTProtoWithMap(const TTProtoWithMap& TP);
238 
239  virtual ~TTProtoWithMap();
240 
243 
244  virtual bool is_mappable () {return true;}
246  virtual bool is_mapped () {return _map.checkRegisteredTrait(this->get_type());}
248  virtual vector< unsigned int > get_locus_map_positions ();
250 
251  void setMapIndex (unsigned int idx) {_mapIndex = idx;}
252 
253  unsigned int getMapIndex () {return _mapIndex;}
254 
255  static GeneticMap& getGeneticMapRef () {return _map;}
256 
257  double getRecombRate () const {return _recombRate;}
258 
259  bool setGeneticMapParameters (string prefix, unsigned int numLoci = 0);
260 
261  void addGeneticMapParameters (string prefix);
262 
264 
265  bool setRecombinationMapNonRandom (vector< vector<double> >& lociPositions);
266 
267  bool setRecombinationMapFixed ();
268 
269  bool setNumLociPerChromosome (string param_name);
270 
272 
273  void registerGeneticMap ();
274 
275  void unregisterFromGeneticMap ();
276 
277  bool areGeneticMapParamSet(string prefix);
278 
279  bool isRecombinationFree(string prefix);
280 
281  void recordRandomMap ();
282 
283  static void recombine (unsigned long indID);
284 
285  virtual void reset ();
286 
287 };
288 
289 
290 // ------------------------------------------------------------------------------
294 // ------------------------------------------------------------------------------
295 class TTraitWithMap : public TTrait {
296 
297 protected:
298 
300 
301 public:
302 
304 
305  virtual ~TTraitWithMap() {}
306 
307 };
308 
309 #endif
GeneticMap.
Definition: ttrait_with_map.h:45
void setLookupTable(unsigned int idx)
Bbuilds the lookup table for each trait.
Definition: ttrait_with_map.cc:983
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:190
unsigned int * getLocusPositionTable(const trait_t trait)
Definition: ttrait_with_map.h:193
void reset_tables()
Definition: ttrait_with_map.cc:1404
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:64
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:60
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:55
unsigned int _recombLength
Definition: ttrait_with_map.h:87
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:1313
double setResolution(double val)
Definition: ttrait_with_map.h:107
double _recombinationRate
Definition: ttrait_with_map.h:91
vector< unsigned int > _numChrsmPerTrait
Vector of number of chromosomes for each trait.
Definition: ttrait_with_map.h:62
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:78
double _totRecombEventsMean
Definition: ttrait_with_map.h:90
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:691
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:85
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:1115
unsigned int _totalLength
Definition: ttrait_with_map.h:86
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:69
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:74
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:84
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:66
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:924
GeneticMap()
Definition: ttrait_with_map.h:96
~GeneticMap()
Definition: ttrait_with_map.h:101
unsigned int _numChromosome
Definition: ttrait_with_map.h:83
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:88
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:1166
double _resolution
Definition: ttrait_with_map.h:89
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:673
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:649
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:184
void clear()
Definition: ttrait_with_map.cc:682
unsigned long _currentIndividual
Definition: ttrait_with_map.h:49
double getResolution()
Definition: ttrait_with_map.h:105
vector< unsigned int > _junctions
A vector to store the position of the recombination events.
Definition: ttrait_with_map.h:81
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:52
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:163
void rescaleMap(double val)
Definition: ttrait_with_map.cc:954
TTProtoWithMap.
Definition: ttrait_with_map.h:203
double _mapResolution
Definition: ttrait_with_map.h:215
static GeneticMap _map
Definition: ttrait_with_map.h:228
static GeneticMap & getGeneticMapRef()
Definition: ttrait_with_map.h:255
bool setNumLociPerChromosome(string param_name)
Definition: ttrait_with_map.cc:297
void unregisterFromGeneticMap()
Definition: ttrait_with_map.cc:584
virtual vector< unsigned int > get_locus_map_positions()
Returns the map positions of the loci in vector.
Definition: ttrait_with_map.cc:602
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:221
string _paramPrefix
Definition: ttrait_with_map.h:205
bool setRecombinationMapFixed()
Definition: ttrait_with_map.cc:388
bool setRecombinationMapNonRandom(vector< vector< double > > &lociPositions)
Definition: ttrait_with_map.cc:364
void recordRandomMap()
Definition: ttrait_with_map.cc:533
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:244
bool areGeneticMapParamSet(string prefix)
Definition: ttrait_with_map.cc:88
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:220
virtual bool is_mapped()
Checks if the trait's loci are placed on a genetic map.
Definition: ttrait_with_map.h:246
double _recombRate
Definition: ttrait_with_map.h:214
double * _recombRatePerChrmsm
Definition: ttrait_with_map.h:218
unsigned int _numLoci
Definition: ttrait_with_map.h:217
TTProtoWithMap()
Definition: ttrait_with_map.h:231
unsigned int getMapIndex()
Definition: ttrait_with_map.h:253
bool setGeneticMapParameters(string prefix, unsigned int numLoci=0)
Definition: ttrait_with_map.cc:125
double _totRecombEventsMean
Definition: ttrait_with_map.h:213
unsigned int _numChromosome
Definition: ttrait_with_map.h:216
bool isRecombinationFree(string prefix)
Definition: ttrait_with_map.cc:98
virtual void reset()
Definition: ttrait_with_map.cc:637
bool _isRegistered
Definition: ttrait_with_map.h:207
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:219
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:627
void registerGeneticMap()
Definition: ttrait_with_map.cc:575
void addGeneticMapParameters(string prefix)
Definition: ttrait_with_map.cc:77
unsigned int _mapIndex
Definition: ttrait_with_map.h:212
void setMapIndex(unsigned int idx)
Definition: ttrait_with_map.h:251
virtual ~TTProtoWithMap()
Definition: ttrait_with_map.cc:70
static void recombine(unsigned long indID)
Definition: ttrait_with_map.cc:592
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:438
double getRecombRate() const
Definition: ttrait_with_map.h:257
TTraitWithMap.
Definition: ttrait_with_map.h:295
TTProtoWithMap * _myProto
Definition: ttrait_with_map.h:299
virtual ~TTraitWithMap()
Definition: ttrait_with_map.h:305
TTraitWithMap()
Definition: ttrait_with_map.h:303
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
TTrait setter.
Definition: ttrait.h:130
virtual trait_t get_type() const =0
Type accessor.
Nemo2.
std::string trait_t
Trait types.
Definition: types.h:62
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35

Generated for Nemo v2.4.1 by  doxygen 1.9.1

Catalogued on GSR