Nemo  2.3.46
GeneticMap Class Reference

GeneticMap. More...

#include <ttrait_with_map.h>

+ Collaboration diagram for GeneticMap:

Public Member Functions

 GeneticMap ()
 
 ~GeneticMap ()
 
double getResolution ()
 
double setResolution (double val)
 
void rescaleMap (double val)
 
void reset_tables ()
 
void clear ()
 
void setLookupTable (unsigned int idx)
 Bbuilds the lookup table for each trait. More...
 
void recombine (sex_t SEX)
 Called by TTProtoWithMap::recombine twice to create the two gametes necessary for the creation of a new individual. More...
 
bool registerIndForRecombine (unsigned long ID)
 Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine. More...
 
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. More...
 
void unregisterTrait (trait_t trait)
 
vector< unsigned int > & getRecLoci (sex_t SEX, unsigned int trait)
 Returns a vector of the loci where crossing-overs take place. More...
 
vector< bool > & getFirstRecPosition (sex_t SEX)
 Returns the vector of the first chromosome position for recombination, used for all traits. More...
 

Private Attributes

unsigned long _currentIndividual
 
map< trait_t, unsigned int_traits
 Table mapping trait type to its position index in the following tables. More...
 
unsigned int _nTrait
 Number of traits registered in the map. More...
 
vector< unsigned int * > _lociLookupTable
 A list of tables that map the map position (cM) to a locus, for each trait. More...
 
vector< unsigned int_numChrsmPerTrait
 Vector of number of chromosomes for each trait. More...
 
vector< unsigned int_numLociPerTrait
 Vector of number of loci for each trait. More...
 
vector< unsigned int * > _numLociPerChrsmPerTrait
 Vector containing a table of number of loci per chromosome for each trait. More...
 
vector< unsigned int * > _locPositionsPerTrait
 Vector containing the table of map position for the loci of each trait. More...
 
vector< vector< unsigned int > > _recPositions [2]
 Vector of tables containing, for each trait, the locus number at which x-overs happen. More...
 
vector< bool > _chrsmFirstRecombPosition [2]
 Two vectors holding the starting copy of each chromosome to use when creating the two gametes that are used to create a new individual. More...
 
unsigned int _numChromosome
 
unsigned int_perChrsmLength
 
unsigned int_chrsmFirstLocusPosition
 
unsigned int _totalLength
 
unsigned int _totalNumLoci
 
double _resolution
 
double _totRecombEventsMean
 

Detailed Description

Constructor & Destructor Documentation

GeneticMap::GeneticMap ( )
inline
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
double _resolution
Definition: ttrait_with_map.h:85
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:84
double _totRecombEventsMean
Definition: ttrait_with_map.h:86
unsigned int _totalLength
Definition: ttrait_with_map.h:83
unsigned int _numChromosome
Definition: ttrait_with_map.h:80
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:82
unsigned long _currentIndividual
Definition: ttrait_with_map.h:50
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:81
GeneticMap::~GeneticMap ( )
inline

References reset_tables().

96 {reset_tables();}
void reset_tables()
Definition: ttrait_with_map.cc:972

Member Function Documentation

unsigned int GeneticMap::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.

References _chrsmFirstLocusPosition, _lociLookupTable, _locPositionsPerTrait, _nTrait, _numChromosome, _numChrsmPerTrait, _numLociPerChrsmPerTrait, _numLociPerTrait, _perChrsmLength, _recPositions, _resolution, _totalLength, _totalNumLoci, _totRecombEventsMean, _traits, fatal(), rescaleMap(), reset_tables(), and setLookupTable().

Referenced by TTProtoWithMap::registerGeneticMap().

552 {
553  map<trait_t, unsigned int>::iterator tIter;
554 
555  unsigned int traitIdx = 0;
556 
557  bool do_add = true;
558 
559  tIter = _traits.find(trait);
560 
561  if ( tIter != _traits.end() ) {
562  //this shouldn't happen... unless we are loading a pop from source!!
563 
564  traitIdx = tIter->second;
565 
566  if(_numChrsmPerTrait[traitIdx] != nChrm)
567  fatal("mismatch while loading source population and resetting genetic map for trait \"%s\"\n>>>>> number of chromosomes differ (%i != %i)\n>>>>> please check match between init file and source population\n",trait.c_str(),_numChrsmPerTrait[traitIdx],nChrm);
568 
569  if(_numLociPerTrait[traitIdx] != nLoc)
570  fatal("mismatch while loading source population and resetting genetic map for trait \"%s\"\n>>>>> number of loci differ (%i != %i)\n>>>>> please check match between init file and source population\n",trait.c_str(),_numLociPerTrait[traitIdx], nLoc);
571 
572  unsigned int *locTable = _numLociPerChrsmPerTrait[traitIdx];
573 
574  for (unsigned int i=0; i<nChrm; i++)
575  if(locTable[i] != nLocChrm[i])
576  fatal("mismatch while loading source population and resetting genetic map for trait \"%s\"\n>>>>> number of loci differ (%i != %i) on chromosome %i\n>>>>> please check match between init file and source population\n",trait.c_str(),locTable[i], nLocChrm[i], i+1);
577 
578 // warning("ignoring locus positions saved in source population while resetting genetic map for trait \"%s\"",trait.c_str());
579 // warning("loci positions are set from parameters in the init file only, please check manually for mismatch\n");
580 
581  do_add = false;
582 
583  }
584 
585  if (_nTrait == 0) { //this is the first trait to register its map
586 
587  _numChromosome = nChrm;
588  _totalNumLoci = nLoc;
589  _resolution = resolution;
590  _totalLength = locPositions[nLoc-1];
591 // cout << "GeneticMap::addTrait\n";
592 // cout << " _numChromosome = "<<nChrm<<endl;
593 // cout << " _totalNumLoci = "<<_totalNumLoci<<endl;
594 // cout << " _resolution = "<<_resolution<<endl;
595 // cout << " _totalLength = "<<_totalLength<<endl;
596 
597  //destroy all previously allocated tables
598  reset_tables();
599 
600  _perChrsmLength = new unsigned int[_numChromosome];
601  _chrsmFirstLocusPosition = new unsigned int[_numChromosome];
602 
603  } else {
604  //we have already registered some trait's genetic map, we append this trait's info and update the map
605 
606  if (nChrm != _numChromosome) //check chromosome numbers
607  fatal("Traits in init file don't have same number of chromosomes, cannot set the genetic map!\n");
608 
609  //number of loci
610  _totalNumLoci = max(_totalNumLoci, nLoc);
611 
612  //setting the resolution:
613  if (resolution < _resolution) {
614 
615  rescaleMap(resolution);
616 
617  } else if (resolution > _resolution) {
618 
619  double ratio = resolution/_resolution;
620 
621  for(unsigned int i = 0; i < nLoc; ++i)
622  locPositions[i] = (unsigned int)((double)locPositions[i]*ratio);
623  }
624 
625  }
626 
627  if(do_add) { //only at the start of a simulation, not when loading pop from binary source
628 
629  traitIdx = _nTrait;
630 
631  _traits[trait] = _nTrait++;
632 
633 
634  //---- record num chrmsm
635  if ( _numChrsmPerTrait.size() != _nTrait -1 ) {
636  fatal("Genetic map::wrong size of table of num chrms per trait (%i != %i)",
637  _numChrsmPerTrait.size(), _nTrait -1);
638  } else
639  _numChrsmPerTrait.push_back(nChrm);
640 
641  //---- record num loci
642  if ( _numLociPerTrait.size() != _nTrait -1 ) {
643  fatal("Genetic map::wrong size of table of num loci per trait (%i != %i)",
644  _numLociPerTrait.size(), _nTrait -1);
645  } else
646  _numLociPerTrait.push_back(nLoc);
647 
648  //---- record table of num loci per chrmsm
649  if ( _numLociPerChrsmPerTrait.size() != _nTrait -1 )
650  fatal("Genetic map::wrong size of table of num loci per chrms per trait (%i != %i)",
652 
653  unsigned int* locTable = new unsigned int[nChrm];
654 
655  for (unsigned int i = 0; i < nChrm; i++) locTable[i] = nLocChrm[i];
656 
657  _numLociPerChrsmPerTrait.push_back(locTable);
658 
659  //---- record the locus positions
660  if ( _locPositionsPerTrait.size() != _nTrait -1 ) {
661  fatal("Genetic map::wrong size of table of loc position per trait (%i != %i)",
662  _locPositionsPerTrait.size(), _nTrait-1);
663  }
664 
665  //copy the locus positions
666  unsigned int* posTable = new unsigned int[nLoc];
667 
668  for (unsigned int i = 0; i < nLoc; ++i) {
669  posTable[i] = locPositions[i];
670  }
671 
672  _locPositionsPerTrait.push_back(posTable);
673 
674 
675  //---- create tables to record positions of x-over, for each gamete (male and female)
676 
677  for(unsigned int s = 0; s < 2; ++s){
678  if ( _recPositions[s].size() != _nTrait -1 )
679  fatal("Genetic map::wrong size of rec positions table (%i != %i)",
680  _recPositions[s].size(), _nTrait-1);
681 
682  _recPositions[s].push_back(vector<unsigned int>()); //add an empty array for each trait
683  }
684 
685 
686  //---- set the map positions according to other trait's
687  //---- need to correctly set starting position and length of each chromosome
688 
689  if (_nTrait == 1) { //first trait to register
690 
691  for (unsigned int c = 0, stride = 0; c < _numChromosome; ++c) {
692  _chrsmFirstLocusPosition[c] = locPositions[stride];
693  _perChrsmLength[c] = locPositions[stride + nLocChrm[c] - 1] - locPositions[stride]; //position of last locus - position of first locus on that chromosome.
694  stride += nLocChrm[c];
695  }
696 
697  } else {
698 
699  for (unsigned int c = 0, lastPos, stride = 0; c < _numChromosome; ++c) {
700 
701  lastPos = max(locPositions[stride + nLocChrm[c] - 1],
703 
704  _chrsmFirstLocusPosition[c] = min(_chrsmFirstLocusPosition[c], locPositions[stride]);
705 
706  _perChrsmLength[c] = lastPos - _chrsmFirstLocusPosition[c];
707 
708  stride += nLocChrm[c];
709  }
710  }
711 
712  //---- compute total chromosome length
713  _totalLength = 0;
714  for (unsigned int c = 0; c < _numChromosome; ++c) _totalLength += _perChrsmLength[c];
715 
716  //---- mean num recombination events, map length of 1M = 1 x-over on average
717  _totRecombEventsMean = (double)_totalLength * 0.01 * _resolution;
718 
719 
720 
721  //---- create new slot for the lookup table of that trait
722  // will be allocated and filled in setLookupTable
723  if ( _lociLookupTable.size() != _nTrait -1 )
724  fatal("Genetic map::wrong size of loci lookup tables (%i != %i)",
725  _lociLookupTable.size(), _nTrait-1);
726 
727  _lociLookupTable.push_back(NULL);
728 
729  //---- set all lookup tables (all genetic maps):
730  // we reset all tables each time a trait is added because _totalLength changes
731  for (unsigned int t = 0; t < _nTrait; ++t) setLookupTable(t);
732 
733  }
734 
735  return traitIdx;
736 }
void setLookupTable(unsigned int idx)
Bbuilds the lookup table for each trait.
Definition: ttrait_with_map.cc:769
vector< unsigned int > _numChrsmPerTrait
Vector of number of chromosomes for each trait.
Definition: ttrait_with_map.h:63
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
double _resolution
Definition: ttrait_with_map.h:85
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:53
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:84
double _totRecombEventsMean
Definition: ttrait_with_map.h:86
unsigned int _totalLength
Definition: ttrait_with_map.h:83
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:69
void fatal(const char *str,...)
Definition: output.cc:90
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
void rescaleMap(double val)
Definition: ttrait_with_map.cc:740
unsigned int _numChromosome
Definition: ttrait_with_map.h:80
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:82
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
void reset_tables()
Definition: ttrait_with_map.cc:972
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:81
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:67
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
void GeneticMap::clear ( )

References _nTrait, _traits, and reset_tables().

Referenced by IndFactory::clearPrototype().

539 {
540  reset_tables();
541  _traits.clear();
542  _nTrait = 0;
543 }
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:53
void reset_tables()
Definition: ttrait_with_map.cc:972
vector< bool >& GeneticMap::getFirstRecPosition ( sex_t  SEX)
inline

Returns the vector of the first chromosome position for recombination, used for all traits.

Referenced by TProtoBDMI::inherit(), TProtoQuanti::inherit_low(), TProtoNeutralGenes::inherit_low(), and TProtoDeletMutations_bitstring::inherit_low().

156  { return _chrsmFirstRecombPosition[SEX]; }
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
vector< unsigned int>& GeneticMap::getRecLoci ( sex_t  SEX,
unsigned int  trait 
)
inline

Returns a vector of the loci where crossing-overs take place.

Referenced by TProtoBDMI::inherit(), TProtoQuanti::inherit_low(), TProtoNeutralGenes::inherit_low(), and TProtoDeletMutations_bitstring::inherit_low().

150  {
151  return _recPositions[SEX][trait];
152  }
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
double GeneticMap::getResolution ( )
inline

References _resolution.

Referenced by TTProtoWithMap::setRecombinationMapRandom().

98 {return _resolution;}
double _resolution
Definition: ttrait_with_map.h:85
void GeneticMap::recombine ( sex_t  SEX)

Called by TTProtoWithMap::recombine twice to create the two gametes necessary for the creation of a new individual.

This function sets the location of the x-over on the chromosome map and records the loci positions at which x-over happen for each trait separately. The positions are stored in GeneticMap::_recPositions, which are then passed to the trait-specific inheritance functions when setting up the genetics of the traits in new individuals.

Parameters
SEXthe origin of the gamete, whether from the father or the mother

References _chrsmFirstRecombPosition, _lociLookupTable, _nTrait, _numChromosome, _numLociPerTrait, _recPositions, _totalLength, _totalNumLoci, _totRecombEventsMean, RAND::Poisson(), RAND::RandBool(), and RAND::Uniform().

Referenced by TTProtoWithMap::recombine().

880 {
881  unsigned int nbRec = 0;
882 
883  //empty the array of x-over positions
884  for (unsigned int t = 0; t < _nTrait; t++) {
885  _recPositions[SEX][t].clear();
886  }
887 
888  //create a gamete:
889 
890  //draw the number of x-over depending on the total map size
891  nbRec = (unsigned int)RAND::Poisson( _totRecombEventsMean );
892 
893  //adjust
894  if(nbRec > _totalNumLoci - 1) nbRec = _totalNumLoci - 1;
895 
896 
897  //determine where the x-over will take place
898 
899  if(nbRec > 0) {
900 
901  unsigned int* pos = new unsigned int [nbRec];
902 
903  for(unsigned int i = 0; i < nbRec; i++) {
904 
905  //draw position of x-over:
906  pos[i] = RAND::Uniform()*_totalLength +1;
907  //the +1 is necessary because the lookupTable (the map) starts with position 0
908  //position 0 should never be drawn as it would suppress recombination b/n two first loci
909  //it is safe so because the lookupTable has _totalLength +1 elements
910  }
911 
912  //the (automatically sorted) table of < locus number, num of x-over at locus position >
913  map< unsigned int, unsigned int> cumul_rec_positions;
914 
915  //the iterator to read within the map
916  map< unsigned int, unsigned int>::const_iterator recIter;
917 
918  //set up trait recombination spots, more than one x-over may happen b/n two loci of a given trait
919  //two consecutive x-overs b/n two loci cancel each other
920  //we need to cound the number of consecutive x-overs for each trait separately
921  //the use of a map to store the x-over positions insure that they will be sorted
922  for (unsigned int t = 0; t < _nTrait; t++) {
923 
924  cumul_rec_positions.clear();
925 
926  for(unsigned int i = 0, hit, num_interleaved_xover; i < nbRec; i++) {
927 
928 
929  hit = _lociLookupTable[t][ pos[i] ];
930  //this gives the locus to the right of that 'hit' position
931 
932  num_interleaved_xover = cumul_rec_positions[hit];
933  //returns 0 if position hit was not yet recorded
934 
935  cumul_rec_positions[hit] = ++num_interleaved_xover;
936  //indicates that one more x-over happened b/n two loci
937 
938  }
939 // cout<<" --- recording rec position: ";
940  // record only the positions at which an odd number of x-over happened:
941  for (recIter = cumul_rec_positions.begin(); recIter != cumul_rec_positions.end(); recIter++) {
942 
943  if(recIter->second % 2) {_recPositions[SEX][t].push_back(recIter->first); //add locus position
944 
945 // cout<<recIter->first<<", ";
946  }
947  }
948 // cout<<endl;
949  }// end_for_traits
950 
951  delete [] pos;
952 
953  } // end_if_nbRec
954 
955  // we always add the last position possible, to avoid returning an empty vector
956  for (unsigned int t = 0; t < _nTrait; t++) {
957  _recPositions[SEX][t].push_back(_numLociPerTrait[t]);
958  }
959 
960  //set the starting point for each chromosome randomly (which chromosome copy to use first)
961 
962  _chrsmFirstRecombPosition[SEX].assign(_numChromosome, 0); //re-initialise the array
963 
964  for(unsigned int c = 0; c < _numChromosome; ++c) {
966  }
967 
968 }
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
unsigned int _totalNumLoci
Definition: ttrait_with_map.h:84
double _totRecombEventsMean
Definition: ttrait_with_map.h:86
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
unsigned int _totalLength
Definition: ttrait_with_map.h:83
static double Poisson(double mean)
From the Numerical Recieps.
Definition: Uniform.h:196
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 _numChromosome
Definition: ttrait_with_map.h:80
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
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
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:139
bool GeneticMap::registerIndForRecombine ( unsigned long  ID)
inline

Called by TTProtoWithMap::recombine with individual ID passed down from Individual::recombine.

Returns false when already called by the same individual. The function is called for each trait separately but recombination must be computed once per individual only. It is so because some functions create new individual's trait separately, for instance in breed_selection when traits under viability selection are created before neutral traits.

Parameters
IDthe ID number of the individual calling the recombination function

Referenced by TTProtoWithMap::recombine().

134  {
135  if (ID == _currentIndividual) return false;
136  else _currentIndividual = ID;
137  return true;
138  }
unsigned long _currentIndividual
Definition: ttrait_with_map.h:50
void GeneticMap::rescaleMap ( double  val)

References _chrsmFirstLocusPosition, _locPositionsPerTrait, _nTrait, _numChromosome, _numLociPerTrait, _perChrsmLength, _resolution, _totalLength, _totRecombEventsMean, and setLookupTable().

Referenced by addTrait().

741 {
742  assert(val < _resolution);
743 
744  double ratio = _resolution/val; //it is assumed that val < _resolution
745 
746  _resolution = val;
747 
748  //we have to update all positions
749  for (unsigned int i = 0; i < _nTrait; ++i) {
750  for (unsigned int j = 0; j < _numLociPerTrait[i]; ++j) {
751  _locPositionsPerTrait[i][j] *= ratio;
752  }
753  }
754 
755  for (unsigned int i = 0; i < _numChromosome; ++i) {
756  _perChrsmLength[i] *= ratio;
757  _chrsmFirstLocusPosition[i] *= ratio;
758  }
759 
760  _totalLength *= ratio;
761  _totRecombEventsMean = (double)_totalLength * 0.01 * _resolution;
762 
763  //reset all lookup tables, the total length has changed!
764  for (unsigned int i = 0; i < _nTrait; ++i) setLookupTable(i);
765 }
void setLookupTable(unsigned int idx)
Bbuilds the lookup table for each trait.
Definition: ttrait_with_map.cc:769
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
double _resolution
Definition: ttrait_with_map.h:85
double _totRecombEventsMean
Definition: ttrait_with_map.h:86
unsigned int _totalLength
Definition: ttrait_with_map.h:83
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:69
unsigned int _numChromosome
Definition: ttrait_with_map.h:80
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:82
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:81
void GeneticMap::reset_tables ( )

References _chrsmFirstLocusPosition, _chrsmFirstRecombPosition, _lociLookupTable, _locPositionsPerTrait, _numChrsmPerTrait, _numLociPerChrsmPerTrait, _numLociPerTrait, _perChrsmLength, _recPositions, and error().

Referenced by addTrait(), clear(), and ~GeneticMap().

973 {
974  if(_perChrsmLength != NULL) delete [] _perChrsmLength;
975  _perChrsmLength = NULL;
976 
979 
980  _numChrsmPerTrait.clear();
981  _numLociPerTrait.clear();
982 
983  for (unsigned int i = 0; i < _lociLookupTable.size(); ++i) {
984  if(_lociLookupTable[i] != NULL) delete [] _lociLookupTable[i];
985  else error("GeneticMap::reset_tables::found null pointer in _lociLookupTable\n");
986  }
987  _lociLookupTable.clear();
988 
989  for (unsigned int i = 0; i < _numLociPerChrsmPerTrait.size(); ++i) {
990  if(_numLociPerChrsmPerTrait[i] != NULL) delete [] _numLociPerChrsmPerTrait[i];
991  else error("GeneticMap::reset_tables::found null pointer in _numLociPerChrsmPerTrait\n");
992  }
993  _numLociPerChrsmPerTrait.clear();
994 
995  for (unsigned int i = 0; i < _locPositionsPerTrait.size(); ++i) {
996  if(_locPositionsPerTrait[i] != NULL) delete [] _locPositionsPerTrait[i];
997  else error("GeneticMap::reset_tables::found null pointer in _locPositionsPerTrait\n");
998  }
999  _locPositionsPerTrait.clear();
1000 
1001  _recPositions[0].clear();
1002  _recPositions[1].clear();
1003 
1004  _chrsmFirstRecombPosition[0].clear();
1005  _chrsmFirstRecombPosition[1].clear();
1006 
1007 }
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:78
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:69
int error(const char *str,...)
Definition: output.cc:73
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 * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:82
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:81
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:67
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
void GeneticMap::setLookupTable ( unsigned int  idx)

Bbuilds the lookup table for each trait.

A lookup table maps a chromosomal position to a locus so that when a x-over is placed at a given map position, the corresponding locus can be directly found. The size of the lookup table depends on the _totalLength and _resolution of the map. The lookup table for a 1M map at the 0.01 cM scale will have 10,000 elements.

Parameters
idxthe index of the trait in the table (stored in the trait prototype)

!!! +1 needed here because map must start with 0 !!!!

!!! this means mumLocus may be returned, adjust _recPositions accordingly !!!!

References _chrsmFirstLocusPosition, _lociLookupTable, _locPositionsPerTrait, _numChromosome, _numLociPerChrsmPerTrait, _numLociPerTrait, _perChrsmLength, _resolution, _totalLength, _totRecombEventsMean, and fatal().

Referenced by addTrait(), and rescaleMap().

770 {
771  if(_lociLookupTable[idx] != NULL) delete [] _lociLookupTable[idx];
772 
773  _lociLookupTable[idx] = new unsigned int [_totalLength +1];
775 
776  if(_lociLookupTable[idx] == NULL)
777  fatal("GeneticMap::set lookup table: memory exhausted?\n");
778 
779  //------------------------------------------------------------------------
780  int pre_offset = 0, post_offset = 0, offset;
781 // cout<<"\n-- Genetic map #"<<idx<<":"<<endl;
782 
783  for (unsigned int loc = 0, pos = 0, stride = 0,
784  c = 0; c < _numChromosome; ++c) {
785 
786 // cout<<"Chrm "<<c+1<<" ("<<_perChrsmLength[c]<<" ["<<_resolution<<"cM]):\n"<<"{ ";
787  if(c > 0) loc = stride;
788 
789  stride += _numLociPerChrsmPerTrait[idx][c];
790 
791  //the map must start with position zero for the first locus with lowest position
792  pre_offset = -_chrsmFirstLocusPosition[c];
793 
794  //chromosomes are contiguous
795  offset = pre_offset + post_offset;
796 
797  for(; loc < stride && loc < _numLociPerTrait[idx]; ++loc)
798  {
799 
800  while (pos <= ( _locPositionsPerTrait[idx][loc] + offset) &&
801  ((int)pos - post_offset) <= (int)_perChrsmLength[c])
802  //table has 1 more elmnt, hence <=
803 
804  _lociLookupTable[idx][pos++] = loc;
805 
806 // cout << loc<<":"<<pos-1<<"("<<(int)pos - post_offset<<"; tab["<<pos-1<<"]="<<_lociLookupTable[idx][pos-1]<<") ";
807 
808  }
809 
810  post_offset += _perChrsmLength[c];
811 
812  while (pos < _totalLength && loc >= _numLociPerTrait[idx])
813  {
814 
815  _lociLookupTable[idx][pos++] = _numLociPerTrait[idx];
817  //(i.e. must contain num loci + 1 elements)!!!!
818 
819 
820 // cout << loc<<":"<<pos-1<<"(tab["<<pos-1<<"]="<<_lociLookupTable[idx][pos-1]<<") ";
821 
822  }
823 // cout << "}\n";
824  }
825 
826 
827 #ifdef _DEBUG_
828  cout << "\nGeneticMap::setLookupTable ("<<idx<<")\n";
829 
830  cout << "lookup table: [";
831  for(unsigned int i = 0; i < _totalLength+1; ++i)
832  if( i < 100 || !(i % 100) ) cout << _lociLookupTable[idx][i] << " ";
833  cout << "] (truncated if > 100 positions)\n";
834 
835  pre_offset = 0; post_offset = 0;
836  for(unsigned int c = 0, stride = 0; c < _numChromosome; c++) {
837 
838  cout<<"+++Chrm "<<c+1<<" ("<<_perChrsmLength[c]<<" ["<<_resolution<<"cM]):\n";
839  cout << "Loc positions: [ ";
840 
841  for(unsigned int i = 0; i < _numLociPerChrsmPerTrait[idx][c]; ++i)
842  if( i < 100 || !(i % 100) )
843  cout << _locPositionsPerTrait[idx][i+stride] << " " ;
844 
845  cout << "]\n";
846 
847  pre_offset = -_chrsmFirstLocusPosition[c];
848  offset = pre_offset + post_offset;
849 
850  cout << "lookup table: [ ";
851 
852  for(unsigned int cnt=0, i = _chrsmFirstLocusPosition[c]+offset; i < _chrsmFirstLocusPosition[c]+_perChrsmLength[c]+offset && cnt < 100; ++i, ++cnt){
853  cout << _lociLookupTable[idx][i] << " " ;
854  }
855  cout << "] (first 100 positions only)\n{position:locus} {";
856 
857  for(unsigned int i = 0; i < _numLociPerChrsmPerTrait[idx][c]-1; ++i)
858  if( i < 100 || !(i % 100) ) cout<<_locPositionsPerTrait[idx][i+stride]+offset<<":"<<_lociLookupTable[idx][_locPositionsPerTrait[idx][i+stride]+offset]<<", ";
859 
860  cout<<_locPositionsPerTrait[idx][stride + _numLociPerChrsmPerTrait[idx][c]-1]+offset
861  <<":"<<_lociLookupTable[idx][_locPositionsPerTrait[idx][stride + _numLociPerChrsmPerTrait[idx][c]-1]+offset]<<"}\n";
862 
863  post_offset += _perChrsmLength[c];
864  stride += _numLociPerChrsmPerTrait[idx][c];
865  }
866  cout<<endl;
867  // cout<<"Loc pos lookup table:"<<endl<<"{";
868  // for(unsigned int i = 0; i < _superChrsmLength; ++i)
869  // cout<<_recLociPositionTable[i]<<", ";
870  // cout<<"}"<<endl;
871 
872  cout<<" Tot map length: "<<_totalLength<<endl;
873  cout<<" Mean num recombination events: "<<_totRecombEventsMean<<endl;
874 #endif
875 }
double _resolution
Definition: ttrait_with_map.h:85
double _totRecombEventsMean
Definition: ttrait_with_map.h:86
unsigned int _totalLength
Definition: ttrait_with_map.h:83
vector< unsigned int * > _locPositionsPerTrait
Vector containing the table of map position for the loci of each trait.
Definition: ttrait_with_map.h:69
void fatal(const char *str,...)
Definition: output.cc:90
unsigned int _numChromosome
Definition: ttrait_with_map.h:80
unsigned int * _chrsmFirstLocusPosition
Definition: ttrait_with_map.h:82
vector< unsigned int > _numLociPerTrait
Vector of number of loci for each trait.
Definition: ttrait_with_map.h:65
unsigned int * _perChrsmLength
Definition: ttrait_with_map.h:81
vector< unsigned int * > _numLociPerChrsmPerTrait
Vector containing a table of number of loci per chromosome for each trait.
Definition: ttrait_with_map.h:67
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
double GeneticMap::setResolution ( double  val)
inline

References _resolution.

101  {
102  _resolution = (val < _resolution ? val : _resolution);
103  return _resolution;
104  }
double _resolution
Definition: ttrait_with_map.h:85
void GeneticMap::unregisterTrait ( trait_t  trait)

References _nTrait, _traits, and fatal().

Referenced by TTProtoWithMap::reset().

518 {
519  map<trait_t, unsigned int>::iterator tIter;
520 
521  tIter = _traits.find(trait);
522 
523  if ( tIter != _traits.end() ) {
524 
525 // cout<<"GeneticMap::unregisterTrait::"<<tIter->first<<" (idx: "<<tIter->second<<")"<<endl;
526 
527  _traits.erase(tIter);
528 
529 // cout<<"GeneticMap::unregisterTrait::done\n";
530  }
531  else fatal("Genetic map::unregisterTrait: trait \"%s\" is not registered\n", trait.c_str());
532 
533  _nTrait--;
534 }
unsigned int _nTrait
Number of traits registered in the map.
Definition: ttrait_with_map.h:56
map< trait_t, unsigned int > _traits
Table mapping trait type to its position index in the following tables.
Definition: ttrait_with_map.h:53
void fatal(const char *str,...)
Definition: output.cc:90

Member Data Documentation

unsigned int* GeneticMap::_chrsmFirstLocusPosition
private
vector< bool > GeneticMap::_chrsmFirstRecombPosition[2]
private

Two vectors holding the starting copy of each chromosome to use when creating the two gametes that are used to create a new individual.

Referenced by recombine(), and reset_tables().

unsigned long GeneticMap::_currentIndividual
private
vector< unsigned int* > GeneticMap::_lociLookupTable
private

A list of tables that map the map position (cM) to a locus, for each trait.

The length of the table is the length of the genetic map, which depends on the map resolution (cM by default).

Referenced by addTrait(), recombine(), reset_tables(), and setLookupTable().

vector< unsigned int* > GeneticMap::_locPositionsPerTrait
private

Vector containing the table of map position for the loci of each trait.

Referenced by addTrait(), rescaleMap(), reset_tables(), and setLookupTable().

unsigned int GeneticMap::_nTrait
private

Number of traits registered in the map.

Length of following arrays.

Referenced by addTrait(), clear(), recombine(), rescaleMap(), and unregisterTrait().

unsigned int GeneticMap::_numChromosome
private
vector< unsigned int > GeneticMap::_numChrsmPerTrait
private

Vector of number of chromosomes for each trait.

Referenced by addTrait(), and reset_tables().

vector< unsigned int* > GeneticMap::_numLociPerChrsmPerTrait
private

Vector containing a table of number of loci per chromosome for each trait.

Referenced by addTrait(), reset_tables(), and setLookupTable().

vector< unsigned int > GeneticMap::_numLociPerTrait
private

Vector of number of loci for each trait.

Referenced by addTrait(), recombine(), rescaleMap(), reset_tables(), and setLookupTable().

unsigned int* GeneticMap::_perChrsmLength
private
vector< vector < unsigned int > > GeneticMap::_recPositions[2]
private

Vector of tables containing, for each trait, the locus number at which x-overs happen.

Updated at each generation. There is matrix per sex/gamete with one trait per row and a variable number of elements in each row.

Referenced by addTrait(), recombine(), and reset_tables().

double GeneticMap::_resolution
private
unsigned int GeneticMap::_totalLength
private
unsigned int GeneticMap::_totalNumLoci
private

Referenced by addTrait(), and recombine().

double GeneticMap::_totRecombEventsMean
private
map< trait_t, unsigned int > GeneticMap::_traits
private

Table mapping trait type to its position index in the following tables.

Referenced by addTrait(), clear(), and unregisterTrait().


The documentation for this class was generated from the following files:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR