Nemo  2.4.2
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
99  {}
TTQuanti_diallelic_bitstring()
Definition: ttquanti_bitstring.h:43

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
102  {}

◆ ~TTQuanti_diallelic_bitstring_no_pleio()

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

Member Function Documentation

◆ clone()

virtual TTQuanti_diallelic_bitstring_no_pleio* TTQuanti_diallelic_bitstring_no_pleio::clone ( )
inlinevirtual

Implements TTrait.

109 {return new TTQuanti_diallelic_bitstring_no_pleio(*this);}
TTQuanti_diallelic_bitstring_no_pleio()
Definition: ttquanti_bitstring.h:98

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.

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

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.

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

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.

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

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

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.

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

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.

235 {
237 }
virtual void init()
Definition: ttquanti_bitstring.cc:141

References TTQuanti_diallelic_bitstring::init().

◆ init_sequence()

void TTQuanti_diallelic_bitstring_no_pleio::init_sequence ( )
inlinevirtual

Implements TTrait.

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

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.

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

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.2 by  doxygen 1.9.1

Catalogued on GSR