Nemo  2.4.0b
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 
30 #ifndef TTRAIT_WITH_MAP_H
31 #define TTRAIT_WITH_MAP_H
32 
33 #include <string>
34 #include <vector>
35 #include <map>
36 #include <utility>
37 #include "ttrait.h"
38 
39 
40 // ------------------------------------------------------------------------------
44 // ------------------------------------------------------------------------------
45 
46 class GeneticMap {
47 
48 private:
49 
50  unsigned long _currentIndividual;
51 
53  map< trait_t, unsigned int > _traits;
54 
56  unsigned int _nTrait;
57 
61  vector< unsigned int* > _lociLookupTable; //this is the actual map, for each trait
63  vector< unsigned int > _numChrsmPerTrait;
65  vector< unsigned int > _numLociPerTrait;
67  vector< unsigned int* > _numLociPerChrsmPerTrait;
70  vector< unsigned int* > _locPositionsPerTrait;
71 
75  vector< vector < unsigned int > > _recPositions[2];
76 
79  vector< bool > _chrsmFirstRecombPosition[2];
80 
82  vector< unsigned int > _junctions;
83 
84  unsigned int _numChromosome;
85  unsigned int *_perChrsmLength; //array length is _numChromosome
86  unsigned int *_chrsmFirstLocusPosition; //array length is _numChromosome
87  unsigned int _totalLength; // total map length
88  unsigned int _recombLength; // this is _totalLength + 1; used to draw the x-over spots
89  unsigned int _totalNumLoci;
90  double _resolution;
93 
94 
95 public:
96 
101 
103 
104  bool getGeneticMap (trait_t trait, double** table, unsigned int table_length);
105 
106  double getResolution ( ) {return _resolution;}
107 
108  double setResolution (double val)
109  {
110  _resolution = (val < _resolution ? val : _resolution);
111  return _resolution;
112  }
113 
114  void rescaleMap (double val);
115  void reset_tables ();
116  void clear ();
117 
123  void setLookupTable (unsigned int idx);
124 
132  void recombine (sex_t SEX);
133 
135  vector< pair<unsigned int, unsigned int> > reduceJunctions (sex_t SEX, unsigned int trait_idx);
136 
144  bool registerIndForRecombine (unsigned long ID)
145  {
146  if (ID == _currentIndividual) return false;
147  else _currentIndividual = ID;
148  return true;
149  }
150 
152  unsigned int addTrait (trait_t trait, unsigned int nChrm, unsigned int nLoc, unsigned int* nLocChrm,
153  double resolution, unsigned int* locPositions);
154 
155  void unregisterTrait (trait_t trait);
156 
160  bool checkRegisteredTrait (trait_t trait);
161 
162 // void unregisterTrait_at (unsigned int traitIdx);
163 
165  vector< unsigned int>& getRecLoci (sex_t SEX, unsigned int trait)
166  {
167  return _recPositions[SEX][trait];
168  }
169 
171  vector< bool >& getFirstRecPosition (sex_t SEX)
172  { return _chrsmFirstRecombPosition[SEX]; }
173 
174  unsigned int* getLocusPositionTable (const trait_t trait)
175  {return _locPositionsPerTrait[ _traits[ trait ] ];}
176 };
177 
178 
179 // ------------------------------------------------------------------------------
183 // ------------------------------------------------------------------------------
185 
186  string _paramPrefix;
187 
189 
190 protected:
191 
192  //recombination:
193  unsigned int _mapIndex;
195  double _recombRate;
197  unsigned int _numChromosome;
198  unsigned int _numLoci;
200  unsigned int *_numLociPerChrmsm;
201  unsigned int *_chrsmLength;
202  unsigned int *_lociMapPositions;
203 
204  friend class TTraitWithMap;
205 
206 public:
207 
208 
209  static GeneticMap _map;
210 
211 
216  {}
217 
218  TTProtoWithMap(const TTProtoWithMap& TP);
219 
220  virtual ~TTProtoWithMap();
221 
224 
225  virtual bool is_mappable () {return true;}
227  virtual bool is_mapped () {return _map.checkRegisteredTrait(this->get_type());}
229  virtual vector< unsigned int > get_locus_map_positions ();
231 
232  void setMapIndex (unsigned int idx) {_mapIndex = idx;}
233 
234  unsigned int getMapIndex () {return _mapIndex;}
235 
236  static GeneticMap& getGeneticMapRef () {return _map;}
237 
238  double getRecombRate () const {return _recombRate;}
239 
240  bool setGeneticMapParameters (string prefix, unsigned int numLoci = 0);
241 
242  void addGeneticMapParameters (string prefix);
243 
245 
246  bool setRecombinationMapNonRandom (vector< vector<double> >& lociPositions);
247 
248  bool setRecombinationMapFixed ();
249 
250  bool setNumLociPerChromosome (string param_name);
251 
253 
254  void registerGeneticMap ();
255 
256  void unregisterFromGeneticMap ();
257 
258  bool areGeneticMapParamSet(string prefix);
259 
260  bool isRecombinationFree(string prefix);
261 
262  void recordRandomMap ();
263 
264  static void recombine (unsigned long indID);
265 
266  virtual void reset ();
267 
268 };
269 
270 
271 // ------------------------------------------------------------------------------
275 // ------------------------------------------------------------------------------
276 class TTraitWithMap : public TTrait {
277 
278 protected:
279 
281 
282 public:
283 
285 
286  virtual ~TTraitWithMap() {}
287 
288 };
289 
290 #endif
GeneticMap.
Definition: ttrait_with_map.h:46
void setLookupTable(unsigned int idx)
Bbuilds the lookup table for each trait.
Definition: ttrait_with_map.cc:974
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:171
unsigned int * getLocusPositionTable(const trait_t trait)
Definition: ttrait_with_map.h:174
void reset_tables()
Definition: ttrait_with_map.cc:1295
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
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:61
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
unsigned int _recombLength
Definition: ttrait_with_map.h:88
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:1205
double setResolution(double val)
Definition: ttrait_with_map.h:108
double _recombinationRate
Definition: ttrait_with_map.h:92
vector< unsigned int > _numChrsmPerTrait
Vector of number of chromosomes for each trait.
Definition: ttrait_with_map.h:63
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:79
double _totRecombEventsMean
Definition: ttrait_with_map.h:91
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
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:86
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
unsigned int _totalLength
Definition: ttrait_with_map.h:87
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:70
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:75
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:85
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:67
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:915
GeneticMap()
Definition: ttrait_with_map.h:97
~GeneticMap()
Definition: ttrait_with_map.h:102
unsigned int _numChromosome
Definition: ttrait_with_map.h:84
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:89
double _resolution
Definition: ttrait_with_map.h:90
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:674
void unregisterTrait(trait_t trait)
Definition: ttrait_with_map.cc:650
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:165
void clear()
Definition: ttrait_with_map.cc:683
unsigned long _currentIndividual
Definition: ttrait_with_map.h:50
double getResolution()
Definition: ttrait_with_map.h:106
vector< unsigned int > _junctions
A vector to store the position of the recombination events.
Definition: ttrait_with_map.h:82
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:53
bool registerIndForRecombine(unsigned long ID)
Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.
Definition: ttrait_with_map.h:144
void rescaleMap(double val)
Definition: ttrait_with_map.cc:945
TTProtoWithMap.
Definition: ttrait_with_map.h:184
double _mapResolution
Definition: ttrait_with_map.h:196
static GeneticMap _map
Definition: ttrait_with_map.h:209
static GeneticMap & getGeneticMapRef()
Definition: ttrait_with_map.h:236
bool setNumLociPerChromosome(string param_name)
Definition: ttrait_with_map.cc:298
void unregisterFromGeneticMap()
Definition: ttrait_with_map.cc:585
virtual vector< unsigned int > get_locus_map_positions()
Returns the map positions of the loci in vector.
Definition: ttrait_with_map.cc:603
unsigned int * _lociMapPositions
Definition: ttrait_with_map.h:202
string _paramPrefix
Definition: ttrait_with_map.h:186
bool setRecombinationMapFixed()
Definition: ttrait_with_map.cc:389
bool setRecombinationMapNonRandom(vector< vector< double > > &lociPositions)
Definition: ttrait_with_map.cc:365
void recordRandomMap()
Definition: ttrait_with_map.cc:534
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
bool areGeneticMapParamSet(string prefix)
Definition: ttrait_with_map.cc:89
unsigned int * _chrsmLength
Definition: ttrait_with_map.h:201
virtual bool is_mapped()
Checks if the trait's loci are placed on a genetic map.
Definition: ttrait_with_map.h:227
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
TTProtoWithMap()
Definition: ttrait_with_map.h:212
unsigned int getMapIndex()
Definition: ttrait_with_map.h:234
bool setGeneticMapParameters(string prefix, unsigned int numLoci=0)
Definition: ttrait_with_map.cc:126
double _totRecombEventsMean
Definition: ttrait_with_map.h:194
unsigned int _numChromosome
Definition: ttrait_with_map.h:197
bool isRecombinationFree(string prefix)
Definition: ttrait_with_map.cc:99
virtual void reset()
Definition: ttrait_with_map.cc:638
bool _isRegistered
Definition: ttrait_with_map.h:188
unsigned int * _numLociPerChrmsm
Definition: ttrait_with_map.h:200
void reset_recombination_pointers()
Definition: ttrait_with_map.cc:628
void registerGeneticMap()
Definition: ttrait_with_map.cc:576
void addGeneticMapParameters(string prefix)
Definition: ttrait_with_map.cc:78
unsigned int _mapIndex
Definition: ttrait_with_map.h:193
void setMapIndex(unsigned int idx)
Definition: ttrait_with_map.h:232
virtual ~TTProtoWithMap()
Definition: ttrait_with_map.cc:71
static void recombine(unsigned long indID)
Definition: ttrait_with_map.cc:593
bool setRecombinationMapRandom()
Definition: ttrait_with_map.cc:439
double getRecombRate() const
Definition: ttrait_with_map.h:238
TTraitWithMap.
Definition: ttrait_with_map.h:276
TTProtoWithMap * _myProto
Definition: ttrait_with_map.h:280
virtual ~TTraitWithMap()
Definition: ttrait_with_map.h:286
TTraitWithMap()
Definition: ttrait_with_map.h:284
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:46
TTrait setter.
Definition: ttrait.h:131
virtual trait_t get_type() const =0
Type accessor.
std::string trait_t
Trait types.
Definition: types.h:63
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36

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