ALMaSS Vole ODDox  1.1
The vole model description following ODdox protocol
GeneticMaterial1616 Class Reference

#include <GeneticMaterial.h>

Public Member Functions

 GeneticMaterial1616 ()
 
void SetAllele (unsigned int locus, uint32 value, unsigned int Chromo)
 
uint32 GetAllele (unsigned int locus, unsigned int Chromo)
 
void PrintChromosome (char *C, unsigned int Chromosome)
 
void SetGeneticFlag ()
 
void SetDirectFlag ()
 
void UnsetGeneticFlag ()
 
void UnsetDirectFlag ()
 
uint32 GetGeneticFlag ()
 
uint32 GetDirectFlag ()
 
int HomozygosityCount ()
 
int HeterozygosityCount ()
 
void Recombine (GeneticMaterial1616 *Gene1, GeneticMaterial1616 *Gene2)
 
void Initiation (AlleleFreq1616 *Al)
 
void Mutation_1 ()
 
void Mutation_2 ()
 
void Mutation_3 ()
 

Protected Attributes

uint32 Chromosome [4]
 

Detailed Description

Definition at line 153 of file GeneticMaterial.h.

Constructor & Destructor Documentation

◆ GeneticMaterial1616()

GeneticMaterial1616::GeneticMaterial1616 ( )

Definition at line 592 of file GeneticMaterial.cpp.

592  {
593  // ensure zeros in all loci
594  for ( int i = 0; i < 4; i++ ) Chromosome[ i ] = 0;
595 }

References Chromosome.

Member Function Documentation

◆ GetAllele()

uint32 GeneticMaterial1616::GetAllele ( unsigned int  locus,
unsigned int  Chromo 
)

Definition at line 599 of file GeneticMaterial.cpp.

599  {
600  // This is for 32 bit machines, 64bit is easier
601  // locus must be 0 to 15
602  //Chromo must be either 0 or 1
603  // These debug tests below are costly so turn off in release code
604  #ifdef __GENDEBUG
605  if (Chromo>1) {
606  g_msg->Warn( "Chromo > 1 in GeneticMaterial1616 - get allele", NULL );
607  exit( 0 );
608  }
609  if (locus>15) {
610  g_msg->Warn( "locus > 15 in GeneticMaterial1616 - get allele", NULL );
611  exit( 0 );
612  }
613  #endif
614 
615  uint32 segment=((Chromo<<1) | ((locus & 0x08)>>3)); // locates on which segment in the comosome we are in
616  uint32 allele=0x0F & (Chromosome[segment]>>((locus & 0x07)<<2)); //Locates the allele and shifts it down to the first postition to read
617  return allele;
618 }

References Chromosome.

Referenced by GetDirectFlag(), GetGeneticFlag(), HeterozygosityCount(), HomozygosityCount(), Mutation_2(), Mutation_3(), PrintChromosome(), and Recombine().

◆ GetDirectFlag()

uint32 GeneticMaterial1616::GetDirectFlag ( )

Definition at line 766 of file GeneticMaterial.cpp.

766  {
767  return GetAllele(0,1);
768 }

References GetAllele().

◆ GetGeneticFlag()

uint32 GeneticMaterial1616::GetGeneticFlag ( )

Definition at line 762 of file GeneticMaterial.cpp.

762  {
763  return GetAllele(0,0);
764 }

References GetAllele().

◆ HeterozygosityCount()

int GeneticMaterial1616::HeterozygosityCount ( )

Definition at line 718 of file GeneticMaterial.cpp.

718  {
719  int heterozyg = 0;
720  for ( int i = 0; i < 16; i++ ) {
721  if ( GetAllele( i, 0 ) != GetAllele( i, 1 ) ) heterozyg++;
722  }
723  return heterozyg;
724 }

References GetAllele().

◆ HomozygosityCount()

int GeneticMaterial1616::HomozygosityCount ( )

Definition at line 707 of file GeneticMaterial.cpp.

707  {
708  // OK OK there is an easy way to do this by calling HeterozygosityCount and
709  // subtracting this from 32, but just is case that little bit of saved time is useful:
710  int homozyg=0;
711  for ( int i = 0; i < 16; i++ ) {
712  if ( GetAllele( i, 0 ) == GetAllele( i, 1 ) ) homozyg++;
713  }
714  return homozyg;
715 }

References GetAllele().

◆ Initiation()

void GeneticMaterial1616::Initiation ( AlleleFreq1616 Al)

The method called to intialise genes on initiation of the simulation.
Gene frequencies are based on an external text file input read in on construction.

Definition at line 775 of file GeneticMaterial.cpp.

775  {
776  uint32 value; //, c;
777  for ( int l = 0; l < 16; l++ ) {
778  // if ( l < 16 ) c = 0; else c = 2;
779 
780  int chance = random( 1000 );
781  uint32 index = 0;
782  while ( chance >= Al->SupplyAN( l, index ) ) {
783  index++;
784  }
785  value = index;
786  // set the value
787  SetAllele( l, value, 0 );
788 
789  chance = random( 1000 );
790  index = 0;
791  while ( chance >= Al->SupplyAN( l, index ) ) {
792  index++;
793  }
794  value = index;
795  // set the value
796  SetAllele( l, value, 1 );
797  }
798 }

References SetAllele(), and AlleleFreq1616::SupplyAN().

◆ Mutation_1()

void GeneticMaterial1616::Mutation_1 ( )

random allele choice

Definition at line 807 of file GeneticMaterial.cpp.

808 {
809  if (MutationChance != 0)
810  {
811  for ( int i = 0; i < 16; i++ )
812  {
813  if ( g_rand_uni() < MutationChance ) // one chance in Mutation Chance
814  {
815  SetAllele( i, random( 16 ), random( 2 ) );
816  }
817  }
818  }
819 }

References g_rand_uni, MutationChance, and SetAllele().

◆ Mutation_2()

void GeneticMaterial1616::Mutation_2 ( )

Move one allele + and 16 becomes 0

Definition at line 826 of file GeneticMaterial.cpp.

827 {
828  if (MutationChance != 0){
829  for ( int i = 0; i < 16; i++ ) {
830  if (g_rand_uni() < MutationChance) // one chance in Mutation Chance for the locus
831  {
832  unsigned int strand = random( 2 ); // kromosom 0 or 1
833  unsigned int allele = GetAllele( i, strand );
834  allele++;
835  allele&=0x0f; //and with 1111 - allels curls up 15 -> 0
836  SetAllele( i, allele, strand );
837  }
838  }
839 }
840 }

References g_rand_uni, GetAllele(), MutationChance, and SetAllele().

◆ Mutation_3()

void GeneticMaterial1616::Mutation_3 ( )

Move one allele one up or down

Definition at line 847 of file GeneticMaterial.cpp.

848 {
849  if (MutationChance != 0){
850  for ( int i = 0; i < 16; i++ ) {
851  if ( g_rand_uni() < MutationChance) // one chance in Mutation Chance for the locus
852  {
853  unsigned strand = random( 2 ); // kromosom 0 or 1
854  unsigned allele = GetAllele( i, strand );
855  //if (strand == 1) allele++; else allele--;
856  if ( random( 2 ) == 1 ) allele++; else allele--;
857 
858  //For mutations less than 0 and more than 15 the mutation should result in 1 or 14
859 
860  if (allele > 0x0f) // Test to see if mutation to negative or above 15
861  {
862  allele |= 0x1C;
863  if(allele > 0x01C) { allele &= 0x01;}
864  else allele >>=1;
865  //allele|= 0xF0; // (240) Sets neg to 0, and 16 to 15 -> to avoid curling up
866  //allele = (~allele);
867  }
868 
869  SetAllele( i, allele, strand );
870  }
871  }
872 }
873 }

References g_rand_uni, GetAllele(), MutationChance, and SetAllele().

◆ PrintChromosome()

void GeneticMaterial1616::PrintChromosome ( char *  C,
unsigned int  Chromosome 
)

Definition at line 649 of file GeneticMaterial.cpp.

649  {
650  for ( int i = 0; i < 16; i++ ) {
651  uint32 allele = GetAllele( i, Chromo );
652  switch ( allele ) {
653  case 0:
654  C[ i ] = 'a';
655  break;
656  case 1:
657  C[ i ] = 'b';
658  break;
659  case 2:
660  C[ i ] = 'c';
661  break;
662  case 3:
663  C[ i ] = 'd';
664  break;
665  case 4:
666  C[ i ] = 'e';
667  break;
668  case 5:
669  C[ i ] = 'f';
670  break;
671  case 6:
672  C[ i ] = 'g';
673  break;
674  case 7:
675  C[ i ] = 'h';
676  break;
677  case 8:
678  C[ i ] = 'i';
679  break;
680  case 9:
681  C[ i ] = 'j';
682  break;
683  case 10:
684  C[ i ] = 'k';
685  break;
686  case 11:
687  C[ i ] = 'l';
688  break;
689  case 12:
690  C[ i ] = 'm';
691  break;
692  case 13:
693  C[ i ] = 'n';
694  break;
695  case 14:
696  C[ i ] = 'o';
697  break;
698  case 15:
699  C[ i ] = 'p';
700  break;
701  }
702  }
703  C[ 16 ] = 0;
704 }

References GetAllele().

◆ Recombine()

void GeneticMaterial1616::Recombine ( GeneticMaterial1616 Gene1,
GeneticMaterial1616 Gene2 
)

Definition at line 727 of file GeneticMaterial.cpp.

727  {
728  // Is called with hers and his genes
729  for ( int i = 0; i < 16; i++ ) {
730  // For each locus
731  // Choose which chromosome for each parent
732  int g0 = random(2);
733  int g1 = random(2);
734  // get the two alleles
735  uint32 a0 = Gene1->GetAllele( i, g0 );
736  uint32 a1 = Gene2->GetAllele( i, g1 );
737  // put a0 into chromo0 & a1 to chromo1 & vice versa
738  SetAllele( i, a0, 0 );
739  SetAllele( i, a1, 1 );
740  }
741 }

References GetAllele(), and SetAllele().

◆ SetAllele()

void GeneticMaterial1616::SetAllele ( unsigned int  locus,
uint32  value,
unsigned int  Chromo 
)

Definition at line 621 of file GeneticMaterial.cpp.

621  {
622  // This is for 32 bit machines, 64bit is easier
623  // locus must be 0 to 15
624  //Chromo must be either 0 or 1
625  // These debug tests below are costly so turn off in release code
626  #ifdef __GENDEBUG
627  if (Chromo>1) {
628  g_msg->Warn( "Chromo > 1 in GeneticMaterial1616 - set allele", NULL );
629  exit( 0 );
630  }
631  if (locus>15) {
632  g_msg->Warn( "locus > 15 in GeneticMaterial1616 - set allele", NULL );
633  exit( 0 );
634  }
635  #endif
636 
637  uint32 segment=((Chromo<<1) | ((locus & 0x08)>>3));
638  uint32 mask = 0x0F; //0000 1111F
639  // Need to shift the mask over the correct allele
640  mask=mask<<((locus&7)<<2);
641  value = value & 0x0f; // make sure there was no extra stuff added!
642  // create the value mask
643  value = value << ((locus&7)<<2);
644  Chromosome[ segment ] &= ~mask; // get rid of the current info
645  Chromosome[ segment ] |= value; // write the value
646 }

References Chromosome.

Referenced by Initiation(), Mutation_1(), Mutation_2(), Mutation_3(), Recombine(), SetDirectFlag(), SetGeneticFlag(), UnsetDirectFlag(), and UnsetGeneticFlag().

◆ SetDirectFlag()

void GeneticMaterial1616::SetDirectFlag ( )

Definition at line 748 of file GeneticMaterial.cpp.

748  {
749  SetAllele(0,1,1);
750 }

References SetAllele().

◆ SetGeneticFlag()

void GeneticMaterial1616::SetGeneticFlag ( )

Definition at line 744 of file GeneticMaterial.cpp.

744  {
745  SetAllele(0,1,0);
746 }

References SetAllele().

◆ UnsetDirectFlag()

void GeneticMaterial1616::UnsetDirectFlag ( )

Definition at line 757 of file GeneticMaterial.cpp.

757  {
758  SetAllele(0,0,1);
759 }

References SetAllele().

◆ UnsetGeneticFlag()

void GeneticMaterial1616::UnsetGeneticFlag ( )

Definition at line 753 of file GeneticMaterial.cpp.

753  {
754  SetAllele(0,0,0);
755 }

References SetAllele().

Member Data Documentation

◆ Chromosome

uint32 GeneticMaterial1616::Chromosome[4]
protected

Definition at line 156 of file GeneticMaterial.h.

Referenced by GeneticMaterial1616(), GetAllele(), and SetAllele().


The documentation for this class was generated from the following files:
MutationChance
double MutationChance
Definition: GeneticMaterial.cpp:52
GeneticMaterial1616::SetAllele
void SetAllele(unsigned int locus, uint32 value, unsigned int Chromo)
Definition: GeneticMaterial.cpp:621
g_rand_uni
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
AlleleFreq1616::SupplyAN
int SupplyAN(int loc, int al)
Definition: GeneticMaterial.h:135
GeneticMaterial1616::GetAllele
uint32 GetAllele(unsigned int locus, unsigned int Chromo)
Definition: GeneticMaterial.cpp:599
GeneticMaterial1616::Chromosome
uint32 Chromosome[4]
Definition: GeneticMaterial.h:156