Nemo  2.2.0
Public Member Functions | Private Attributes
TTQuanti Class Reference

#include <ttquanti_double.h>

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

List of all members.

Public Member Functions

 TTQuanti ()
 TTQuanti (const TTQuanti &T)
 ~TTQuanti ()
virtual void init ()
 Called to allocate the trait's genotypic sequences.
virtual void init_sequence ()
 Called at the start of each replicate, sets the initial genotypes.
virtual void reset ()
 Called at the end of each simulation/replicate, deallocates sequence memory.
virtual void inherit (TTrait *mother, TTrait *father)
 Inheritance procedure, creates a new trait from mother's and father's traits.
virtual void mutate ()
 Mutation procedure, perform mutations on the genes sequence.
virtual void * set_trait (void *value)
 Called to set the phenotypic to a particular value or to give context-dependant value(s) to the trait.
virtual void set_sequence (void **seq)
 Called to set the sequence pointer to an existing trait.
virtual void set_value ()
 Tells the trait to set its phenotype from genotype, should be used instead of getValue().
virtual void * getValue ()
 Genotype to phenotype mapper.
virtual trait_t get_type () const
 type accessor.
virtual void ** get_sequence () const
 sequence accessor.
virtual void * get_allele (int loc, int all) const
 Called to read one allele value at a particular locus.
virtual void show_up ()
 Writes some info to stdout.
virtual TTQuanticlone ()
 Returns a copy of itself.
virtual TTQuantioperator= (const TTrait &T)
 Copies the complete state of the trait from right to left side of the operator, sequence data included.
virtual bool operator== (const TTrait &T)
 Checks for parameters equivalence, not genetic equivalence.
virtual bool operator!= (const TTrait &T)
double get_genotype (unsigned int trait)
virtual void store_data (BinaryStorageBuffer *saver)
 Interface to store the component data (e.g. gene values) into a binary buffer.
virtual bool retrieve_data (BinaryStorageBuffer *reader)
 Interface to retrieve the same data from the binary buffer.
void set_proto (TProtoQuanti *proto)
void set_nb_locus (unsigned int val)
void set_nb_traits (unsigned int val)
void set_seq_length (unsigned int val)
void set_genomic_mutation_rate (double val)
void set_init_value (double *val, bool doInit)
void set_init_value (double *val)
void set_mutation_fptr (double *(TProtoQuanti::*val)(void))
void set_inherit_fptr (void(TProtoQuanti::*val)(double *, double **))
void set_eVariance (double var)

Private Attributes

double ** sequence
double * _phenotypes
unsigned int _nb_locus
unsigned int _nb_traits
unsigned int _seq_length
double _genomic_mutation_rate
double * _init_value
bool _doInitMutation
double _eVariance
TProtoQuanti_myProto
double *(TProtoQuanti::* _getMutationValues )(void)
void(TProtoQuanti::* _inherit )(double *, double **)

Detailed Description

Definition at line 54 of file ttquanti_double.h.


Constructor & Destructor Documentation

TTQuanti::TTQuanti ( ) [inline]
TTQuanti::TTQuanti ( const TTQuanti T) [inline]
TTQuanti::~TTQuanti ( ) [inline]

Definition at line 71 of file ttquanti_double.h.

References reset().

{reset();}

Member Function Documentation

virtual TTQuanti* TTQuanti::clone ( ) [inline, virtual]

Returns a copy of itself.

Note: call the copy constructor of the trait which should only copy the parameters values not the complete state of the trait (i.e. shallow copy). The copy of the sequence data is made through the assignement operator!

Implements TTrait.

Definition at line 87 of file ttquanti_double.h.

References TTQuanti().

{return new TTQuanti(*this);}
virtual void* TTQuanti::get_allele ( int  loc,
int  all 
) const [inline, virtual]

Called to read one allele value at a particular locus.

Returns:
the allelic value at position 'all' at locus 'loc'
Parameters:
loclocus position in the sequence
allwhich allele we want to read the value from

Implements TTrait.

Definition at line 85 of file ttquanti_double.h.

References _seq_length, and sequence.

{return (loc < (int)_seq_length && all < 2 ? (void*)&sequence[all][loc] : 0);}
double TTQuanti::get_genotype ( unsigned int  trait)

Definition at line 1065 of file ttquanti_double.cc.

{
  unsigned int loc;
  double genotype = 0;
  
  for(unsigned int j = 0; j < _nb_locus; ++j) {
    loc = j * _nb_traits + trait;
    genotype += sequence[0][loc] + sequence[1][loc];
  } 
  return genotype;
}
virtual void** TTQuanti::get_sequence ( ) const [inline, virtual]

sequence accessor.

Returns:
the sequence pointer

Implements TTrait.

Definition at line 84 of file ttquanti_double.h.

References sequence.

{return (void**)sequence;}
virtual trait_t TTQuanti::get_type ( ) const [inline, virtual]

type accessor.

Returns:
the trait's type

Implements TTrait.

Definition at line 83 of file ttquanti_double.h.

References QUANT.

{return QUANT;}
virtual void* TTQuanti::getValue ( ) [inline, virtual]

Genotype to phenotype mapper.

Returns:
the phenotype computed from the genotype

Implements TTrait.

Definition at line 82 of file ttquanti_double.h.

References _phenotypes.

{return _phenotypes;}
void TTQuanti::inherit ( TTrait mother,
TTrait father 
) [inline, virtual]

Inheritance procedure, creates a new trait from mother's and father's traits.

Parameters:
motherthe mother's trait
fatherthe father's trait

Implements TTrait.

Definition at line 1006 of file ttquanti_double.cc.

{
  double** mother_seq = (double**)mother->get_sequence();
  double** father_seq = (double**)father->get_sequence();
  
  (_myProto->* _inherit) (sequence[0], mother_seq);
  
  (_myProto->* _inherit) (sequence[1], father_seq);
}
void TTQuanti::init ( ) [inline, virtual]

Called to allocate the trait's genotypic sequences.

Called each time a new Individual is created (Individual::init())

Implements TTrait.

Definition at line 949 of file ttquanti_double.cc.

{  
  sequence = new double*[2];
  sequence[0] = new double [_seq_length];
  sequence[1] = new double [_seq_length];
  if(!_phenotypes) _phenotypes = new double [_nb_traits];
}
void TTQuanti::init_sequence ( ) [inline, virtual]

Called at the start of each replicate, sets the initial genotypes.

Called by Individual::create().

Implements TTrait.

Definition at line 959 of file ttquanti_double.cc.

{
  unsigned int pos;
  
  for(unsigned int i = 0; i < _nb_locus; i++) {
    pos = i * _nb_traits;
    for(unsigned int j = 0; j < _nb_traits; j++) {
      sequence[0][pos] = _init_value[j]; 
      sequence[1][pos] = _init_value[j]; 
      pos++;
    }
  }
  
  if(_doInitMutation) {

    double *mut1, *mut2;

    for(unsigned int i = 0; i < _nb_locus; i++) {
      pos = i * _nb_traits;
      mut1 = (_myProto->*_getMutationValues)();
      mut2 = (_myProto->*_getMutationValues)();
      for(unsigned int j = 0; j < _nb_traits; j++) {
        sequence[0][pos] += mut1[j]; 
        sequence[1][pos] += mut2[j]; 
        pos++;
      }
    }
  }
  
}
void TTQuanti::mutate ( ) [inline, virtual]

Mutation procedure, perform mutations on the genes sequence.

Implements TTrait.

Definition at line 1018 of file ttquanti_double.cc.

{
  unsigned int NbMut = (unsigned int)RAND::Poisson(_genomic_mutation_rate);
  unsigned int mut_locus, mut_all, pos;
  double *effects;
  
  while(NbMut != 0) {
    mut_locus = RAND::Uniform(_nb_locus);
    //    cout<<"TTQuanti::mutate:: new mutation at <"<<mut_locus<<">"<<flush;
    effects = (_myProto->*_getMutationValues)();
    //    cout<<", new effects "<<effects[0]<<" "<<effects[1]<<flush;
    mut_all = RAND::RandBool();
    //    message(" at all %i\n",mut_all);
    pos = mut_locus*_nb_traits;
    for(unsigned int i = 0; i < _nb_traits; i++)
      sequence[mut_all][pos + i] += effects[i];
    
    NbMut--; 
  }
  
}
bool TTQuanti::operator!= ( const TTrait T) [virtual]

Implements TTrait.

Definition at line 939 of file ttquanti_double.cc.

{
  if(!((*this) == T) )
    return true;
  else
    return false;
}
TTQuanti & TTQuanti::operator= ( const TTrait ) [virtual]

Copies the complete state of the trait from right to left side of the operator, sequence data included.

Implements TTrait.

Definition at line 895 of file ttquanti_double.cc.

{  
  const TTQuanti& TQ = dynamic_cast<const TTQuanti&>(T);
  
  if(this != &TQ) {
    
    if( (*this) != TQ) {
      _nb_locus = TQ._nb_locus;
      _nb_traits = TQ._nb_traits;
      _seq_length = TQ._seq_length;
      _genomic_mutation_rate = TQ._genomic_mutation_rate;    
      reset();
      init();
    }
    _myProto = TQ._myProto;
    _getMutationValues = TQ._getMutationValues;
    _inherit = TQ._inherit;
    
    memcpy(sequence[0],TQ.sequence[0],_seq_length*sizeof(double));
    memcpy(sequence[1],TQ.sequence[1],_seq_length*sizeof(double));
    
    set_value();
  }
  
  return *this;
}
bool TTQuanti::operator== ( const TTrait ) [virtual]

Checks for parameters equivalence, not genetic equivalence.

Implements TTrait.

Definition at line 924 of file ttquanti_double.cc.

{ 
  if(this->get_type().compare(T.get_type()) != 0) return false;
  
  const TTQuanti& TQ = dynamic_cast<const TTQuanti&>(T);
  
  if(this != &TQ) {
    if(_nb_locus != TQ._nb_locus) return false;
    if(_nb_traits != TQ._nb_traits) return false;
  }
  return true;
}
void TTQuanti::reset ( ) [inline, virtual]

Called at the end of each simulation/replicate, deallocates sequence memory.

Implements TTrait.

Definition at line 992 of file ttquanti_double.cc.

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

{
  if(sequence != NULL) {
    delete [] sequence[0]; 
    delete [] sequence[1];
    delete [] sequence; 
    sequence = NULL;
  }
  if(_phenotypes != NULL) delete [] _phenotypes;
  _phenotypes = NULL;
}
virtual bool TTQuanti::retrieve_data ( BinaryStorageBuffer reader) [inline, virtual]

Interface to retrieve the same data from the binary buffer.

Implements StorableComponent.

Definition at line 97 of file ttquanti_double.h.

References _seq_length, BinaryStorageBuffer::read(), and sequence.

                                                             {reader->read(sequence[0],_seq_length*sizeof(double));
                                                              reader->read(sequence[1],_seq_length*sizeof(double));return true;}
void TTQuanti::set_eVariance ( double  var) [inline]

Definition at line 110 of file ttquanti_double.h.

References _eVariance.

{_eVariance = var;}
void TTQuanti::set_genomic_mutation_rate ( double  val) [inline]

Definition at line 105 of file ttquanti_double.h.

References _genomic_mutation_rate.

void TTQuanti::set_inherit_fptr ( void(TProtoQuanti::*)(double *, double **)  val) [inline]

Definition at line 109 of file ttquanti_double.h.

References _inherit.

{_inherit = val;}
void TTQuanti::set_init_value ( double *  val,
bool  doInit 
) [inline]

Definition at line 106 of file ttquanti_double.h.

References _doInitMutation, and _init_value.

{ _init_value = val; _doInitMutation = doInit;}
void TTQuanti::set_init_value ( double *  val) [inline]

Definition at line 107 of file ttquanti_double.h.

References _init_value.

{ _init_value = val;} //this is for the quanti_init LCE
void TTQuanti::set_mutation_fptr ( double *(TProtoQuanti::*)(void)  val) [inline]

Definition at line 108 of file ttquanti_double.h.

References _getMutationValues.

void TTQuanti::set_nb_locus ( unsigned int  val) [inline]

Definition at line 102 of file ttquanti_double.h.

References _nb_locus.

{_nb_locus = val;}
void TTQuanti::set_nb_traits ( unsigned int  val) [inline]

Definition at line 103 of file ttquanti_double.h.

References _nb_traits.

{_nb_traits = val;}
void TTQuanti::set_proto ( TProtoQuanti proto) [inline]

Definition at line 101 of file ttquanti_double.h.

References _myProto.

{_myProto = proto;}
void TTQuanti::set_seq_length ( unsigned int  val) [inline]

Definition at line 104 of file ttquanti_double.h.

References _seq_length.

{_seq_length = val;}
virtual void TTQuanti::set_sequence ( void **  seq) [inline, virtual]

Called to set the sequence pointer to an existing trait.

Parameters:
seqthe existing sequence pointer

Implements TTrait.

Definition at line 80 of file ttquanti_double.h.

References reset(), and sequence.

{reset(); sequence = (double**)seq;}
virtual void* TTQuanti::set_trait ( void *  value) [inline, virtual]

Called to set the phenotypic to a particular value or to give context-dependant value(s) to the trait.

Parameters:
valuethe value passed to the trait
Returns:
the argument passed

Implements TTrait.

Definition at line 79 of file ttquanti_double.h.

{return value;}
void TTQuanti::set_value ( ) [inline, virtual]

Tells the trait to set its phenotype from genotype, should be used instead of getValue().

Implements TTrait.

Definition at line 1042 of file ttquanti_double.cc.

{
  register unsigned int loc;
  
  for(unsigned int i = 0; i < _nb_traits; ++i) 
    _phenotypes[i] = 0;
  
  for(unsigned int j = 0; j < _nb_locus; ++j) {
    loc = j * _nb_traits;
    for(unsigned int i = 0; i < _nb_traits; ++i) {
      _phenotypes[i] += sequence[0][loc] + sequence[1][loc];
      loc++;
    }
  } 
  
  if(_eVariance != 0)
    for(unsigned int i = 0; i < _nb_traits; ++i) 
      _phenotypes[i] += RAND::Gaussian(_eVariance);
}
void TTQuanti::show_up ( ) [virtual]

Writes some info to stdout.

Implements TTrait.

Definition at line 1079 of file ttquanti_double.cc.

{
  message("\
          Trait's type: QUANTI\n\
          traits: %i\n\
          loci: %i\n",_nb_traits,_nb_locus);
  
  for(unsigned int i = 0; i < _nb_traits; i++)
    message("phenotype %i: %f\n",i+1,_phenotypes[i]);
  
  message("sequence: \n0:");
  unsigned int loc;
  for(unsigned int i = 0; i < _nb_traits; ++i) {
    message("\nt%i:",i+1);
    for(unsigned int j = 0; (j < _nb_locus); ++j) {
      loc = j * _nb_traits + i;
      message("%.3f,",sequence[0][loc]);
    }
  }
  message("\n1:");
  for(unsigned int i = 0; i < _nb_traits; ++i) {
    message("\nt%i:",i+1);
    for(unsigned int j = 0; (j < _nb_locus); ++j) {
      loc = j * _nb_traits + i;
      message("%.3f,",sequence[1][loc]);
    }
  }
  message("\n");
  
}  
virtual void TTQuanti::store_data ( BinaryStorageBuffer saver) [inline, virtual]

Interface to store the component data (e.g. gene values) into a binary buffer.

Implements StorableComponent.

Definition at line 95 of file ttquanti_double.h.

References _seq_length, sequence, and BinaryStorageBuffer::store().

                                                             {saver->store(sequence[0],_seq_length*sizeof(double));
                                                              saver->store(sequence[1],_seq_length*sizeof(double));}

Member Data Documentation

bool TTQuanti::_doInitMutation [private]

Definition at line 119 of file ttquanti_double.h.

Referenced by set_init_value().

double TTQuanti::_eVariance [private]

Definition at line 120 of file ttquanti_double.h.

Referenced by set_eVariance().

Definition at line 118 of file ttquanti_double.h.

Referenced by set_genomic_mutation_rate().

double*(TProtoQuanti::* TTQuanti::_getMutationValues)(void) [private]

Definition at line 123 of file ttquanti_double.h.

Referenced by set_mutation_fptr().

void(TProtoQuanti::* TTQuanti::_inherit)(double *, double **) [private]

Definition at line 124 of file ttquanti_double.h.

Referenced by set_inherit_fptr().

double * TTQuanti::_init_value [private]

Definition at line 118 of file ttquanti_double.h.

Referenced by set_init_value().

Definition at line 122 of file ttquanti_double.h.

Referenced by set_proto().

unsigned int TTQuanti::_nb_locus [private]

Definition at line 117 of file ttquanti_double.h.

Referenced by set_nb_locus().

unsigned int TTQuanti::_nb_traits [private]

Definition at line 117 of file ttquanti_double.h.

Referenced by set_nb_traits(), and TTQuanti().

double* TTQuanti::_phenotypes [private]

Definition at line 115 of file ttquanti_double.h.

Referenced by getValue(), and TTQuanti().

unsigned int TTQuanti::_seq_length [private]

Definition at line 117 of file ttquanti_double.h.

Referenced by get_allele(), retrieve_data(), set_seq_length(), and store_data().

double** TTQuanti::sequence [private]

Definition at line 114 of file ttquanti_double.h.

Referenced by get_allele(), get_sequence(), retrieve_data(), set_sequence(), and store_data().


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

Generated for Nemo v2.2.0 by  doxygen 1.7.5.1 -- Nemo is hosted by  SourceForge.net Logo