/* This file contains C code for the the infinite island model with no mutation in dioecious populations and the finite island model with k-allele mutation in s demes with dioecious populations. */ /* INFINITE ISLAND MODEL CODE STARTS HERE */ /* This program simulates the infinite island model with no mutation in dioecious populations */ /* Random number generator functions ignuin(), ranf() and gscgn() from the C library RANLIB (www.netlib.org/random/) are employed */ /* This program produces and prints estimates of Q1, Q2 and Q3 (in the array Qdat) which can then be used to estimate m and N */ /* No warranty, guarantee or technical support is associated with this code, users are responsible for their results */ #include #include #include #include #include "ranlib.h" /* m = migration rate N = effective population size reps = number of replicate simulations nL = number of loci s = number of demes sampled n = number of individuals genotyped per deme k = number of alleles at each locus nt = number of generations */ /* Main demographic parameters */ #define m 0.05 #define N 20 /* Sampling design */ #define reps 10 #define nL 20 #define n 50 #define k 8 /* Demographic scenario */ #define nt 1000 #define s 20 /* Number of random number generators in RANLIB */ #define ngen 32 int ikdraw(int,int); int main() { static long genlst[ngen]={0}; long igen; int iN1, iN2, ik; int IndM[nL][s][N]={{{0}}}, IndF[nL][s][N]={{{0}}}, IndMo[nL][s][N]={{{0}}}, IndFo[nL][s][N]={{{0}}}, G[nL][s][2*n]={{{0}}}; int qbit; double Q1e, p2s, Q1s, Q2s; double P[s][k]={{0}}, Qa[nL][3]={{0}}, Qdat[reps][5]={{0}}; int i0, i1, i2, i3, i4, i5, gct; FILE * fp; Q1e=((1-m)*(1-m))/2/N/(1-(1-m)*(1-m)*(1-1/2/N))+(1-(1-m)*(1-m))/(1-(1-m)*(1-m)*(1-1/2/N))/k; /* Equilibrium Q1 */ srand(time(NULL)); /* Seed the generator from the standard C library */ gct=1; for (i0=1; i0<=ngen; i0++) { genlst[i0-1]=i0; } /* Repeat for reps number of replicate simulations */ for (i0=1; i0<=reps; i0++) { setall(rand(),time(NULL)+i0); /* Seed the generators of RANLIB for each replicate*/ /* Draw random initial genotypes */ for (i1=1; i1<=s; i1++) { for (i2=1; i2<=N; i2++) { for (i3=1; i3<=nL; i3++) { IndM[i3-1][i1-1][i2-1]=ignuin(1,k); IndMo[i3-1][i1-1][i2-1]=IndM[i3-1][i1-1][i2-1]; IndF[i3-1][i1-1][i2-1]=ignuin(1,k); IndFo[i3-1][i1-1][i2-1]=IndF[i3-1][i1-1][i2-1]; } } } /* Iterate for nt-1 generations */ if (nt>=2) { for (i1=1; i1<=nt-1; i1++) { /* Pick a random number generator for each generation */ if (gct==ngen) {gct=1;} else {gct=gct+1;} igen=*(genlst+gct-1); gscgn(1,&igen); /* Iterate through demes */ for (i2=1; i2<=s; i2++) { for (i3=1; i3<=N/2; i3++) { /* Males */ if (ranf() #include #include #include #include "ranlib.h" /* u = mutation rate m = migration rate N = effective population size reps = number of replicate simulations nL = number of loci n = number of individuals genotyped per deme k = number of alleles at each locus nt = number of generations s = number of demes */ /* Main demographic parameters */ #define u 0.0005 #define m 0.05 #define N 20 /* Sampling design */ #define reps 10 #define nL 30 #define n 100 #define k 8 /* Demographic scenario */ #define nt 6000 #define s 20 /* Number of generators */ #define ngen 32 int isdraw(int,int); int ikdraw(int,int); int main() { static long genlst[ngen]={0}; long igen; int iN1, iN2, ik, is; int IndM[nL][s][N]={{{0}}}, IndF[nL][s][N]={{{0}}}, IndMo[nL][s][N]={{{0}}}, IndFo[nL][s][N]={{{0}}}, G[nL][s][2*n]={{{0}}}; int qbit; double p2s, Q1s, Q2s; double P[s][k]={{0}}, Qa[nL][3]={{0}}, Qdat[reps][5]={{0}}; int i0, i1, i2, i3, i4, i5, gct; FILE * fp; srand(time(NULL)); /* Seed the generator from the standard C library */ gct=1; for (i0=1; i0<=ngen; i0++) { genlst[i0-1]=i0; } /* Repeat for reps number of replicate simulations */ for (i0=1; i0<=reps; i0++) { setall(rand(),time(NULL)+i0); /* Seed the generators of RANLIB for each replicate*/ /* Draw random initial genotypes */ for (i1=1; i1<=s; i1++) { for (i2=1; i2<=N; i2++) { for (i3=1; i3<=nL; i3++) { IndM[i3-1][i1-1][i2-1]=ignuin(1,k); IndMo[i3-1][i1-1][i2-1]=IndM[i3-1][i1-1][i2-1]; IndF[i3-1][i1-1][i2-1]=ignuin(1,k); IndFo[i3-1][i1-1][i2-1]=IndF[i3-1][i1-1][i2-1]; } } } /* Iterate for nt-1 generations */ if (nt>=2) { for (i1=1; i1<=nt-1; i1++) { /* Pick a random number generator for each generation */ if (gct==ngen) {gct=1;} else {gct=gct+1;} igen=*(genlst+gct-1); gscgn(1,&igen); /* Iterate through demes */ for (i2=1; i2<=s; i2++) { for (i3=1; i3<=N/2; i3++) { /* Males */ if (ranf()