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

TTQuanti_diallelic_bitstring_no_pleio : single or multiple non-pleiotropic traits, di-allelic. More...

#include <ttquanti_bitstring.h>

+ Inheritance diagram for TTQuanti_diallelic_bitstring_no_pleio:
+ Collaboration diagram for TTQuanti_diallelic_bitstring_no_pleio:

Public Member Functions

 TTQuanti_diallelic_bitstring_no_pleio ()
 
 TTQuanti_diallelic_bitstring_no_pleio (const TTQuanti_diallelic_bitstring_no_pleio &TT)
 
virtual ~TTQuanti_diallelic_bitstring_no_pleio ()
 
virtual void init ()
 
virtual void init_sequence ()
 
virtual TTQuanti_diallelic_bitstring_no_pleioclone ()
 
virtual void show_up ()
 
virtual double get_additive_genotype (const unsigned int trait) const
 
virtual double get_dominant_genotype (const unsigned int trait) const
 
virtual void copy_sequence_block (sex_t SEX, unsigned int chromosome, unsigned int from_locus, unsigned int to_locus, const TTQuanti *parent)
 
virtual void copy_sequence_1locus (sex_t SEX, unsigned int chromosome, unsigned int at, const TTQuanti *parent)
 
double get_additive_genotype_equal_effects (const unsigned int trait) const
 
- Public Member Functions inherited from TTQuanti_diallelic_bitstring
 TTQuanti_diallelic_bitstring ()
 
 TTQuanti_diallelic_bitstring (const TTQuanti &T)
 
virtual ~TTQuanti_diallelic_bitstring ()
 
virtual bool get_allele_bit (unsigned int position, unsigned int allele) const
 
virtual void set_allele_bit (unsigned int position, unsigned int allele, bool value)
 
void set_bit_sequence (const bitstring *inseq)
 
const bitstringget_bit_sequence (bool chromosome) const
 
void inherit_free (const TTrait *mother, const TTrait *father)
 
virtual void reset ()
 
virtual void set_sequence (void **seq)
 
virtual void ** get_sequence () const
 
virtual unsigned int get_allele (int loc, int all) const
 
virtual double get_allele_value (int locus, int allele) const
 
virtual void set_allele_value (unsigned int locus, unsigned int allele, double value)
 
virtual TTQuanti_diallelic_bitstringoperator= (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)
 
virtual double get_full_genotype (unsigned int trait)
 
virtual void mutate_add (unsigned int position, unsigned int allele, double value)
 
virtual void mutate_inplace (unsigned int position, unsigned int allele, double value)
 
- Public Member Functions inherited from TTQuanti
 TTQuanti ()
 
 TTQuanti (const TTQuanti &T)
 
virtual ~TTQuanti ()
 
virtual trait_t get_type () const
 
virtual void mutate ()
 
virtual void inherit (const TTrait *mother, const TTrait *father)
 
virtual void * set_trait (void *value)
 
virtual void set_value ()
 
virtual void * getValue () const
 
void set_proto (TProtoQuanti *proto)
 
TProtoQuantiget_proto ()
 
double get_phenotype (unsigned int trai)
 
void set_phenotype (unsigned int trait, double value)
 
void reset_phenotype_to_genotypic_value ()
 
- Public Member Functions inherited from TTrait
virtual ~TTrait ()
 
- Public Member Functions inherited from StorableComponent
virtual ~StorableComponent ()
 

Additional Inherited Members

- Protected Attributes inherited from TTQuanti_diallelic_bitstring
bitstring_sequence
 
- Protected Attributes inherited from TTQuanti
double * _phenotypes
 
double * _genotypic_values
 
TProtoQuanti_myProto
 

Detailed Description

TTQuanti_diallelic_bitstring_no_pleio : single or multiple non-pleiotropic traits, di-allelic.

Constructor & Destructor Documentation

◆ TTQuanti_diallelic_bitstring_no_pleio() [1/2]

TTQuanti_diallelic_bitstring_no_pleio::TTQuanti_diallelic_bitstring_no_pleio ( )
inline
100  {}
TTQuanti_diallelic_bitstring()
Definition: ttquanti_bitstring.h:44

Referenced by clone().

+ Here is the caller graph for this function:

◆ TTQuanti_diallelic_bitstring_no_pleio() [2/2]

TTQuanti_diallelic_bitstring_no_pleio::TTQuanti_diallelic_bitstring_no_pleio ( const TTQuanti_diallelic_bitstring_no_pleio TT)
inline
103  {}

◆ ~TTQuanti_diallelic_bitstring_no_pleio()

virtual TTQuanti_diallelic_bitstring_no_pleio::~TTQuanti_diallelic_bitstring_no_pleio ( )
inlinevirtual
105 {}

Member Function Documentation

◆ clone()

virtual TTQuanti_diallelic_bitstring_no_pleio* TTQuanti_diallelic_bitstring_no_pleio::clone ( )
inlinevirtual

Implements TTrait.

110 {return new TTQuanti_diallelic_bitstring_no_pleio(*this);}
TTQuanti_diallelic_bitstring_no_pleio()
Definition: ttquanti_bitstring.h:99

References TTQuanti_diallelic_bitstring_no_pleio().

◆ copy_sequence_1locus()

void TTQuanti_diallelic_bitstring_no_pleio::copy_sequence_1locus ( sex_t  SEX,
unsigned int  chromosome,
unsigned int  at,
const TTQuanti parent 
)
inlinevirtual

Implements TTQuanti.

359 {
360  const bitstring& orig = dynamic_cast<const TTQuanti_diallelic_bitstring*>(parent)->get_bit_sequence((bool)chromosome);
361 
362  _sequence[SEX][at] = orig[at];
363 }
TTQuanti_diallelic_bitstring.
Definition: ttquanti_bitstring.h:40
const bitstring & get_bit_sequence(bool chromosome) const
Definition: ttquanti_bitstring.h:55
bitstring * _sequence
Definition: ttquanti_bitstring.h:88
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56

References TTQuanti_diallelic_bitstring::_sequence, and TTQuanti_diallelic_bitstring::get_bit_sequence().

◆ copy_sequence_block()

void TTQuanti_diallelic_bitstring_no_pleio::copy_sequence_block ( sex_t  SEX,
unsigned int  chromosome,
unsigned int  from_locus,
unsigned int  to_locus,
const TTQuanti parent 
)
inlinevirtual

Implements TTQuanti.

346 {
347  assert(to_locus > from_locus);
348 
349  const bitstring& orig = dynamic_cast<const TTQuanti_diallelic_bitstring*>(parent)->get_bit_sequence((bool)chromosome);
350 
351  _sequence[SEX].copy(orig, from_locus, to_locus);
352 
353 }
void copy(const bitstring &b)
Unchecked copy, assumes we have sames sizes.
Definition: bitstring.h:360

References TTQuanti_diallelic_bitstring::_sequence, bitstring::copy(), and TTQuanti_diallelic_bitstring::get_bit_sequence().

◆ get_additive_genotype()

double TTQuanti_diallelic_bitstring_no_pleio::get_additive_genotype ( const unsigned int  trait) const
inlinevirtual

Implements TTQuanti.

241 {
242  unsigned int L = _myProto->get_num_locus(trait); //number of loci affecting this trait
243  unsigned int pos = _myProto->get_locus_seq_pos(0, trait); //starting position, all loci contiguous on the map
244  double genotype = 0;
245 
246  if(_myProto->has_equal_effects() ) {
247 
248  const bitstring& mask = _myProto->get_trait_mask(trait);
249  unsigned int n0 = _sequence[0].count_and(mask);
250  unsigned int n1 = _sequence[1].count_and(mask);
251  return 2.0 * L * _myProto->get_equal_val_0()
252  + (n0 + n1) * _myProto->get_equal_val_diff();
253  }
254 
255  for(unsigned int j = 0; j < L; ++j, ++pos) {
256  genotype += _myProto->get_seq_diallele_value( pos, _sequence[0][pos] );
257  genotype += _myProto->get_seq_diallele_value( pos, _sequence[1][pos] );
258  }
259 
260  return genotype;
261 }
double get_equal_val_diff()
Definition: ttquanti.h:443
const bitstring & get_trait_mask(unsigned int trait) const
Definition: ttquanti.h:444
double get_seq_diallele_value(unsigned int position, unsigned int allele)
Definition: ttquanti.h:437
bool has_equal_effects()
Definition: ttquanti.h:440
unsigned int get_locus_seq_pos(unsigned int loc, unsigned int trait)
Definition: ttquanti.h:452
double get_equal_val_0()
Definition: ttquanti.h:441
unsigned int get_num_locus()
Definition: ttquanti.h:423
TProtoQuanti * _myProto
Definition: ttquanti.h:106
unsigned int count_and(const bitstring &mask) const
Masked popcount: count set bits in (this AND mask).
Definition: bitstring.h:299

References TTQuanti::_myProto, TTQuanti_diallelic_bitstring::_sequence, bitstring::count_and(), TProtoQuanti::get_equal_val_0(), TProtoQuanti::get_equal_val_diff(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_seq_diallele_value(), TProtoQuanti::get_trait_mask(), and TProtoQuanti::has_equal_effects().

◆ get_additive_genotype_equal_effects()

double TTQuanti_diallelic_bitstring_no_pleio::get_additive_genotype_equal_effects ( const unsigned int  trait) const
inline
264 {
265  unsigned int L = _myProto->get_num_locus(trait); //number of loci affecting this trait
266  unsigned int pos = _myProto->get_locus_seq_pos(0, trait); //starting position, all loci contiguous on the map
267 
268  // bulk path: replace O(L) per-bit loop with two popcount calls over [pos, pos+L)
269  unsigned int n0 = _sequence[0].count(pos, pos + L);
270  unsigned int n1 = _sequence[1].count(pos, pos + L);
271  return 2.0 * L * _myProto->get_equal_val_0()
272  + (n0 + n1) * _myProto->get_equal_val_diff();
273 }
unsigned int count()
Count number of set bits.
Definition: bitstring.h:258

References TTQuanti::_myProto, TTQuanti_diallelic_bitstring::_sequence, bitstring::count(), TProtoQuanti::get_equal_val_0(), TProtoQuanti::get_equal_val_diff(), TProtoQuanti::get_locus_seq_pos(), and TProtoQuanti::get_num_locus().

Referenced by get_dominant_genotype().

+ Here is the caller graph for this function:

◆ get_dominant_genotype()

double TTQuanti_diallelic_bitstring_no_pleio::get_dominant_genotype ( const unsigned int  trait) const
inlinevirtual

Implements TTQuanti.

278 {
279  unsigned int L = _myProto->get_num_locus(trait); //number of loci affecting this trait
280  unsigned int pos = _myProto->get_locus_seq_pos(0, trait); //starting position, all loci contiguous on the map
281 
283 
284  const bitstring& mask = _myProto->get_trait_mask(trait);
285  unsigned int n_htz = _sequence[0].count_xor_and(_sequence[1], mask);
286  unsigned int n_hmz1 = _sequence[0].count_and_and(_sequence[1], mask);
287  unsigned int n_hmz0 = L - n_htz - n_hmz1; // remainder are homozygous ancestral
288 
289  double val_0 = _myProto->get_equal_val_0();
290  double val_1 = _myProto->get_equal_val_1();
291  double k = _myProto->get_dominance(0, trait); // uniform k
292 
293  return n_hmz0 * 2.0 * val_0
294  + n_htz * (val_0 + val_1 + k * fabs(val_1 - val_0))
295  + n_hmz1 * 2.0 * val_1;
296 
297  }//END_has_equal_effect && has_equal_domCoeff
298 
299  if(_myProto->has_equal_effects() ) {
300  unsigned long word;
301 
302  // additive effects are equal across loci, only dominance varies
303  double het_val = fabs(_myProto->get_equal_val_1() - _myProto->get_equal_val_0());
304  double genotype = get_additive_genotype_equal_effects(trait); // includes add efx of all loci
305 
306  bitstring htz(_sequence[0]);
307  htz ^= _sequence[1]; // XOR: heterozygous loci have bit=1
308 
309  // Per-locus part (only heterozygous loci — iterate over set bits in htz)
310  for (size_t w = pos/BITS_PER_WORD; w <= (pos+L-1)/BITS_PER_WORD; ++w) {
311  word = *htz.getword_atIdx(w); // only heterozygous bits
312  while (word) {
313  unsigned int bit = __builtin_ctzl(word); // find lowest set bit
314  unsigned int locus = w * BITS_PER_WORD + bit;
315  double k = _myProto->get_dominance(locus, trait);
316  genotype += k * het_val; // add dominance deviation at that locus
317  word &= word - 1; // clear lowest set bit
318  }
319  }
320 
321  return genotype;
322  } //END_has_equal_effect
323 
324 
325  // non-optimized case:
326  double genotype = 0;
327  unsigned int locID;
328 
329  for(unsigned int j = 0; j < L; ++j, ++pos) {
330  locID = _myProto->get_locus_ID(j, trait);
332  _myProto->get_seq_diallele_value( pos, _sequence[0][pos] ) ,
333  _myProto->get_seq_diallele_value( pos, _sequence[1][pos] ),
334  locID,
335  trait);
336  }
337 
338  return genotype;
339 
340 }
#define BITS_PER_WORD
Definition: bitstring.h:40
double get_dominance(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:478
unsigned int get_locus_ID(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:454
double get_equal_val_1()
Definition: ttquanti.h:442
bool has_equal_domCoeff()
Definition: ttquanti.h:439
double get_genotype_with_dominance(const double a1, const double a2, const unsigned int locus, const unsigned int trait)
Definition: ttquanti.cc:2538
double get_additive_genotype_equal_effects(const unsigned int trait) const
Definition: ttquanti_bitstring.cc:263
unsigned int count_and_and(const bitstring &other, const bitstring &mask) const
Fused AND + mask popcount: count set bits in ((this AND other) AND mask).
Definition: bitstring.h:326
_ul * getword_atIdx(size_t index) const
Definition: bitstring.h:158
unsigned int count_xor_and(const bitstring &other, const bitstring &mask) const
Fused XOR + mask popcount: count set bits in ((this XOR other) AND mask).
Definition: bitstring.h:317

References TTQuanti::_myProto, TTQuanti_diallelic_bitstring::_sequence, BITS_PER_WORD, bitstring::count_and_and(), bitstring::count_xor_and(), get_additive_genotype_equal_effects(), TProtoQuanti::get_dominance(), TProtoQuanti::get_equal_val_0(), TProtoQuanti::get_equal_val_1(), TProtoQuanti::get_genotype_with_dominance(), TProtoQuanti::get_locus_ID(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_seq_diallele_value(), TProtoQuanti::get_trait_mask(), bitstring::getword_atIdx(), TProtoQuanti::has_equal_domCoeff(), and TProtoQuanti::has_equal_effects().

◆ init()

void TTQuanti_diallelic_bitstring_no_pleio::init ( )
inlinevirtual

Reimplemented from TTQuanti_diallelic_bitstring.

236 {
238 }
virtual void init()
Definition: ttquanti_bitstring.cc:142

References TTQuanti_diallelic_bitstring::init().

◆ init_sequence()

void TTQuanti_diallelic_bitstring_no_pleio::init_sequence ( )
inlinevirtual

Implements TTrait.

368 {
369  //options:
370  //0: no variation, all alleles set to 0
371  //1: max variation, randomly set alleles at each locus
372  //2: no variation and initialize with opposite effect alleles at alternating loci.
373 
374  // initialize with 0 bit
375  _sequence[0].reset();
376  _sequence[1].reset();
377 
378  if (_myProto->get_doInitMutation() == 1) {
379 
380  for(unsigned int i = 0; i < _myProto->get_num_locus(); ++i) {
381 
382  // randomly set the allelic values
383  _sequence[0][ i ] = RAND::RandBool();
384  _sequence[1][ i ] = RAND::RandBool();
385 
386  }
387 
388  } else if (_myProto->get_doInitMutation() == 2) {
389  //option 2; polarized di-allelic values; even locus set to +a, odd locus set to -a
390 
391  for(unsigned int i = 0; i < _myProto->get_num_locus(); i++) { // process trait-wise
392  // no need to set alleles to 0 since it was initialized that way
393 
394  if(i%2) { // odd locus
395  _sequence[1][ i ].flip(); //set with the alternate/negative allele value
396  _sequence[0][ i ].flip();
397  }
398  }
399  }
400 
401 }
static bool RandBool()
Returns a random boolean.
Definition: Uniform.h:164
unsigned int get_doInitMutation()
Definition: ttquanti.h:448
void flip(size_t n)
Flip the bit at n.
Definition: bitstring.h:346
void reset(size_t length)
Definition: bitstring.h:139

References TTQuanti::_myProto, TTQuanti_diallelic_bitstring::_sequence, bitstring::flip(), TProtoQuanti::get_doInitMutation(), TProtoQuanti::get_num_locus(), RAND::RandBool(), and bitstring::reset().

◆ show_up()

void TTQuanti_diallelic_bitstring_no_pleio::show_up ( )
virtual

Implements TTrait.

406 {
407  message("\
408  Trait's type: QUANTI (diallelic, no pleiotropy)\n\
409  traits: %i\n\
410  loci: %i\n\
411  seq length: %i\n",_myProto->get_num_traits(),_myProto->get_num_locus()
413 
414  for(unsigned int i = 0; i < _myProto->get_num_traits(); i++)
415  message("phenotype %i: %f\n",i+1,_phenotypes[i]);
416 
417  message("genotype:");
418 
419  for(unsigned int i = 0; i < _myProto->get_num_traits(); ++i) {
420 
421  message("\ntrait %i (%i loci):\nloci: ",i+1, _myProto->get_num_locus(i));
422 
423  for(unsigned int j = 0; j < _myProto->get_num_locus(i); ++j) {
424  message("%i, ", _myProto->get_locus_ID(j, i));
425  }
426 
427  message("\n[0]: ");
428 
429  for(unsigned int j = 0; j < _myProto->get_num_locus(i); ++j) {
430  message("%.3f,", (double)_sequence[0][ _myProto->get_locus_seq_pos(j, i) ]);
431  }
432 
433  message("\n[1]: ");
434 
435  for(unsigned int j = 0; j < _myProto->get_num_locus(i); ++j) {
436  message("%.3f,", (double)_sequence[1][ _myProto->get_locus_seq_pos(j, i) ]);
437  }
438  }
439 
440  message("\n");
441 
442 }
unsigned int get_seq_length()
Definition: ttquanti.h:426
unsigned int get_num_traits()
Definition: ttquanti.h:422
double * _phenotypes
Definition: ttquanti.h:104
void message(const char *message,...)
Definition: output.cc:39

References TTQuanti::_myProto, TTQuanti::_phenotypes, TTQuanti_diallelic_bitstring::_sequence, TProtoQuanti::get_locus_ID(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), TProtoQuanti::get_seq_length(), and message().


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

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR