/// <summary> /// Defines the parental haplotypes according to the recombination type /// </summary> /// <param name="recType"></param> public void DefineParentalHaplotypes(RecombinationType recType) { mother = new Individ(); father = new Individ(); Random s_Random = new Random(); switch (recType) { case RecombinationType.Backcross: for (int i = 0; i < mother.Haplotype0.Length; i++) { mother.Haplotype0[i] = 0; } for (int i = 0; i < father.Haplotype0.Length; i++) { father.Haplotype0[i] = 1; } break; case RecombinationType.BackcrossWithNoise: for (int i = 0; i < mother.Haplotype0.Length; i++) { int perCent = s_Random.Next(0, 100); if (perCent < 20) { mother.Haplotype0[i] = 1; } else { mother.Haplotype0[i] = 0; } } for (int i = 0; i < father.Haplotype0.Length; i++) { int perCent = s_Random.Next(0, 100); if (perCent < 20) { mother.Haplotype0[i] = 0; } else { mother.Haplotype0[i] = 1; } } break; } }
public void SimulateRecombination(int amountOfIndivids) { //create population of 200 children -individulas pop = new Population(); for (int i = 0; i < amountOfIndivids; i++) { //the same parents Individ offSpring = new Individ(); offSpring.Parent0 = mother; offSpring.Parent1 = father; pop.Individ.Add(offSpring); } //calculate recombination pathways //FusionSimple() //gameta_get() }
private void HaplotypeInheritOrderedListOfLoci(List <Locus> OrderedListOfLoci, Individ parent, IList <Position> RecEventsParent, out List <int> Haplotype, out List <bool> HaplotypeOk) { int Phase = 0; int NRec = RecEventsParent.Count; int NLoci = OrderedListOfLoci.Count; //NotBeforePosition(Position Pos) Haplotype = new List <int>(); HaplotypeOk = new List <bool>(); if (NLoci > 0) { Position PosLast = new Position(); PosLast.Chromosome = OrderedListOfLoci[NLoci].Position.Chromosome; PosLast.PositionChrGenetic = OrderedListOfLoci[NLoci].Position.PositionChrGenetic + 10; Position PosNextRec = new Position(); if (NRec == 0) { PosNextRec = PosLast; } else { PosNextRec = RecEventsParent[0]; } int IRec = 0; int ILocus = 0; List <int> ParentHaplotype; List <bool> ParentHaplotypeOk; foreach (Locus locus in OrderedListOfLoci) { while (!PosNextRec.NotBeforePosition(locus.Position)) { IRec++; if (IRec >= NRec) { PosNextRec = PosLast; } else { PosNextRec = RecEventsParent[IRec]; } Phase = 1 - Phase;//0<->1 } if (Phase == 0) { ParentHaplotype = this.Haplotype0; ParentHaplotypeOk = this.Haplotype0Ok; } else { ParentHaplotype = this.Haplotype1; ParentHaplotypeOk = this.Haplotype1Ok; } Haplotype.Add(ParentHaplotype[ILocus]); HaplotypeOk.Add(ParentHaplotypeOk[ILocus]); ILocus++; } } }
//dRec=expectation of number of recombination events in the interval (1 cM=0.01 recombination event) //Independent recombination or start from he begin of chromosome => exponential distribution of distance to the next recombination //E{exp(lambda)}=1/lambda=100 cM => lambda=1/100 //density: p(x)=lambda e^{- lambda*x} //comulative distribution function: P(x)=P(exp(lambda)<x)=1 - e^{- lambda*x} ~ U[0,1] => e^{- lambda*x}=1-U[0,1] => - lambda*x=ln(1-U[0,1]) => x=(-1/lambda)*ln(1-U[0,1]) = -100*ln(1-U[0,1]) /// <summary> /// Simulates the recombination events for the production of the children from two parents /// </summary> /// <param name="amountOfIndivids"></param> public void SimulateRecombination(int amountOfIndivids = 200) { Random rand = new Random(); double p, previousPosition, currentPosition = 0.0, l, lambda = 0.01; //create population of 200 children -individulas pop = new Population(); for (int i = 0; i < amountOfIndivids; i++) { //the same parents Individ offSpring = new Individ(); offSpring.Parent0 = mother; offSpring.Parent1 = father; //define recombination events positions H0 haplotyes for children for (int j = 0; j < go.Chromosome.Count; j++) { //genereate random number P = 0 to 1 p = rand.NextDouble(); if (p < 0.5) { //begin with grandmother (copy haplotpes H0) //first recombination happens at coordinate 0 Position pos = new Position(); pos.Chromosome = go.Chromosome[j]; pos.PositionChrGenetic = 0.0; offSpring.RecEventsParent0.Add(pos); } previousPosition = 0.0; while (go.Chromosome[j].LenGenetcM > currentPosition) { // l=generate random number with exponantional distribution with lambda = 1/100 l = generateRandExponantionalDist(go.Chromosome[j].LenGenetcM, 0, lambda); currentPosition = previousPosition + l; Position pos = new Position(); pos.Chromosome = go.Chromosome[j]; pos.PositionChrGenetic = currentPosition; offSpring.RecEventsParent0.Add(pos); previousPosition = currentPosition; } } //reset all the values p = 0.0; previousPosition = 0.0; currentPosition = 0.0; l = 0.0; //define recombination events positions H1 haplotyes for children for (int k = 0; k < go.Chromosome.Count; k++) { //genereate random number P = 0 to 1 p = rand.NextDouble(); if (p < 0.5) { //begin with grandmother (copy haplotpes H0) //first recombination happens at coordinate 0 Position pos = new Position(); pos.Chromosome = go.Chromosome[k]; pos.PositionChrGenetic = 0.0; offSpring.RecEventsParent1.Add(pos); } previousPosition = 0.0; while (go.Chromosome[k].LenGenetcM > currentPosition) { // l=generate random number with exponantional distribution with lambda = 1/100 l = generateRandExponantionalDist(go.Chromosome[k].LenGenetcM, 0, lambda); currentPosition = previousPosition + l; Position pos = new Position(); pos.Chromosome = go.Chromosome[k]; pos.PositionChrGenetic = currentPosition; offSpring.RecEventsParent1.Add(pos); previousPosition = currentPosition; } } pop.Individ.Add(offSpring); } }