Mutation-selection balance & Perturbation techniquerestart:w[A]:= (w[AA]*p+w[Aa]*q); w[a]:= (w[Aa]*p+w[aa]*q); induced fitnesses of A and awmean:=(w[AA]*p^2+2*w[Aa]*p*q+w[aa]*q^2 ); average fitness of the populationq:=1-p;ps:=w[A]*p/wmean: qs:=w[a]*q/wmean: allele frequencies after selectionpm:=(1-mu)*ps+mu*qs: frequency of A after mutationDelta:=pm-p: change in p per generation w[AA]:=1-s: w[Aa]:=1-h : w[aa]:=1: genotype fitnessesDelta;factor(%);Eq:=numer(%);subs(s=0,Eq); symmetric underdominancefactor(%);sol:=solve(%=0,p);assume(h>0): simplify(taylor(sol[2],mu=0,2));simplify(taylor(sol[3],mu=0,2));subs(h=s/2,Eq); additive fitnessessol:=solve(%=0,p);assume(s>0): simplify(taylor(sol[1],mu=0,2));assume(s>0): simplify(taylor(sol[2],mu=0,2));subs(h=0,Eq); recessive allelef:=collect(%,p);factor(subs(mu=0,%));p:=sum(P[i]*mu^(epsilon*i),i=0..2);P[0]:=0:combine(expand(f));collect(%,mu,factor);subs(p=sqrt(mu)/sqrt(s)+P[2]*mu,f);combine(expand(%));mu^(3/2)/s^(1/2)+2*mu^(3/2)*s^(1/2)*P[2];
solve(%,P[2]);Genetic drift in a finite populationChanges in allele frequency as modeled by binomial samplingrestart:with(stats):N:=50: p:=.4: T:=100: X:=array[0..T]:for i from 1 to T don:=0: for j from 1 to N do x:=random[uniform](1): if x<p then n:=n+1: fi od: p:=n/N: X[i]:=p; od:F:=seq([i,X[i]],i=0..T): plot({F}, style=point, labels=[ `generation number`,`freq`], title=`Genetic Drift`,color=[red,blue,green],titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12]);Fixation probabilityrestart:with(DEtools): General solution for the probability of fixationeq:=m(p)*diff(u(p),p)+v(p)*diff(u(p),p$2)/2;dsolve(eq=0,u(p));F:=exp(-2*int(m(p)/v(p),p));U:=int(F,p=0..x)/int(F,p=0..1); Additive fitnessesm(p):=s*p*(1-p); v(p):=p*(1-p)/(2*N);U;F:=subs(x=1/(2*N),%); assuming there is a single mutant initiallyplot( {subs(N=25,log10(F)),subs(N=50,log10(F)),subs(N=100,log10(F))},s=-0.1..0.1,y=-17..0,titlefont=[TIMES,BOLD,12],font=[TIMES,BOLD,12],thickness=2,labels=[ `s`,`log10(u)`], title=`Fixation probability`); Underdominant selectionChange in allele frequency per generation with underdominant selectionrestart:f:=p*q*(w[A]-w[a])/wmean;w[A]:=w[AA]*p+w[Aa]*q;w[a]:=w[Aa]*p+w[aa]*q;wmean:=w[A]*p+w[a]*q;q:=1-p;Delta[p]:=factor(f);factor(subs({w[AA]=1,w[Aa]=1-s,w[aa]=1},Delta[p]));numer(%)/collect(denom(%),s,factor); if s<<1, the denominator (i.e. the average fitness of the population) is approximately 1. Unequal fitness of homozygotesfactor(subs({w[AA]=1,w[Aa]=1-s,w[aa]=1+h},Delta[p]));m(p):=s*p*(1-p)*(2*p-1+e*(p-1)); different peaksm(p):=s*p*(1-p)*(2*p-1); equal peaksU;subs(x=1/(2*N),%);X:=(erf(Y*(e-1))+erf(Y))/(2*erf(Y));series(X,e=0,2);subs({Y=sqrt(S),e=1/N},exp(-Y^2)*Y/(sqrt(Pi)*erf(Y))*e);Fixation timesrestart:with(DEtools): General solution for the probability of fixationm(p):=s*p*(1-p); v(p):=p*(1-p)/(2*N);eq:=1+m(p)*diff(T(p),p)+v(p)*diff(T(p),p$2)/2;dsolve(eq=0,T(p));restart;P0(p):=int(F(y),y=p..1)/int(F(y),y=0..1);P1(p):=int(F(y),y=0..p)/int(F(y),y=0..1);F(y):=exp(-2*int(m(y)/v(y),y));U:=int(F,p=0..x)/int(F,p=0..1);