Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TTQuanti Class Reference

TTQuanti. More...

#include <ttquanti.h>

+ Inheritance diagram for TTQuanti:
+ Collaboration diagram for TTQuanti:

Public Member Functions

 TTQuanti ()
 
 TTQuanti (const TTQuanti &T)
 
virtual ~TTQuanti ()
 
virtual void init ()
 
virtual void init_sequence ()
 
virtual void reset ()
 
virtual void inherit (TTrait *mother, TTrait *father)
 
virtual void mutate ()
 
virtual void * set_trait (void *value)
 
virtual void set_sequence (void **seq)
 
virtual void set_value ()
 
virtual void * getValue () const
 
virtual trait_t get_type () const
 
virtual void ** get_sequence () const
 
virtual double get_allele_value (int loc, int all)
 
virtual void set_allele_value (unsigned int locus, unsigned int allele, double value)
 
virtual void show_up ()
 
virtual TTQuanticlone ()
 
virtual TTQuantioperator= (const TTrait &T)
 
virtual bool operator== (const TTrait &T)
 
virtual bool operator!= (const TTrait &T)
 
virtual void store_data (BinaryStorageBuffer *saver)
 
virtual bool retrieve_data (BinaryStorageBuffer *reader)
 
void set_proto (TProtoQuanti *proto)
 
double get_additive_genotype (unsigned int trait)
 
double get_full_genotype (unsigned int trait)
 
void set_allele (int locus, int allele, double value)
 
void set_phenotype (unsigned int trait, double value)
 
- Public Member Functions inherited from TTrait
virtual void init ()=0
 Called to allocate the trait's genotypic sequences. More...
 
virtual void init_sequence ()=0
 Called at the start of each replicate, sets the initial genotypes. More...
 
virtual void reset ()=0
 Called at the end of each simulation/replicate, deallocates sequence memory. More...
 
virtual void inherit (TTrait *mother, TTrait *father)=0
 Inheritance procedure, creates a new trait from mother's and father's traits. More...
 
virtual void mutate ()=0
 Mutation procedure, perform mutations on the genes sequence. More...
 
virtual void * set_trait (void *value)=0
 Called to set the phenotypic to a particular value or to give context-dependant value(s) to the trait. More...
 
virtual void set_sequence (void **seq)=0
 Called to set the sequence pointer to an existing trait. More...
 
virtual double get_allele_value (int loc, int all)=0
 Called to read one allele value at a particular locus. More...
 
virtual void set_allele_value (unsigned int locus, unsigned int allele, double value)=0
 Called to change the allelic value at a particular locus. More...
 
virtual void set_value ()=0
 Tells the trait to set its phenotype from genotype, should be used instead of getValue(). More...
 
virtual void * getValue () const =0
 Genotype to phenotype mapper. More...
 
virtual trait_t get_type () const =0
 type accessor. More...
 
virtual void ** get_sequence () const =0
 sequence accessor. More...
 
virtual void show_up ()=0
 Writes some info to stdout. More...
 
virtual TTraitclone ()=0
 Returns a copy of itself. More...
 
virtual ~TTrait ()
 
- 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 ()
 

Private Attributes

double ** _sequence
 
double * _phenotypes
 
TProtoQuanti_myProto
 

Detailed Description

Constructor & Destructor Documentation

◆ TTQuanti() [1/2]

TTQuanti::TTQuanti ( )
inline
61 { }
TProtoQuanti * _myProto
Definition: ttquanti.h:105
double ** _sequence
Definition: ttquanti.h:102
double * _phenotypes
Definition: ttquanti.h:103

Referenced by clone().

+ Here is the caller graph for this function:

◆ TTQuanti() [2/2]

TTQuanti::TTQuanti ( const TTQuanti T)
inline
64 { }

◆ ~TTQuanti()

virtual TTQuanti::~TTQuanti ( )
inlinevirtual
66{reset();}
virtual void reset()
Definition: ttquanti.cc:1611

References reset().

Member Function Documentation

◆ clone()

virtual TTQuanti * TTQuanti::clone ( )
inlinevirtual

Implements TTrait.

83{return new TTQuanti(*this);}
TTQuanti()
Definition: ttquanti.h:60

References TTQuanti().

◆ get_additive_genotype()

double TTQuanti::get_additive_genotype ( unsigned int  trait)
1665{
1666 return _myProto->set_genotype_value_additive((const double**)_sequence, trait);
1667}
double set_genotype_value_additive(const double **sequ, const unsigned int trait)
Definition: ttquanti.cc:1045

References _myProto, _sequence, and TProtoQuanti::set_genotype_value_additive().

Referenced by TTQuantiSH::getVaNoDominance(), and TTQuantiFH::print().

+ Here is the caller graph for this function:

◆ get_allele_value()

double TTQuanti::get_allele_value ( int  loc,
int  all 
)
inlinevirtual

Implements TTrait.

1442{
1443 return (loc < (int)_myProto->_seq_length && all < 2 ? _sequence[all][loc] : 0);
1444}
unsigned int _seq_length
Total number of loci, same as _nb_locus.
Definition: ttquanti.h:202

References _myProto, TProtoQuanti::_seq_length, and _sequence.

Referenced by TProtoQuanti::mutate_diallelic_HC(), and TProtoQuanti::mutate_noHC().

+ Here is the caller graph for this function:

◆ get_full_genotype()

double TTQuanti::get_full_genotype ( unsigned int  trait)
1672{ //returns genotypic value that includes dominance effects if any
1673 return (_myProto->*_myProto->_set_genotype_func_ptr)((const double**)_sequence, trait);
1674}
double(TProtoQuanti::* _set_genotype_func_ptr)(const double **, const unsigned int)
Definition: ttquanti.h:240

References _myProto, _sequence, and TProtoQuanti::_set_genotype_func_ptr.

Referenced by TTQuantiSH::getVaWithDominance(), TTQuantiFH::print(), and store_quanti_trait_values().

+ Here is the caller graph for this function:

◆ get_sequence()

virtual void ** TTQuanti::get_sequence ( ) const
inlinevirtual

Implements TTrait.

79{return (void**)_sequence;}

References _sequence.

Referenced by TTQuantiSH::getVaWithDominance(), TTQuantiFH::print(), and TProtoQuanti::set_trait_value_noVE().

+ Here is the caller graph for this function:

◆ get_type()

virtual trait_t TTQuanti::get_type ( ) const
inlinevirtual

Implements TTrait.

78{return QUANT;}
#define QUANT
Definition: types.h:72

References QUANT.

Referenced by operator==().

+ Here is the caller graph for this function:

◆ getValue()

virtual void * TTQuanti::getValue ( ) const
inlinevirtual

Implements TTrait.

77{return _phenotypes;}

References _phenotypes.

Referenced by TTQuantiFH::print(), and store_quanti_trait_values().

+ Here is the caller graph for this function:

◆ inherit()

void TTQuanti::inherit ( TTrait mother,
TTrait father 
)
inlinevirtual

Implements TTrait.

1628{
1629 const double** mother_seq = (const double**)mother->get_sequence();
1630 const double** father_seq = (const double**)father->get_sequence();
1631
1632 _myProto->inherit(FEM, _sequence[FEM], mother_seq);
1633
1634 _myProto->inherit(MAL, _sequence[MAL], father_seq);
1635}
void inherit(sex_t SEX, double *seq, const double **parent)
Definition: ttquanti.cc:1113
virtual void ** get_sequence() const =0
sequence accessor.
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References _myProto, _sequence, FEM, TTrait::get_sequence(), TProtoQuanti::inherit(), and MAL.

◆ init()

void TTQuanti::init ( )
inlinevirtual

Implements TTrait.

1457{
1458 reset();
1459 _sequence = new double*[2];
1460 _sequence[0] = new double [ _myProto->_seq_length];
1461 _sequence[1] = new double [ _myProto->_seq_length];
1462
1463 _phenotypes = new double [_myProto->_nb_traits];
1464
1465}
unsigned int _nb_traits
Number of traits.
Definition: ttquanti.h:200

References _myProto, TProtoQuanti::_nb_traits, _phenotypes, TProtoQuanti::_seq_length, _sequence, and reset().

Referenced by operator=(), and set_sequence().

+ Here is the caller graph for this function:

◆ init_sequence()

void TTQuanti::init_sequence ( )
inlinevirtual

Implements TTrait.

1479{
1480 unsigned int pos;
1481 //options:
1482 //0: no variation, init value = (trait value)/(2*_nb_locus)
1483 //1: init value = (trait value)/(2*_nb_locus) + 1 mutation/locus
1484 //2: init value = (trait value)/(2*_nb_locus) + 1 mutation/locus+make parts ==> mean trait value doesn't change
1485 //3: init value = (trait value + random deviate N(0,sdVm))/(2*_nb_locus) + 1 mutation/locus+make parts
1486 //4: no variation and initialize with opposite effect alleles at alternating loci.
1487
1488 //decide what initial value to use
1489
1490 //Note: the initial values may have been set individually by LCE_quanti
1491 // it wouldn't make sense then to store the init values in the prototype
1492 // because init values are set patch-specific by LCE_quanti
1493 // Problem: without LCE_quanti, the original init values must not change from one replicate
1494 // to the other, so we use a local variable
1495
1496 double my_init[_myProto->_nb_traits];
1497
1498 if(_myProto->_doInitMutation == 3) {
1499
1500 double sdVm;
1501
1502 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1503 // sdVm = sqrt(4*_nb_locus*_mut_rate*_myProto->get_trait_var(j)); //trait variance = 2Vm
1504 sdVm = 0.25;
1505 my_init[j] = (_myProto->_init_value[j] + RAND::Gaussian(sdVm)) / (2*_myProto->_nb_locus);
1506 }
1507
1508 } else {
1509
1510 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) my_init[j] = _myProto->_init_value[j] / (2*_myProto->_nb_locus);
1511
1512 }
1513
1514 if(_myProto->_allele_model < 3) { //for the di-allelic models
1515
1516 if (_myProto->_doInitMutation != 4){
1517 for(unsigned int i = 0; i < _myProto->_nb_locus; i++) {
1518 pos = i * _myProto->_nb_traits;
1519 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1520 _sequence[0][pos] = _myProto->_allele_value[i][0]; //set with the positive allele value
1521 _sequence[1][pos] = _myProto->_allele_value[i][0];
1522 pos++;
1523 }
1524 }
1525
1526 } else {
1527 //this is intended for a diallelic model with no initial variance
1528
1529 for(unsigned int i = 0; i < _myProto->_nb_locus; i++) {
1530 pos = i * _myProto->_nb_traits;
1531 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1532 if (i % 2 == 0){
1533 _sequence[0][pos] = _myProto->_allele_value[i][0]; //set with the positive allele value
1534 _sequence[1][pos] = _myProto->_allele_value[i][0];
1535 pos++;
1536 } else {
1537 _sequence[0][pos] = _myProto->_allele_value[i][0]*-1; //set with the negative allele value
1538 _sequence[1][pos] = _myProto->_allele_value[i][0]*-1;
1539 pos++;
1540 }
1541 }
1542 }
1543
1544 }
1545 } else {
1546
1547 //set the allele values from the trait value
1548 for(unsigned int i = 0; i < _myProto->_nb_locus; i++) {
1549 pos = i * _myProto->_nb_traits;
1550 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1551 _sequence[0][pos] = my_init[j];
1552 _sequence[1][pos] = my_init[j];
1553 pos++;
1554 }
1555 }
1556 }
1557
1558
1559 //add random effects to allele values if needed
1561
1562 double *mut1, *mut2;
1563 unsigned int L;
1564
1565 for(unsigned int i = 0; i < _myProto->_nb_locus; i++) {
1566
1567 pos = i * _myProto->_nb_traits;
1568
1569 mut1 = (_myProto->*_myProto->_getMutationValues)(i);
1570 mut2 = (_myProto->*_myProto->_getMutationValues)(i);
1571
1572 if(_myProto->_allele_model < 3) { //diallelic models
1573
1574 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1575 _sequence[0][pos] = mut1[j];
1576 _sequence[1][pos] = mut2[j];
1577 pos++;
1578 }
1579
1580 } else {
1581
1582 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1583 _sequence[0][pos] += mut1[j];
1584 _sequence[1][pos] += mut2[j];
1585 pos++;
1586 }
1587
1588 if(_myProto->_doInitMutation > 1) { // the make-parts algorithm
1589
1590 //select a random locus
1591 do{
1593 }while(L == i);
1594
1595 pos = L * _myProto->_nb_traits;
1596 //subtract the previous random deviates from that locus
1597 for(unsigned int j = 0; j < _myProto->_nb_traits; j++) {
1598 _sequence[0][pos] -= mut1[j];
1599 _sequence[1][pos] -= mut2[j];
1600 pos++;
1601 }
1602 }
1603 }
1604 }
1605 }
1606
1607}
static double Gaussian(double sigma)
Definition: Uniform.h:262
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
unsigned int _allele_model
Definition: ttquanti.h:203
unsigned int _doInitMutation
Definition: ttquanti.h:219
double *(TProtoQuanti::* _getMutationValues)(unsigned int)
Definition: ttquanti.h:237
double * _init_value
Definition: ttquanti.h:205
unsigned int _nb_locus
Total number of loci, for all traits.
Definition: ttquanti.h:198
double ** _allele_value
Definition: ttquanti.h:204

References TProtoQuanti::_allele_model, TProtoQuanti::_allele_value, TProtoQuanti::_doInitMutation, TProtoQuanti::_getMutationValues, TProtoQuanti::_init_value, _myProto, TProtoQuanti::_nb_locus, TProtoQuanti::_nb_traits, _sequence, RAND::Gaussian(), and RAND::Uniform().

Referenced by LCE_QuantiInit::init_trait_value().

+ Here is the caller graph for this function:

◆ mutate()

void TTQuanti::mutate ( )
inlinevirtual

Implements TTrait.

1640{
1641 _myProto->mutate(this);
1642}
void mutate(TTQuanti *ind)
Definition: ttquanti.cc:1211

References _myProto, and TProtoQuanti::mutate().

◆ operator!=()

bool TTQuanti::operator!= ( const TTrait T)
virtual

Implements TTrait.

1432 {
1433 if(!((*this) == T) )
1434 return true;
1435 else
1436 return false;
1437 }

◆ operator=()

TTQuanti & TTQuanti::operator= ( const TTrait T)
virtual

Implements TTrait.

1395{
1396 const TTQuanti& TQ = dynamic_cast<const TTQuanti&>(T);
1397
1398 assert(*this == TQ); // to make sure that the sequences are of same length
1399
1400 if(this != &TQ) {
1401
1402 init();
1403
1404 memcpy(_sequence[0], TQ._sequence[0], _myProto->_seq_length*sizeof(double));
1405 memcpy(_sequence[1], TQ._sequence[1], _myProto->_seq_length*sizeof(double));
1406
1407 set_value();
1408 }
1409
1410 return *this;
1411}
TTQuanti.
Definition: ttquanti.h:56
virtual void set_value()
Definition: ttquanti.cc:1646
virtual void init()
Definition: ttquanti.cc:1456

References _myProto, TProtoQuanti::_seq_length, _sequence, init(), and set_value().

◆ operator==()

bool TTQuanti::operator== ( const TTrait T)
virtual

Implements TTrait.

1416 {
1417 if(this->get_type().compare(T.get_type()) != 0) return false;
1418
1419 const TTQuanti& TQ = dynamic_cast<const TTQuanti&>(T);
1420
1421 if(this != &TQ) {
1422 if(_myProto->_nb_locus != TQ._myProto->_nb_locus) return false;
1423 if(_myProto->_nb_traits != TQ._myProto->_nb_traits) return false;
1424 if(_myProto->_seq_length != TQ._myProto->_seq_length) return false;
1425 }
1426 return true;
1427 }
virtual trait_t get_type() const
Definition: ttquanti.h:78
virtual trait_t get_type() const =0
type accessor.

References _myProto, TProtoQuanti::_nb_locus, TProtoQuanti::_nb_traits, TProtoQuanti::_seq_length, get_type(), and TTrait::get_type().

◆ reset()

void TTQuanti::reset ( )
inlinevirtual

Implements TTrait.

1612{
1613 if(_sequence != NULL) {
1614 delete [] _sequence[0];
1615 delete [] _sequence[1];
1616 delete [] _sequence;
1617 _sequence = NULL;
1618 }
1619
1620 if(_phenotypes != NULL) delete [] _phenotypes;
1621 _phenotypes = NULL;
1622
1623}

References _phenotypes, and _sequence.

Referenced by init(), and ~TTQuanti().

+ Here is the caller graph for this function:

◆ retrieve_data()

bool TTQuanti::retrieve_data ( BinaryStorageBuffer reader)
inlinevirtual

Implements StorableComponent.

1687{
1688 reader->read(_sequence[0],_myProto->_seq_length*sizeof(double));
1689 reader->read(_sequence[1],_myProto->_seq_length*sizeof(double));
1690 return true;
1691}
void read(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:162

References _myProto, TProtoQuanti::_seq_length, _sequence, and BinaryStorageBuffer::read().

◆ set_allele()

void TTQuanti::set_allele ( int  locus,
int  allele,
double  value 
)
inline
97{_sequence[allele][locus] = value;}

References _sequence.

Referenced by LCE_QuantiInit::init_allele_freq(), TProtoQuanti::mutate_diallelic_HC(), TProtoQuanti::mutate_HC(), and TProtoQuanti::mutate_noHC().

+ Here is the caller graph for this function:

◆ set_allele_value()

void TTQuanti::set_allele_value ( unsigned int  locus,
unsigned int  allele,
double  value 
)
inlinevirtual

Implements TTrait.

1449{
1450 assert(locus < _myProto->_nb_locus && allele < 2);
1451 _sequence[allele][locus] = value;
1452}

References _sequence.

◆ set_phenotype()

void TTQuanti::set_phenotype ( unsigned int  trait,
double  value 
)
1656{
1657 assert(trait < _myProto->_nb_traits && _phenotypes != NULL);
1658
1659 _phenotypes[trait] = value;
1660}

References _phenotypes.

◆ set_proto()

void TTQuanti::set_proto ( TProtoQuanti proto)
inline
93{_myProto = proto;}

References _myProto.

Referenced by TProtoQuanti::hatch().

+ Here is the caller graph for this function:

◆ set_sequence()

void TTQuanti::set_sequence ( void **  seq)
virtual

Implements TTrait.

1470{
1471 init();
1472 memcpy(_sequence[0], seq[0], _myProto->_seq_length*sizeof(double));
1473 memcpy(_sequence[1], seq[1], _myProto->_seq_length*sizeof(double));
1474}

References _myProto, TProtoQuanti::_seq_length, _sequence, and init().

Referenced by TTQuantiFH::FHread().

+ Here is the caller graph for this function:

◆ set_trait()

virtual void * TTQuanti::set_trait ( void *  value)
inlinevirtual

Implements TTrait.

74{return value;}

◆ set_value()

void TTQuanti::set_value ( )
inlinevirtual

Implements TTrait.

1647{
1648 for (int i = 0; i < _myProto->_nb_traits; ++i) {
1650 }
1651}
double(TProtoQuanti::* _set_trait_value_func_ptr)(const TTQuanti *, const unsigned int)
Definition: ttquanti.h:239

References _myProto, TProtoQuanti::_nb_traits, _phenotypes, and TProtoQuanti::_set_trait_value_func_ptr.

Referenced by TTQuantiFH::FHread(), LCE_QuantiInit::init_allele_freq(), LCE_QuantiInit::init_trait_value(), and operator=().

+ Here is the caller graph for this function:

◆ show_up()

void TTQuanti::show_up ( )
virtual

Implements TTrait.

1696{
1697 message("\
1698 Trait's type: QUANTI\n\
1699 traits: %i\n\
1700 loci: %i\n\
1701 seq length: %i\n",_myProto->_nb_traits,_myProto->_nb_locus
1703
1704 for(unsigned int i = 0; i < _myProto->_nb_traits; i++)
1705 message("phenotype %i: %f\n",i+1,_phenotypes[i]);
1706
1707 message("_sequence: \n0:");
1708 unsigned int loc;
1709 for(unsigned int i = 0; i < _myProto->_nb_traits; ++i) {
1710 message("\nt%i:",i+1);
1711 for(unsigned int j = 0; (j < _myProto->_nb_locus); ++j) {
1712 loc = j * _myProto->_nb_traits + i;
1713 message("%.3f,",_sequence[0][loc]);
1714 }
1715 }
1716 message("\n1:");
1717 for(unsigned int i = 0; i < _myProto->_nb_traits; ++i) {
1718 message("\nt%i:",i+1);
1719 for(unsigned int j = 0; (j < _myProto->_nb_locus); ++j) {
1720 loc = j * _myProto->_nb_traits + i;
1721 message("%.3f,",_sequence[1][loc]);
1722 }
1723 }
1724 message("\n");
1725
1726}
void message(const char *message,...)
Definition: output.cc:40

References _myProto, TProtoQuanti::_nb_locus, TProtoQuanti::_nb_traits, _phenotypes, TProtoQuanti::_seq_length, _sequence, and message().

◆ store_data()

void TTQuanti::store_data ( BinaryStorageBuffer saver)
inlinevirtual

Implements StorableComponent.

1679{
1680 saver->store(_sequence[0],_myProto->_seq_length*sizeof(double));
1681 saver->store(_sequence[1],_myProto->_seq_length*sizeof(double));
1682}
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.cc:16

References _myProto, TProtoQuanti::_seq_length, _sequence, and BinaryStorageBuffer::store().

Member Data Documentation

◆ _myProto

◆ _phenotypes

double* TTQuanti::_phenotypes
private

◆ _sequence


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

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR