Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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]
 

Constructor & Destructor Documentation

◆ GeneticMaterial1616()

GeneticMaterial1616::GeneticMaterial1616 ( )
589  {
590  // ensure zeros in all loci
591  for ( int i = 0; i < 4; i++ ) Chromosome[ i ] = 0;
592 }

References Chromosome.

Member Function Documentation

◆ GetAllele()

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

References Chromosome, g_msg, and MapErrorMsg::Warn().

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

◆ GetDirectFlag()

uint32 GeneticMaterial1616::GetDirectFlag ( )
763  {
764  return GetAllele(0,1);
765 }

References GetAllele().

◆ GetGeneticFlag()

uint32 GeneticMaterial1616::GetGeneticFlag ( )
759  {
760  return GetAllele(0,0);
761 }

References GetAllele().

◆ HeterozygosityCount()

int GeneticMaterial1616::HeterozygosityCount ( )
715  {
716  int heterozyg = 0;
717  for ( int i = 0; i < 16; i++ ) {
718  if ( GetAllele( i, 0 ) != GetAllele( i, 1 ) ) heterozyg++;
719  }
720  return heterozyg;
721 }

References GetAllele().

◆ HomozygosityCount()

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

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.

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

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

◆ Mutation_1()

void GeneticMaterial1616::Mutation_1 ( )

random allele choice

805 {
806  if (MutationChance != 0)
807  {
808  for ( int i = 0; i < 16; i++ )
809  {
810  if ( g_rand_uni_fnc() < MutationChance ) // one chance in Mutation Chance
811  {
812  SetAllele( i, g_random_fnc( 16 ), g_random_fnc( 2 ) );
813  }
814  }
815  }
816 }

References g_rand_uni_fnc(), g_random_fnc(), MutationChance, and SetAllele().

◆ Mutation_2()

void GeneticMaterial1616::Mutation_2 ( )

Move one allele + and 16 becomes 0

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

References g_rand_uni_fnc(), g_random_fnc(), GetAllele(), MutationChance, and SetAllele().

◆ Mutation_3()

void GeneticMaterial1616::Mutation_3 ( )

Move one allele one up or down

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

References g_rand_uni_fnc(), g_random_fnc(), GetAllele(), MutationChance, and SetAllele().

◆ PrintChromosome()

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

References GetAllele().

◆ Recombine()

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

References g_random_fnc(), GetAllele(), and SetAllele().

◆ SetAllele()

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

References Chromosome, g_msg, and MapErrorMsg::Warn().

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

◆ SetDirectFlag()

void GeneticMaterial1616::SetDirectFlag ( )
745  {
746  SetAllele(0,1,1);
747 }

References SetAllele().

◆ SetGeneticFlag()

void GeneticMaterial1616::SetGeneticFlag ( )
741  {
742  SetAllele(0,1,0);
743 }

References SetAllele().

◆ UnsetDirectFlag()

void GeneticMaterial1616::UnsetDirectFlag ( )
754  {
755  SetAllele(0,0,1);
756 }

References SetAllele().

◆ UnsetGeneticFlag()

void GeneticMaterial1616::UnsetGeneticFlag ( )
750  {
751  SetAllele(0,0,0);
752 }

References SetAllele().

Member Data Documentation

◆ Chromosome

uint32 GeneticMaterial1616::Chromosome[4]
protected

The documentation for this class was generated from the following files:
g_rand_uni_fnc
double g_rand_uni_fnc()
Definition: ALMaSS_Random.cpp:56
uint32
unsigned int uint32
Definition: ALMaSS_Setup.h:34
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
MutationChance
double MutationChance
Definition: GeneticMaterial.cpp:49
GeneticMaterial1616::SetAllele
void SetAllele(unsigned int locus, uint32 value, unsigned int Chromo)
Definition: GeneticMaterial.cpp:618
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
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:596
g_random_fnc
int g_random_fnc(const int a_range)
Definition: ALMaSS_Random.cpp:74
GeneticMaterial1616::Chromosome
uint32 Chromosome[4]
Definition: GeneticMaterial.h:156