├── EXAMPLE ├── example ├── Output_d2_example ├── Output_Ne_example └── OUTPUT_example ├── USER´S GUIDE.pdf ├── GONE TUTORIAL.pdf ├── Linux ├── PROGRAMMES │ ├── GONE │ ├── GONEaverage │ ├── LD_SNP_REAL3 │ ├── SUMM_REP_CHROM3 │ ├── MANAGE_CHROMOSOMES2 │ ├── COMPILE&LINK.txt │ └── GONEparallel.sh ├── INPUT_PARAMETERS_FILE └── script_GONE.sh ├── MacOSX ├── PROGRAMMES │ ├── GONE │ ├── GONEaverage │ ├── LD_SNP_REAL3 │ ├── SUMM_REP_CHROM3 │ ├── MANAGE_CHROMOSOMES2 │ └── GONEparallel.sh ├── INPUT_PARAMETERS_FILE └── script_GONE.sh ├── CODES_LINUX ├── COMPILE&LINK.txt ├── SUMM_REP_CHROM3.c ├── GONEaverage.cpp ├── MANAGE_CHROMOSOMES2.c ├── libhdr ├── LD_SNP_REAL3.c └── GONE.cpp ├── CODES_MACOSX ├── COMPILE&LINK.txt ├── SUMM_REP_CHROM3.c ├── GONEaverage.cpp ├── MANAGE_CHROMOSOMES2.c ├── libhdr ├── LD_SNP_REAL3.c └── GONE.cpp └── README.md /EXAMPLE/example: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /USER´S GUIDE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/USER´S GUIDE.pdf -------------------------------------------------------------------------------- /GONE TUTORIAL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/GONE TUTORIAL.pdf -------------------------------------------------------------------------------- /Linux/PROGRAMMES/GONE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/Linux/PROGRAMMES/GONE -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/GONE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/MacOSX/PROGRAMMES/GONE -------------------------------------------------------------------------------- /Linux/PROGRAMMES/GONEaverage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/Linux/PROGRAMMES/GONEaverage -------------------------------------------------------------------------------- /Linux/PROGRAMMES/LD_SNP_REAL3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/Linux/PROGRAMMES/LD_SNP_REAL3 -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/GONEaverage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/MacOSX/PROGRAMMES/GONEaverage -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/LD_SNP_REAL3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/MacOSX/PROGRAMMES/LD_SNP_REAL3 -------------------------------------------------------------------------------- /Linux/PROGRAMMES/SUMM_REP_CHROM3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/Linux/PROGRAMMES/SUMM_REP_CHROM3 -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/SUMM_REP_CHROM3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/MacOSX/PROGRAMMES/SUMM_REP_CHROM3 -------------------------------------------------------------------------------- /Linux/PROGRAMMES/MANAGE_CHROMOSOMES2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/Linux/PROGRAMMES/MANAGE_CHROMOSOMES2 -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/MANAGE_CHROMOSOMES2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esrud/GONE/HEAD/MacOSX/PROGRAMMES/MANAGE_CHROMOSOMES2 -------------------------------------------------------------------------------- /CODES_LINUX/COMPILE&LINK.txt: -------------------------------------------------------------------------------- 1 | 2 | time cc -o LD_SNP_REAL3 -w -O -static LD_SNP_REAL3.c genlib.c -lm 3 | time cc -o SUMM_REP_CHROM3 -w -O -static SUMM_REP_CHROM3.c genlib.c -lm 4 | time cc -o MANAGE_CHROMOSOMES2 -w -O -static MANAGE_CHROMOSOMES2.c genlib.c -lm 5 | 6 | g++ -std=gnu++0x -static GONE.cpp 7 | mv a.out GONE 8 | g++ -std=gnu++0x -static GONEaverage.cpp 9 | mv a.out GONEaverage 10 | -------------------------------------------------------------------------------- /Linux/PROGRAMMES/COMPILE&LINK.txt: -------------------------------------------------------------------------------- 1 | 2 | time cc -o LD_SNP_REAL3 -w -O -static LD_SNP_REAL3.c genlib.c -lm 3 | time cc -o SUMM_REP_CHROM3 -w -O -static SUMM_REP_CHROM3.c genlib.c -lm 4 | time cc -o MANAGE_CHROMOSOMES2 -w -O -static MANAGE_CHROMOSOMES2.c genlib.c -lm 5 | 6 | g++ -std=gnu++0x -static GONE.cpp 7 | mv a.out GONE 8 | g++ -std=gnu++0x -static GONEaverage.cpp 9 | mv a.out GONEaverage 10 | -------------------------------------------------------------------------------- /CODES_MACOSX/COMPILE&LINK.txt: -------------------------------------------------------------------------------- 1 | Mac OSX instrucions: 2 | 3 | COMPILE 4 | gcc -c genlib.c 5 | gcc -c -static LD_SNP_REAL3.c (COMPILE in the same directory as libhdr) 6 | gcc -c -static MANAGE_CHROMOSOMES2.c (COMPILE in the same directory as libhdr) 7 | gcc -c -static SUMM_REP_CHROM3.c (COMPILE in the same directory as libhdr) 8 | 9 | LINK: 10 | gcc genlib.o LD_SNP_REAL3.o -lm -o LD_SNP_REAL3 11 | gcc genlib.o MANAGE_CHROMOSOMES2.o -lm -o MANAGE_CHROMOSOMES2 12 | gcc genlib.o SUMM_REP_CHROM3.o -lm -o SUMM_REP_CHROM3 13 | 14 | COMPILE&LINK: 15 | c++ -o GONE ./GONE.cpp 16 | c++ -o GONEaverage ./GONEaverage.cpp 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /EXAMPLE/Output_d2_example: -------------------------------------------------------------------------------- 1 | Sample d2 values. Average (d2obs-d2prd)^2 = 1.34554e-06 2 | rec.rate_c observed_d2 adjusted_d2 3 | 0.148248 0.066297 0.0651208 4 | 0.101803 0.073132 0.0719904 5 | 0.072247 0.07882 0.0807582 6 | 0.05597 0.086197 0.0891532 7 | 0.041013 0.103651 0.101734 8 | 0.028953 0.121714 0.119119 9 | 0.022402 0.134635 0.134451 10 | 0.018281 0.148388 0.148361 11 | 0.015443 0.160851 0.161197 12 | 0.013372 0.170688 0.173104 13 | 0.011791 0.183412 0.184208 14 | 0.010545 0.194279 0.194574 15 | 0.009538 0.204093 0.204261 16 | 0.008707 0.213159 0.213324 17 | 0.008008 0.222204 0.221833 18 | 0.007414 0.230125 0.2298 19 | 0.006902 0.237902 0.237285 20 | 0.006456 0.245454 0.244327 21 | 0.006064 0.251469 0.250961 22 | 0.005717 0.258854 0.257214 23 | 0.00527234 0.266175 0.265804 24 | 0.00476931 0.276124 0.276388 25 | 0.00435351 0.285703 0.285919 26 | 0.00386138 0.297316 0.298236 27 | 0.00334272 0.312079 0.312608 28 | 0.00294777 0.323772 0.324649 29 | 0.00251647 0.338667 0.339043 30 | 0.00209282 0.354959 0.354631 31 | 0.00168662 0.370774 0.37114 32 | 0.00121996 0.393125 0.39233 33 | -------------------------------------------------------------------------------- /MacOSX/INPUT_PARAMETERS_FILE: -------------------------------------------------------------------------------- 1 | #INPUT_PARAMETERS_FILE 2 | 3 | ######################################################## 4 | 5 | PHASE=2 ### Phase = 0 (pseudohaploids), 1 (known phase), 2 (unknown phase) 6 | cMMb=1 ### CentiMorgans per Megabase (if distance is not available in map file). 7 | DIST=1 ### none (0), Haldane correction (1) or Kosambi correction (2) 8 | NGEN=2000 ### Number of generations for which linkage data is obtained in bins 9 | NBIN=400 ### Number of bins (e.g. if 400, each bin includes NGEN/NBIN = 2000/400 = 5 generations) 10 | MAF=0.0 ### Minor allele frequency (0-1) (recommended 0) 11 | ZERO=1 ### 0: Remove SNPs with zeroes (1: allow for them) 12 | maxNCHROM=-99 ### Maximum number of chromosomes to be analysed (-99 = all chromosomes; maximum number is 200) 13 | maxNSNP=50000 ### Maximum approx number of SNPs per chromosomes to be analysed (maximum number is 50000) 14 | hc=0.05 ### Maximum value of c analysed (recommended 0.05; maximum is 0.5) 15 | REPS=40 ### Number of replicates to run GONE (recommended 40) 16 | threads=-99 ### Number of threads (if -99 it uses all possible processors) 17 | 18 | ################################################################### 19 | -------------------------------------------------------------------------------- /Linux/INPUT_PARAMETERS_FILE: -------------------------------------------------------------------------------- 1 | #INPUT_PARAMETERS_FILE 2 | 3 | ######################################################## 4 | 5 | PHASE=2 ### Phase = 0 (pseudohaploids), 1 (known phase), 2 (unknown phase) 6 | cMMb=1 ### CentiMorgans per Megabase (if distance is not available in map file). 7 | DIST=1 ### none (0), Haldane correction (1) or Kosambi correction (2) 8 | NGEN=2000 ### Number of generations for which linkage data is obtained in bins 9 | NBIN=400 ### Number of bins (e.g. if 400, each bin includes NGEN/NBIN = 2000/400 = 5 generations) 10 | MAF=0.0 ### Minor allele frequency (0-1) (recommended 0) 11 | ZERO=1 ### 0: Remove SNPs with zeroes (1: allow for them) 12 | maxNCHROM=-99 ### Maximum number of chromosomes to be analysed (-99 = all chromosomes; maximum number is 200) 13 | maxNSNP=50000 ### Maximum approx number of SNPs per chromosomes to be analysed (maximum number is 50000) 14 | hc=0.05 ### Maximum value of c analysed (recommended 0.05; maximum is 0.5) 15 | REPS=40 ### Number of replicates to run GONE (recommended 40) 16 | threads=-99 ### Number of threads (if -99 it uses all possible processors) 17 | 18 | ################################################################### 19 | 20 | -------------------------------------------------------------------------------- /Linux/PROGRAMMES/GONEparallel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | arg=("$@") 4 | options_for_GONE="" 5 | i=0; 6 | while [ $i -lt $[$#-2] ] 7 | do 8 | if [ "${arg[i]}" == "-lc" ] || [ "${arg[i]}" == "-hc" ] || [ "${arg[i]}" == "-ne" ] || [ "${arg[i]}" == "-sd" ] || [ "${arg[i]}" == "-bs" ] || [ "${arg[i]}" == "-bn" ] 9 | then 10 | i=$[$i+2] 11 | elif [ "${arg[i]}" == "-sr" ] || [ "${arg[i]}" == "-vb" ] 12 | then 13 | i=$[$i+1] 14 | else 15 | break 16 | fi 17 | done 18 | 19 | for ((j=0;j [number_of_threads]" 38 | exit 1 39 | fi 40 | 41 | dirtemp="${fichero}_TEMP" 42 | 43 | if [ -d $dirtemp ] 44 | then 45 | rm -r $dirtemp 46 | fi 47 | mkdir $dirtemp 48 | for ((nr=1; nr<=$repeats; nr++)); do echo $nr; done | xargs -I % -P $threads bash -c "./PROGRAMMES/GONE $options_for_GONE $fichero ${dirtemp}/${fichero}_%" 49 | 50 | ./PROGRAMMES/GONEaverage $dirtemp $fichero $repeats 51 | echo " END OF ALL PROCESSES" 52 | -------------------------------------------------------------------------------- /MacOSX/PROGRAMMES/GONEparallel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | arg=("$@") 4 | options_for_GONE="" 5 | i=0; 6 | while [ $i -lt $[$#-2] ] 7 | do 8 | if [ "${arg[i]}" == "-lc" ] || [ "${arg[i]}" == "-hc" ] || [ "${arg[i]}" == "-ne" ] || [ "${arg[i]}" == "-sd" ] || [ "${arg[i]}" == "-bs" ] || [ "${arg[i]}" == "-bn" ] 9 | then 10 | i=$[$i+2] 11 | elif [ "${arg[i]}" == "-sr" ] || [ "${arg[i]}" == "-vb" ] 12 | then 13 | i=$[$i+1] 14 | else 15 | break 16 | fi 17 | done 18 | 19 | for ((j=0;j [number_of_threads]" 38 | exit 1 39 | fi 40 | 41 | dirtemp="${fichero}_TEMP" 42 | 43 | if [ -d $dirtemp ] 44 | then 45 | rm -r $dirtemp 46 | fi 47 | mkdir $dirtemp 48 | for ((nr=1; nr<=$repeats; nr++)); do echo $nr; done | xargs -I % -P $threads bash -c "./PROGRAMMES/GONE $options_for_GONE $fichero ${dirtemp}/${fichero}_%" 49 | 50 | ./PROGRAMMES/GONEaverage $dirtemp $fichero $repeats 51 | echo " END OF ALL PROCESSES" 52 | -------------------------------------------------------------------------------- /CODES_LINUX/SUMM_REP_CHROM3.c: -------------------------------------------------------------------------------- 1 | // SUMM_REP_CHROM3.c 2 | 3 | #include "libhdr" 4 | #define BB 1001 5 | 6 | int x, a, c, b, nchrom, NGEN, NBIN, PHASE, SAM, totSNP, numSNP; 7 | unsigned long long int sumi[BB]; 8 | double w, sumcc[BB], sumd2[BB], sumD2[BB], sumVV[BB]; 9 | double cc[BB], d2[BB], D2[BB], VV[BB], F, G, numNIND; 10 | 11 | FILE *fin, *fout, *fhwd, *fnsnp; 12 | 13 | main() 14 | { 15 | getintandskip("NGEN :",&NGEN, 1, 5000); 16 | getintandskip("NBIN :",&NBIN, 1, 1000); 17 | getintandskip("n.chrom :",&nchrom, 1, 301); 18 | 19 | /* ***************** readfile ******************** */ 20 | 21 | fout = fopen ("outfileLD","w"); 22 | fhwd = fopen ("outfileHWD","w"); 23 | fnsnp = fopen ("nsnp","w"); 24 | fin = fopen ("CHROM","r"); 25 | 26 | for (c=1; c<=nchrom; c++) 27 | { 28 | fscanf(fin,"%d", &x); 29 | PHASE = x; 30 | fscanf(fin,"%d", &x); 31 | SAM = x; 32 | fscanf(fin,"%d", &x); 33 | numSNP = x; 34 | totSNP += numSNP; 35 | 36 | fscanf(fin,"%lf", &w); 37 | if (w != -99) 38 | { 39 | numNIND += w*numSNP; 40 | } 41 | 42 | fscanf(fin,"%lf", &w); 43 | if (w != -99) 44 | { 45 | F += w*numSNP; 46 | } 47 | 48 | for (b=1; b<=NBIN; b++) 49 | { 50 | fscanf(fin,"%d", &a); 51 | sumi[b] += a; 52 | fscanf(fin,"%lf", &w); 53 | sumcc[b] += w*a; 54 | fscanf(fin,"%lf", &w); 55 | sumd2[b] += w*a; 56 | fscanf(fin,"%d", &x); 57 | fscanf(fin,"%lf", &w); 58 | sumD2[b] += w*a; 59 | fscanf(fin,"%lf", &w); 60 | sumVV[b] += w*a; 61 | } 62 | } 63 | for (b=1; b<=NBIN; b++) 64 | { 65 | cc[b] = sumcc[b] / sumi[b]; 66 | d2[b] = sumd2[b] / sumi[b]; 67 | D2[b] = sumD2[b] / sumi[b]; 68 | VV[b] = sumVV[b] / sumi[b]; 69 | } 70 | 71 | fclose(fin); 72 | 73 | fprintf(fnsnp,"%d\n", totSNP); 74 | 75 | /* ***** outfileHWD ********************************************************* */ 76 | 77 | fprintf(fhwd,"%f Hardy-Weinberg deviation (sample)\n", F/totSNP); 78 | fprintf(fhwd,"%f Hardy-Weinberg deviation (population)\n", (1.0 + ((F/totSNP)*(2.0*SAM - 1.0))) / (2.0*SAM - 1.0 + (F/totSNP))); 79 | 80 | /* ***** outfileLD ********************************************************* */ 81 | 82 | fprintf(fout,"%d Phase (0: pseudohaploids; 1: known phase; 2: unknown phase)\n", PHASE); 83 | fprintf(fout,"%f sample size (individuals; corrected for zeroes)\n", numNIND/totSNP); 84 | fprintf(fout,"%f Hardy-Weinberg deviation\n", F/totSNP); 85 | for (b=1; b<=NBIN; b++) 86 | if (sumi[b] != 0) 87 | { 88 | if (b <= 5) fprintf(fout,"%lld %f %f %d\n", sumi[b], cc[b], D2[b]/VV[b], 2*b); 89 | else fprintf(fout,"%lld %f %f %d\n", sumi[b], cc[b], D2[b]/VV[b], ((NGEN/NBIN)*(b-5))+10); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /CODES_MACOSX/SUMM_REP_CHROM3.c: -------------------------------------------------------------------------------- 1 | // SUMM_REP_CHROM3.c 2 | 3 | #include "libhdr" 4 | #define BB 1001 5 | 6 | int x, a, c, b, nchrom, NGEN, NBIN, PHASE, SAM, totSNP, numSNP; 7 | unsigned long long int sumi[BB]; 8 | double w, sumcc[BB], sumd2[BB], sumD2[BB], sumVV[BB]; 9 | double cc[BB], d2[BB], D2[BB], VV[BB], F, G, numNIND; 10 | 11 | FILE *fin, *fout, *fhwd, *fnsnp; 12 | 13 | main() 14 | { 15 | getintandskip("NGEN :",&NGEN, 1, 5000); 16 | getintandskip("NBIN :",&NBIN, 1, 1000); 17 | getintandskip("n.chrom :",&nchrom, 1, 301); 18 | 19 | /* ***************** readfile ******************** */ 20 | 21 | fout = fopen ("outfileLD","w"); 22 | fhwd = fopen ("outfileHWD","w"); 23 | fnsnp = fopen ("nsnp","w"); 24 | fin = fopen ("CHROM","r"); 25 | 26 | for (c=1; c<=nchrom; c++) 27 | { 28 | fscanf(fin,"%d", &x); 29 | PHASE = x; 30 | fscanf(fin,"%d", &x); 31 | SAM = x; 32 | fscanf(fin,"%d", &x); 33 | numSNP = x; 34 | totSNP += numSNP; 35 | 36 | fscanf(fin,"%lf", &w); 37 | if (w != -99) 38 | { 39 | numNIND += w*numSNP; 40 | } 41 | 42 | fscanf(fin,"%lf", &w); 43 | if (w != -99) 44 | { 45 | F += w*numSNP; 46 | } 47 | 48 | for (b=1; b<=NBIN; b++) 49 | { 50 | fscanf(fin,"%d", &a); 51 | sumi[b] += a; 52 | fscanf(fin,"%lf", &w); 53 | sumcc[b] += w*a; 54 | fscanf(fin,"%lf", &w); 55 | sumd2[b] += w*a; 56 | fscanf(fin,"%d", &x); 57 | fscanf(fin,"%lf", &w); 58 | sumD2[b] += w*a; 59 | fscanf(fin,"%lf", &w); 60 | sumVV[b] += w*a; 61 | } 62 | } 63 | for (b=1; b<=NBIN; b++) 64 | { 65 | cc[b] = sumcc[b] / sumi[b]; 66 | d2[b] = sumd2[b] / sumi[b]; 67 | D2[b] = sumD2[b] / sumi[b]; 68 | VV[b] = sumVV[b] / sumi[b]; 69 | } 70 | 71 | fclose(fin); 72 | 73 | fprintf(fnsnp,"%d\n", totSNP); 74 | 75 | /* ***** outfileHWD ********************************************************* */ 76 | 77 | fprintf(fhwd,"%f Hardy-Weinberg deviation (sample)\n", F/totSNP); 78 | fprintf(fhwd,"%f Hardy-Weinberg deviation (population)\n", (1.0 + ((F/totSNP)*(2.0*SAM - 1.0))) / (2.0*SAM - 1.0 + (F/totSNP))); 79 | 80 | /* ***** outfileLD ********************************************************* */ 81 | 82 | fprintf(fout,"%d Phase (0: pseudohaploids; 1: known phase; 2: unknown phase)\n", PHASE); 83 | fprintf(fout,"%f sample size (individuals; corrected for zeroes)\n", numNIND/totSNP); 84 | fprintf(fout,"%f Hardy-Weinberg deviation\n", F/totSNP); 85 | for (b=1; b<=NBIN; b++) 86 | if (sumi[b] != 0) 87 | { 88 | if (b <= 5) fprintf(fout,"%lld %f %f %d\n", sumi[b], cc[b], D2[b]/VV[b], 2*b); 89 | else fprintf(fout,"%lld %f %f %d\n", sumi[b], cc[b], D2[b]/VV[b], ((NGEN/NBIN)*(b-5))+10); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GONE 2 | Scripts and programs referred to in the paper "Recent demographic history inferred by high-resolution analysis of linkage disequilibrium" by Enrique Santiago, Irene Novo, Antonio F. Pardiñas, María Saura, Jinliang Wang and Armando Caballero. Molecular Biology and Evolution, 2020 Volume 37, Issue 12, Pages 3642–3653, https://doi.org/10.1093/molbev/msaa169 3 | 4 | Articles showing the impact of population structure and other factors on GONE performance: 5 | 6 | - Novo I, Pérez-Pereira N, Santiago E, Quesada H, Caballero A. An empirical test of the estimation of historical effective population size using Drosophila melanogaster. Mol Ecol Resour. 2023 Oct;23(7):1632-1640. doi: 10.1111/1755-0998.13837. 7 | - Novo I, Ordás P, Moraga N, Santiago E, Quesada H, Caballero A. Impact of population structure in the estimation of recent historical effective population size by the software GONE. Genet Sel Evol. 2023 Dec 4;55(1):86. doi: 10.1186/s12711-023-00859-2. 8 | 9 | # USE 10 | To use the software please download the whole appropriate directory (Linux or MacOSX). These directories include the scripts and executables files of all necessary programmes. See USER´S GUIDE. 11 | The codes of the programmes are available in the directories CODES, but they are not necessary to run the software. 12 | 13 | # MODIFICATIONS 14 | 01/07/2020 Minor correction in LD_SNP_REAL3.c 15 | 16 | 07/07/2020 Minor modification in MANAGE_CHROMOSOMES2.c, INPUT_PARAMETERS_FILE and SCRIPT ESTIMATION Ne PROCEDURE.docx to note that a maximum of 100,000 SNPs are allowed per chromosome. A maximum number of 200 chromosomes and a maximum number of 1800 individuals are allowed. 17 | 18 | 25/08/2020 Minor modification in INPUT_PARAMETERS_FILE and SCRIPT ESTIMATION Ne PROCEDURE.docx to note that the option cMMb=0 (for human data) does not hold. If the .map file has genetic distances (third column), these will be used. If that column has zeroes (no genetic distances are available) then an average rate of recombination of cMMb (as included in the INPUT_PARAMETERS_FILE) will be assumed. 19 | 20 | 07/09/2020 Minor modification in LD_SNP_REAL3.c so that the string "-9" in the phenotypic column of the ped file is not necessary anymore and that string can be present in the pedfile without causing trouble. 21 | 22 | 13/09/2020 Corrected an error in the function to get random numbers in MANAGE_CHROMOSOMES2.c. Now the file called seedfile is necessary in the running directory to start the random sampling of SNPs within each chromosome. Every time a run is finished the seedfile will be changed automatically. 23 | 24 | 15/10/2020 Small correction in SCRIPT ESTIMATION Ne PROCEDURE.docx 25 | 26 | 26/10/2020 Small correction in script_GONE.sh to generate random seed, and the corresponding modification in SCRIPT ESTIMATION Ne PROCEDURE.pdf 27 | 28 | 09/01/2021 Small addition in SCRIPT ESTIMATION Ne PROCEDURE.docx: NOTE: If the population has recent migrants from another population, the estimation of Ne will be biased. A typical artefact observed is a very recent drastic drop and a previous increase (see Fig. 2f of manuscript). This can be partly corrected by using a maximum value of c lower than that recommended above, for example hc=0.01. 29 | 30 | 18/04/2021 Modification of programmes LD_SNP_REAL3.c and SUMM_REP_CHROM3.c to calculate the deviations from Hardy-Weinberg proportions (Wrigth's Fis). Estimates for the sample and for the population are now shown in the outfileHWD output file. If the estimate for the population substantialy deviates from the expected 0 value of a panmictic population (say Fis > 0.02 or Fis < -0.02), this may imply certain adxmixture in your sample and some artefacts, tipically a sudden recent drop in Ne, may be found. 31 | 32 | 21/06/2021 New USER´S GUIDE which substitutes the old SCRIPT ESTIMATION Ne PROCEDURE.docx 33 | 34 | 29/08/2021 Modification of the USER´S GUIDE to warn that if you make different runs of the script to consider different random subsets of SNPs, do not sent all runs at the same time, as the initial random seed is taken from the computer clock time. 35 | 36 | 30/07/2022 A tutorial for GONE has been added. 37 | 38 | 20/07/2025 A modification has been made to the programme LD_SNP_REAL3 to increase precision in the d^2 values from chromosomes. 39 | -------------------------------------------------------------------------------- /CODES_LINUX/GONEaverage.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // GONEaverage 4 | // 5 | // Created by Enrique Santiago on 18/11/19. 6 | // Copyright © 2019 Enrique Santiago. All rights reserved. 7 | // 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define maxlin 10000 17 | 18 | int main(int argc, const char * argv[]) { 19 | int i, a, nlin=0, nlin2=0, repeticiones; 20 | double b,c,d2o,d2p,NeA[maxlin],NeG[maxlin],NeH[maxlin]; 21 | double dif2=0.0,crec[maxlin],d2obs[maxlin],d2prd[maxlin]; 22 | int generacion[maxlin]; 23 | 24 | if (argc!=4){ 25 | std::cerr << " Usage: "<< argv[0]<< " [directory_of_temp_files] [name_of_input_file] [number_of_repeats] "<> a >> b)){ 51 | std::cerr << " Format error in file "<< fichentra<=maxlin){break;} 60 | } 61 | entrada.close(); 62 | // d2: 63 | std::string fichentra2=directorio+"/"+fichero+"_"+s+"_GONE_d2"; 64 | entrada.open(fichentra2, std::ios::in); 65 | if (!(entrada.is_open())){ 66 | std::cerr << " Error opening file "<< fichentra2 <<"\n"; 67 | return 1;} 68 | nlin2=0; 69 | while (getline(entrada, line)){ 70 | std::istringstream iss(line); 71 | if (!(iss >> c >> d2o >> d2p)){ 72 | std::cerr << " Format error in file "<< fichentra2<=maxlin){break;} 80 | } 81 | entrada.close(); 82 | } 83 | for (i=0;i 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define maxlin 10000 17 | 18 | int main(int argc, const char * argv[]) { 19 | int i, a, nlin=0, nlin2=0, repeticiones; 20 | double b,c,d2o,d2p,NeA[maxlin],NeG[maxlin],NeH[maxlin]; 21 | double dif2=0.0,crec[maxlin],d2obs[maxlin],d2prd[maxlin]; 22 | int generacion[maxlin]; 23 | 24 | if (argc!=4){ 25 | std::cerr << " Usage: "<< argv[0]<< " [directory_of_temp_files] [name_of_input_file] [number_of_repeats] "<> a >> b)){ 51 | std::cerr << " Format error in file "<< fichentra<=maxlin){break;} 60 | } 61 | entrada.close(); 62 | // d2: 63 | std::string fichentra2=directorio+"/"+fichero+"_"+s+"_GONE_d2"; 64 | entrada.open(fichentra2, std::ios::in); 65 | if (!(entrada.is_open())){ 66 | std::cerr << " Error opening file "<< fichentra2 <<"\n"; 67 | return 1;} 68 | nlin2=0; 69 | while (getline(entrada, line)){ 70 | std::istringstream iss(line); 71 | if (!(iss >> c >> d2o >> d2p)){ 72 | std::cerr << " Format error in file "<< fichentra2<=maxlin){break;} 80 | } 81 | entrada.close(); 82 | } 83 | for (i=0;i= snp_nchrom[c]) 47 | { 48 | for (s=1; s<=snp_nchrom[c]; s++) 49 | ranSNP[c][s]=1; 50 | } 51 | else 52 | { 53 | for (s=1; s<=snp_nchrom[c]; s++) 54 | if (uniform() <= ((double)maxNSNP/(double)snp_nchrom[c])) ranSNP[c][s]=1; 55 | } 56 | } 57 | 58 | // ******************** Read data.map ******************** 59 | 60 | FILE *mapchrom[NCHR]; 61 | for (c=1; c<=NCHR; c++) 62 | { 63 | char filename[20]; 64 | sprintf(filename, "chromosome%d.map", c); 65 | mapchrom[c] = fopen(filename, "w"); 66 | } 67 | 68 | fmap = fopen ("data.map","r"); 69 | 70 | for (c=1; c<=NCHR; c++) 71 | { 72 | for (s=1; s<=snp_nchrom[c]; s++) 73 | { 74 | fscanf(fmap,"%d", &x); 75 | if (maxNSNP == -99) fprintf(mapchrom[c], "%d\t", x); 76 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%d\t", x); 77 | 78 | fscanf(fmap,"%s", &S); 79 | if (maxNSNP == -99) fprintf(mapchrom[c], "%s\t", S); 80 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%s\t", S); 81 | 82 | fscanf(fmap,"%lf", &w); 83 | if (maxNSNP == -99) fprintf(mapchrom[c], "%f\t", w); 84 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%f\t", w); 85 | 86 | fscanf(fmap,"%d", &x); 87 | if (maxNSNP == -99) fprintf(mapchrom[c], "%d\n", x); 88 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%d\n", x); 89 | } 90 | } 91 | 92 | fclose(fmap); 93 | 94 | // ******************** Read data.ped ******************** 95 | 96 | FILE *pedchrom[NCHR]; 97 | for (c=1; c<=NCHR; c++) 98 | { 99 | char filename[20]; 100 | sprintf(filename, "chromosome%d.ped", c); 101 | pedchrom[c] = fopen(filename, "w"); 102 | } 103 | 104 | fped = fopen ("data.ped","r"); 105 | 106 | for (i=1; i<=NIND; i++) 107 | { 108 | fscanf(fped,"%s", &S); 109 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 110 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 111 | 112 | fscanf(fped,"%s", &S); 113 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 114 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 115 | 116 | fscanf(fped,"%s", &S); 117 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 118 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 119 | 120 | fscanf(fped,"%s", &S); 121 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 122 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 123 | 124 | fscanf(fped,"%s", &S); 125 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 126 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 127 | 128 | fscanf(fped,"%s", &S); 129 | // if ((i==1)||(i==2)) fprintf(fcheck, "-9 "); 130 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "-9 "); 131 | 132 | for (c=1; c<=NCHR; c++) 133 | { 134 | for (s=1; s<=snp_nchrom[c]; s++) 135 | { 136 | fscanf(fped,"%s", &S); 137 | if (maxNSNP == -99) fprintf(pedchrom[c], "%s ", S); 138 | else if (ranSNP[c][s] == 1) fprintf(pedchrom[c], "%s ", S); 139 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 140 | 141 | fscanf(fped,"%s", &S); 142 | if (maxNSNP == -99) fprintf(pedchrom[c], "%s ", S); 143 | else if (ranSNP[c][s] == 1) fprintf(pedchrom[c], "%s ", S); 144 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ",S); 145 | } 146 | fprintf(pedchrom[c], "\n"); 147 | } 148 | } 149 | 150 | fclose(fped); 151 | writeseed(); 152 | 153 | return(0); 154 | } 155 | 156 | /* **************************************************************************** */ 157 | -------------------------------------------------------------------------------- /CODES_MACOSX/MANAGE_CHROMOSOMES2.c: -------------------------------------------------------------------------------- 1 | 2 | // MANAGE_CHROMOSOMES2.c 3 | 4 | #include "libhdr" 5 | #define CC 200 6 | #define SS 1000000 7 | 8 | int maxNSNP, x, i, c, s, k, NCHR, NIND, snp_nchrom[CC], ranSNP[CC][SS]; 9 | double w; 10 | char S[CC], ch; 11 | 12 | FILE *fnchr, *fnind, *fsnpchrom, *fmap, *fped, *fcheck; 13 | 14 | main() 15 | { 16 | // fcheck = fopen ("checkfile","w"); 17 | 18 | getseed(); 19 | getintandskip("maxNSNP :",&maxNSNP, -99, 100000); 20 | 21 | // ******************** Read NCHR, NIND and NSNP ******************** 22 | 23 | fnchr = fopen ("NCHR","r"); 24 | fscanf(fnchr,"%d", &x); 25 | NCHR = x; 26 | // printf("NCHR=%d\n\n", NCHR); 27 | 28 | fnind = fopen ("NIND","r"); 29 | fscanf(fnind,"%d", &x); 30 | NIND = x; 31 | // printf("NIND=%d\n\n", NIND); 32 | 33 | fsnpchrom = fopen ("SNP_CHROM","r"); 34 | for (c=1; c<=NCHR; c++) 35 | { 36 | fscanf(fsnpchrom,"%d", &x); 37 | snp_nchrom[c] = x; 38 | // if (c==1) printf("NSNP_CHROM[%d]=%d\n", c, snp_nchrom[c]); 39 | } 40 | 41 | // ******** Randomize SNPs ******* 42 | 43 | if (maxNSNP != -99) 44 | for (c=1; c<=NCHR; c++) 45 | { 46 | if (maxNSNP >= snp_nchrom[c]) 47 | { 48 | for (s=1; s<=snp_nchrom[c]; s++) 49 | ranSNP[c][s]=1; 50 | } 51 | else 52 | { 53 | for (s=1; s<=snp_nchrom[c]; s++) 54 | if (uniform() <= ((double)maxNSNP/(double)snp_nchrom[c])) ranSNP[c][s]=1; 55 | } 56 | } 57 | 58 | // ******************** Read data.map ******************** 59 | 60 | FILE *mapchrom[NCHR]; 61 | for (c=1; c<=NCHR; c++) 62 | { 63 | char filename[20]; 64 | sprintf(filename, "chromosome%d.map", c); 65 | mapchrom[c] = fopen(filename, "w"); 66 | } 67 | 68 | fmap = fopen ("data.map","r"); 69 | 70 | for (c=1; c<=NCHR; c++) 71 | { 72 | for (s=1; s<=snp_nchrom[c]; s++) 73 | { 74 | fscanf(fmap,"%d", &x); 75 | if (maxNSNP == -99) fprintf(mapchrom[c], "%d\t", x); 76 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%d\t", x); 77 | 78 | fscanf(fmap,"%s", &S); 79 | if (maxNSNP == -99) fprintf(mapchrom[c], "%s\t", S); 80 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%s\t", S); 81 | 82 | fscanf(fmap,"%lf", &w); 83 | if (maxNSNP == -99) fprintf(mapchrom[c], "%f\t", w); 84 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%f\t", w); 85 | 86 | fscanf(fmap,"%d", &x); 87 | if (maxNSNP == -99) fprintf(mapchrom[c], "%d\n", x); 88 | else if (ranSNP[c][s] == 1) fprintf(mapchrom[c], "%d\n", x); 89 | } 90 | } 91 | 92 | fclose(fmap); 93 | 94 | // ******************** Read data.ped ******************** 95 | 96 | FILE *pedchrom[NCHR]; 97 | for (c=1; c<=NCHR; c++) 98 | { 99 | char filename[20]; 100 | sprintf(filename, "chromosome%d.ped", c); 101 | pedchrom[c] = fopen(filename, "w"); 102 | } 103 | 104 | fped = fopen ("data.ped","r"); 105 | 106 | for (i=1; i<=NIND; i++) 107 | { 108 | fscanf(fped,"%s", &S); 109 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 110 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 111 | 112 | fscanf(fped,"%s", &S); 113 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 114 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 115 | 116 | fscanf(fped,"%s", &S); 117 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 118 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 119 | 120 | fscanf(fped,"%s", &S); 121 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 122 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 123 | 124 | fscanf(fped,"%s", &S); 125 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 126 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "%s ", S); 127 | 128 | fscanf(fped,"%s", &S); 129 | // if ((i==1)||(i==2)) fprintf(fcheck, "-9 "); 130 | for (c=1; c<=NCHR; c++) fprintf(pedchrom[c], "-9 "); 131 | 132 | for (c=1; c<=NCHR; c++) 133 | { 134 | for (s=1; s<=snp_nchrom[c]; s++) 135 | { 136 | fscanf(fped,"%s", &S); 137 | if (maxNSNP == -99) fprintf(pedchrom[c], "%s ", S); 138 | else if (ranSNP[c][s] == 1) fprintf(pedchrom[c], "%s ", S); 139 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ", S); 140 | 141 | fscanf(fped,"%s", &S); 142 | if (maxNSNP == -99) fprintf(pedchrom[c], "%s ", S); 143 | else if (ranSNP[c][s] == 1) fprintf(pedchrom[c], "%s ", S); 144 | // if ((i==1)||(i==2)) fprintf(fcheck, "%s ",S); 145 | } 146 | fprintf(pedchrom[c], "\n"); 147 | } 148 | } 149 | 150 | fclose(fped); 151 | writeseed(); 152 | 153 | return(0); 154 | } 155 | 156 | /* **************************************************************************** */ 157 | -------------------------------------------------------------------------------- /Linux/script_GONE.sh: -------------------------------------------------------------------------------- 1 | #script_GONE.sh 2 | 3 | ######################################################## 4 | 5 | #Check number of arguments 6 | if [ $# -ne 1 ] 7 | then 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | 12 | ### Set arguments 13 | 14 | FILE=$1 ### Data file name for files .ped and .map 15 | 16 | ### Take input parameters from file INPUT_PARAMETERS_FILE 17 | 18 | source INPUT_PARAMETERS_FILE 19 | 20 | ###################### FILES NEEDED ######################## 21 | 22 | ### data.ped 23 | ### data.map 24 | 25 | ### EXECUTABLES FILES NEEDED IN DIRECTORY PROGRAMMES: 26 | 27 | ### MANAGE_CHROMOSOMES2 28 | ### LD_SNP_REAL3 29 | ### SUMM_REP_CHROM3 30 | ### GONE (needs gcc/7.2.0) 31 | ### GONEaverages 32 | ### GONEparallel.sh 33 | 34 | ################### Remove previous output files ################## 35 | 36 | if [ -f "OUTPUT_$FILE" ] 37 | then 38 | rm OUTPUT_$FILE 39 | fi 40 | 41 | if [ -f "Ne_$FILE" ] 42 | then 43 | rm Ne_$FILE 44 | fi 45 | 46 | ################### Create temporary directory ################## 47 | 48 | if [ -d "TEMPORARY_FILES" ] 49 | then 50 | rm -r TEMPORARY_FILES 51 | fi 52 | 53 | mkdir TEMPORARY_FILES 54 | 55 | ################### Obtain sample size, number of chromosomes, number of SNPs ################## 56 | 57 | cp $FILE.map data.map 58 | cp $FILE.ped data.ped 59 | 60 | tr '\t' ' ' < data.map > KK1 61 | cut -d ' ' -f1 < KK1 > KK2 62 | 63 | grep -w "" -c data.ped > NIND 64 | 65 | tail -n 1 data.map | tr '\t' ' ' | cut -d ' ' -f1 > NCHR 66 | 67 | SAM=$(grep -w "" -c $FILE.ped) 68 | 69 | NCHR=$(tail -n 1 data.map | tr '\t' ' ' | cut -d ' ' -f1) 70 | 71 | for((i=1;i<=$NCHR;i++)) 72 | do 73 | grep -wc "$i" < KK2 > NCHR$i 74 | done 75 | 76 | if [ -f "SNP_CHROM" ] 77 | then 78 | rm SNP_CHROM 79 | fi 80 | 81 | for((i=1;i<=$NCHR;i++)) 82 | do 83 | cat NCHR$i >> SNP_CHROM 84 | done 85 | 86 | rm KK* 87 | 88 | ################### Divide ped and map files into chromosomes ################## 89 | 90 | echo "DIVIDE .ped AND .map FILES IN CHROMOSOMES" 91 | echo "DIVIDE .ped AND .map FILES IN CHROMOSOMES" > timefile 92 | 93 | num=$RANDOM 94 | echo "$num" > seedfile 95 | 96 | ./PROGRAMMES/MANAGE_CHROMOSOMES2>>out<<@ 97 | -99 98 | $maxNSNP 99 | @ 100 | 101 | rm NCHR* 102 | rm NIND 103 | rm SNP_CHROM 104 | ###mv checkfile TEMPORARY_FILES/ 105 | 106 | ################### LOOP CHROMOSOMES ################## 107 | ### Analysis of linkage disequilibrium in windows of genetic 108 | ### distances between pairs of SNPs for each chromosome 109 | 110 | if [ $maxNCHROM != -99 ] 111 | then 112 | NCHR=$maxNCHROM 113 | fi 114 | 115 | echo "RUNNING ANALYSIS OF CHROMOSOMES ..." 116 | echo "RUNNING ANALYSIS OF CHROMOSOMES" >> timefile 117 | 118 | options_for_LD="$SAM $MAF $PHASE $NGEN $NBIN $ZERO $DIST $cMMb" 119 | 120 | if [ $threads -eq -99 ] 121 | then 122 | threads=$(getconf _NPROCESSORS_ONLN) 123 | fi 124 | 125 | START=$(date +%s) 126 | 127 | cp chromosome* TEMPORARY_FILES/ 128 | 129 | ###### LD_SNP_REAL3 ####### 130 | 131 | ### Obtains values of c, d2, etc. for pairs of SNPs in bins for each chromosome 132 | for ((n=1; n<=$NCHR; n++)); do echo $n; done | xargs -I % -P $threads bash -c "./PROGRAMMES/LD_SNP_REAL3 % $options_for_LD" 133 | 134 | END=$(date +%s) 135 | DIFF=$(( $END - $START )) 136 | echo "CHROMOSOME ANALYSES took $DIFF seconds" 137 | echo "CHROMOSOME ANALYSES took $DIFF seconds" >> timefile 138 | 139 | ######################## SUMM_REP_CHROM3 ######################### 140 | ### Combination of all data gathered from chromosomes into a single output file 141 | 142 | ### Adds results from all chromosomes 143 | 144 | for ((n=1; n<=$NCHR; n++)) 145 | do 146 | cat outfileLD$n >> CHROM 147 | echo "CHROMOSOME $n" >> OUTPUT 148 | sed '2,3d' outfileLD$n > temp 149 | mv temp outfileLD$n 150 | cat parameters$n >> OUTPUT 151 | done 152 | 153 | mv outfileLD* TEMPORARY_FILES/ 154 | rm parameters* 155 | 156 | ./PROGRAMMES/SUMM_REP_CHROM3>>out<<@ 157 | $NGEN NGEN 158 | $NBIN NBIN 159 | $NCHR NCHR 160 | @ 161 | 162 | mv chrom* TEMPORARY_FILES/ 163 | 164 | echo "TOTAL NUMBER OF SNPs" >> OUTPUT_$FILE 165 | cat nsnp >> OUTPUT_$FILE 166 | echo -e "\n" >> OUTPUT_$FILE 167 | echo "HARDY-WEINBERG DEVIATION" >> OUTPUT_$FILE 168 | cat outfileHWD >> OUTPUT_$FILE 169 | echo -e "\n" >> OUTPUT_$FILE 170 | cat OUTPUT >> OUTPUT_$FILE 171 | echo -e "\n" >> OUTPUT_$FILE 172 | echo "INPUT FOR GONE" >> OUTPUT_$FILE 173 | echo -e "\n" >> OUTPUT_$FILE 174 | cat outfileLD >> OUTPUT_$FILE 175 | 176 | rm nsnp 177 | rm OUTPUT 178 | rm CHROM 179 | 180 | ############################# GONE.cpp ########################## 181 | ### Obtain estimates of temporal Ne from GONE 182 | 183 | echo "Running GONE" 184 | echo "Running GONE" >> timefile 185 | START=$(date +%s) 186 | 187 | ./PROGRAMMES/GONEparallel.sh -hc $hc outfileLD $REPS 188 | 189 | END=$(date +%s) 190 | DIFF=$(( $END - $START )) 191 | echo "GONE run took $DIFF seconds" 192 | echo "GONE run took $DIFF seconds" >> timefile 193 | 194 | echo "END OF ANALYSES" 195 | echo "END OF ANALYSES" >> timefile 196 | 197 | mv outfileLD_Ne_estimates Output_Ne_$FILE 198 | mv outfileLD_d2_sample Output_d2_$FILE 199 | rm outfileLD 200 | rm data.ped 201 | rm data.map 202 | rm out 203 | mv outfileLD_TEMP TEMPORARY_FILES/ 204 | 205 | ################################################################### 206 | -------------------------------------------------------------------------------- /MacOSX/script_GONE.sh: -------------------------------------------------------------------------------- 1 | #script_GONE.sh 2 | 3 | ######################################################## 4 | 5 | #Check number of arguments 6 | if [ $# -ne 1 ] 7 | then 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | 12 | ### Set arguments 13 | 14 | FILE=$1 ### Data file name for files .ped and .map 15 | 16 | ### Take input parameters from file INPUT_PARAMETERS_FILE 17 | 18 | source INPUT_PARAMETERS_FILE 19 | 20 | ###################### FILES NEEDED ######################## 21 | 22 | ### data.ped 23 | ### data.map 24 | 25 | ### EXECUTABLES FILES NEEDED IN DIRECTORY PROGRAMMES: 26 | 27 | ### MANAGE_CHROMOSOMES2 28 | ### LD_SNP_REAL3 29 | ### SUMM_REP_CHROM3 30 | ### GONE (needs gcc/7.2.0) 31 | ### GONEaverages 32 | ### GONEparallel.sh 33 | 34 | ################### Remove previous output files ################## 35 | 36 | if [ -f "OUTPUT_$FILE" ] 37 | then 38 | rm OUTPUT_$FILE 39 | fi 40 | 41 | if [ -f "Ne_$FILE" ] 42 | then 43 | rm Ne_$FILE 44 | fi 45 | 46 | ################### Create temporary directory ################## 47 | 48 | if [ -d "TEMPORARY_FILES" ] 49 | then 50 | rm -r TEMPORARY_FILES 51 | fi 52 | 53 | mkdir TEMPORARY_FILES 54 | 55 | ################### Obtain sample size, number of chromosomes, number of SNPs ################## 56 | 57 | cp $FILE.map data.map 58 | cp $FILE.ped data.ped 59 | 60 | tr '\t' ' ' < data.map > KK1 61 | cut -d ' ' -f1 < KK1 > KK2 62 | 63 | grep -w "" -c data.ped > NIND 64 | 65 | tail -n 1 data.map | tr '\t' ' ' | cut -d ' ' -f1 > NCHR 66 | 67 | SAM=$(grep -w "" -c $FILE.ped) 68 | 69 | NCHR=$(tail -n 1 data.map | tr '\t' ' ' | cut -d ' ' -f1) 70 | 71 | for((i=1;i<=$NCHR;i++)) 72 | do 73 | grep -wc "$i" < KK2 > NCHR$i 74 | done 75 | 76 | if [ -f "SNP_CHROM" ] 77 | then 78 | rm SNP_CHROM 79 | fi 80 | 81 | for((i=1;i<=$NCHR;i++)) 82 | do 83 | cat NCHR$i >> SNP_CHROM 84 | done 85 | 86 | rm KK* 87 | 88 | ################### Divide ped and map files into chromosomes ################## 89 | 90 | echo "DIVIDE .ped AND .map FILES IN CHROMOSOMES" 91 | echo "DIVIDE .ped AND .map FILES IN CHROMOSOMES" > timefile 92 | 93 | num=$RANDOM 94 | echo "$num" > seedfile 95 | 96 | ./PROGRAMMES/MANAGE_CHROMOSOMES2>>out<<@ 97 | -99 98 | $maxNSNP 99 | @ 100 | 101 | rm NCHR* 102 | rm NIND 103 | rm SNP_CHROM 104 | ###mv checkfile TEMPORARY_FILES/ 105 | 106 | ################### LOOP CHROMOSOMES ################## 107 | ### Analysis of linkage disequilibrium in windows of genetic 108 | ### distances between pairs of SNPs for each chromosome 109 | 110 | if [ $maxNCHROM != -99 ] 111 | then 112 | NCHR=$maxNCHROM 113 | fi 114 | 115 | echo "RUNNING ANALYSIS OF CHROMOSOMES ..." 116 | echo "RUNNING ANALYSIS OF CHROMOSOMES" >> timefile 117 | 118 | options_for_LD="$SAM $MAF $PHASE $NGEN $NBIN $ZERO $DIST $cMMb" 119 | 120 | if [ $threads -eq -99 ] 121 | then 122 | threads=$(getconf _NPROCESSORS_ONLN) 123 | fi 124 | 125 | START=$(date +%s) 126 | 127 | cp chromosome* TEMPORARY_FILES/ 128 | 129 | ###### LD_SNP_REAL3 ####### 130 | 131 | ### Obtains values of c, d2, etc. for pairs of SNPs in bins for each chromosome 132 | for ((n=1; n<=$NCHR; n++)); do echo $n; done | xargs -I % -P $threads bash -c "./PROGRAMMES/LD_SNP_REAL3 % $options_for_LD" 133 | 134 | END=$(date +%s) 135 | DIFF=$(( $END - $START )) 136 | echo "CHROMOSOME ANALYSES took $DIFF seconds" 137 | echo "CHROMOSOME ANALYSES took $DIFF seconds" >> timefile 138 | 139 | ######################## SUMM_REP_CHROM3 ######################### 140 | ### Combination of all data gathered from chromosomes into a single output file 141 | 142 | ### Adds results from all chromosomes 143 | 144 | for ((n=1; n<=$NCHR; n++)) 145 | do 146 | cat outfileLD$n >> CHROM 147 | echo "CHROMOSOME $n" >> OUTPUT 148 | sed '2,3d' outfileLD$n > temp 149 | mv temp outfileLD$n 150 | cat parameters$n >> OUTPUT 151 | done 152 | 153 | mv outfileLD* TEMPORARY_FILES/ 154 | rm parameters* 155 | 156 | ./PROGRAMMES/SUMM_REP_CHROM3>>out<<@ 157 | $NGEN NGEN 158 | $NBIN NBIN 159 | $NCHR NCHR 160 | @ 161 | 162 | mv chrom* TEMPORARY_FILES/ 163 | 164 | echo "TOTAL NUMBER OF SNPs" >> OUTPUT_$FILE 165 | cat nsnp >> OUTPUT_$FILE 166 | echo -e "\n" >> OUTPUT_$FILE 167 | echo "HARDY-WEINBERG DEVIATION" >> OUTPUT_$FILE 168 | cat outfileHWD >> OUTPUT_$FILE 169 | echo -e "\n" >> OUTPUT_$FILE 170 | cat OUTPUT >> OUTPUT_$FILE 171 | echo -e "\n" >> OUTPUT_$FILE 172 | echo "INPUT FOR GONE" >> OUTPUT_$FILE 173 | echo -e "\n" >> OUTPUT_$FILE 174 | cat outfileLD >> OUTPUT_$FILE 175 | 176 | rm nsnp 177 | rm OUTPUT 178 | rm CHROM 179 | 180 | ############################# GONE.cpp ########################## 181 | ### Obtain estimates of temporal Ne from GONE 182 | 183 | echo "Running GONE" 184 | echo "Running GONE" >> timefile 185 | START=$(date +%s) 186 | 187 | ./PROGRAMMES/GONEparallel.sh -hc $hc outfileLD $REPS 188 | 189 | END=$(date +%s) 190 | DIFF=$(( $END - $START )) 191 | echo "GONE run took $DIFF seconds" 192 | echo "GONE run took $DIFF seconds" >> timefile 193 | 194 | echo "END OF ANALYSES" 195 | echo "END OF ANALYSES" >> timefile 196 | 197 | mv outfileLD_Ne_estimates Output_Ne_$FILE 198 | mv outfileLD_d2_sample Output_d2_$FILE 199 | rm outfileLD 200 | rm data.ped 201 | rm data.map 202 | rm out 203 | mv outfileLD_TEMP TEMPORARY_FILES/ 204 | 205 | ################################################################### 206 | -------------------------------------------------------------------------------- /CODES_LINUX/libhdr: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #define true 1 7 | #define false 0 8 | #define infinity 999999 9 | #define pi 3.1415927 10 | #define maxranges 5 /* for numerical integration */ 11 | #define maxsimpsonpoints 1025 /* change genlib.c if these changed */ 12 | 13 | struct acc 14 | { 15 | int n; 16 | double sum; 17 | double sumsq; 18 | int n2; 19 | double sum2; 20 | double sumsq2; 21 | }; 22 | 23 | struct covacc 24 | { 25 | int n; 26 | double sumxy, sumx, sumy, sumx2, sumy2; 27 | }; 28 | 29 | 30 | extern long seed; 31 | 32 | extern long rseed; 33 | 34 | extern int tracelevel; 35 | 36 | extern int inputcounter; 37 | 38 | extern initcovacc(); 39 | 40 | extern covaccum(); 41 | 42 | extern double covariance(); 43 | 44 | extern double correlation(); 45 | 46 | extern float ranqd2(); 47 | 48 | extern double uniform(); 49 | 50 | extern initacc(struct acc *a); 51 | 52 | extern accum(struct acc *a, double x); 53 | 54 | extern double accmean(struct acc *a); 55 | 56 | extern double accsum(struct acc *a); 57 | 58 | extern double variance(struct acc *a); 59 | 60 | extern getseed(); 61 | 62 | extern getseedquick(); 63 | 64 | extern writeseed(); 65 | 66 | extern double normal(); 67 | 68 | extern quicknormal(); 69 | 70 | extern double doublegamma(); 71 | 72 | extern wishart(); 73 | 74 | extern bivnormal(); 75 | 76 | extern cubenormal(); 77 | 78 | extern double se(); 79 | 80 | extern printmse(); 81 | 82 | extern printmsd(); 83 | 84 | extern printmsefile(); 85 | 86 | extern gabort(); 87 | 88 | extern generatepoissontable (); 89 | 90 | extern int poisson (); 91 | 92 | extern int binarysearchcumulative(); 93 | 94 | extern int discrete(); 95 | 96 | extern int samplewithoutreplacement(); 97 | 98 | extern trap(); 99 | 100 | extern getint(); 101 | 102 | extern getintandskip(); 103 | 104 | extern printint (); 105 | 106 | extern double se2(); 107 | 108 | extern printmse2(); 109 | 110 | extern printtail(); 111 | 112 | extern acc2umulate (); 113 | 114 | extern double acc2umulatedmean(); 115 | 116 | extern double acc2umulatedvariance(); 117 | 118 | extern int cointoss(); 119 | 120 | extern printline (); 121 | 122 | extern spaces(); 123 | 124 | extern getrealandskip(); 125 | 126 | extern double calculaterealmean(); 127 | 128 | extern tracestart(); 129 | 130 | extern trace(); 131 | 132 | extern outputrep(); 133 | 134 | extern dummystart(); 135 | 136 | extern dummyinput(); 137 | 138 | extern double normalheight(); 139 | 140 | extern double simpson(); 141 | 142 | extern int odd(); 143 | 144 | extern int solvequadratic(); 145 | 146 | extern skiptoendofline(); 147 | 148 | extern double aitken(); 149 | 150 | extern int factorial(); 151 | 152 | extern double logfactorial(); 153 | 154 | extern double doublefactorial(); 155 | 156 | extern double gammaht(); 157 | 158 | extern double gammaalpha(); 159 | 160 | extern double numericalinteg(); 161 | 162 | extern FILE *openforread(char *str); 163 | 164 | extern double gamdev(int ia, double epsilon); 165 | 166 | extern double series_gamma(double beta); 167 | 168 | extern quadratic_regression(double n, double sumx, double sumx2, double sumy, 169 | double sumx3, double sumxy, double sumx4, double sumx2y, 170 | double *b1, double *b2, double *b3); 171 | 172 | extern int findtext(char *s, FILE *inptr); 173 | 174 | 175 | /* ***************************************************************************************** */ 176 | /* ***************************************************************************************** */ 177 | /* ****************************** nrutil.h ************************************************* */ 178 | /* ***************************************************************************************** */ 179 | /* ***************************************************************************************** */ 180 | 181 | 182 | #ifndef _NR_UTILS_H_ 183 | #define _NR_UTILS_H_ 184 | 185 | static float sqrarg; 186 | #define SQR(a) ((sqrarg=(a))==0.0?0.0:sqrarg*sqrarg) 187 | static double dsqrarg; 188 | #define DSQR(a) ((dsqrarg=(a))==0.0?0.0:dsqrarg*dsqrarg) 189 | static double dmaxarg1,dmaxarg2; 190 | #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1)>(dmaxarg2)?(dmaxarg1):(dmaxarg2)) 191 | static double dminarg1,dminarg2; 192 | #define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1)>(dminarg2)?(dminarg1):(dminarg2)) 193 | static float maxarg1,maxarg2; 194 | #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)?(maxarg1):(maxarg2)) 195 | static float minarg1,minarg2; 196 | #define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1)>(minarg2)?(minarg1):(minarg2)) 197 | static long lmaxarg1,lmaxarg2; 198 | #define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1)>(lmaxarg2)?(lmaxarg1):(lmaxarg2)) 199 | static long lminarg1,lminarg2; 200 | #define LMIN(a,b) (lminarg1=(a),lminarg2=(b),(lminarg1)>(lminarg2)?(lminarg1):(lminarg2)) 201 | static int imaxarg1,imaxarg2; 202 | #define IMAX(a,b) (imaxarg1=(a),imaxarg2=(b),(imaxarg1)>(imaxarg2)?(imaxarg1):(imaxarg2)) 203 | static int iminarg1,iminarg2; 204 | #define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1)>(iminarg2)?(iminarg1):(iminarg2)) 205 | 206 | #define SIGN(a,b) ((b)>0.0?fabs(a):-fabs(a)) 207 | void nrerror(char error_text[]); 208 | float *vector(long nl,long nh); 209 | int *ivector(long nl,long nh); 210 | unsigned char *cvector(long nl,long nh); 211 | unsigned long *lvector(long nl,long nh); 212 | double *dvector(long nl,long nh); 213 | float **matrix(long nrl,long nrh,long ncl,long nch); 214 | double **dmatrix(long nrl,long nrh,long ncl,long nch); 215 | int **imatrix(long nrl,long nrh,long ncl,long nch); 216 | float **submatrix(float **a,long oldrl,long oldrh,long oldcl,long oldch,long newrl,long newcl); 217 | float **convert_matrix(float **a,long nrl,long nrh,long ncl,long nch); 218 | float **f3tensor(long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 219 | void free_vector(float *v,long nl, long nh); 220 | void free_ivector(int *v,long nl, long nh); 221 | void free_cvector(unsigned char *v,long nl, long nh); 222 | void free_lvector(unsigned long *v,long nl, long nh); 223 | void free_dvector(double *v,long nl, long nh); 224 | void free_matrix(float **m,long nrl,long nrh,long ncl,long nch); 225 | void free_dmatrix(double **m,long nrl,long nrh,long ncl,long nch); 226 | void free_imatrix(int **m,long nrl,long nrh,long ncl,long nch); 227 | void free_submatrix(float **b,long nrl,long nrh,long ncl,long nch); 228 | void free_convert_matrix(float **b,long nrl,long nrh,long ncl,long nch); 229 | void free_f3tensor(float **t,long nrl,long nrh,long ncl,long nch,long ndl, long ndh); 230 | 231 | #endif 232 | 233 | -------------------------------------------------------------------------------- /CODES_MACOSX/libhdr: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #define true 1 7 | #define false 0 8 | #define infinity 999999 9 | #define pi 3.1415927 10 | #define maxranges 5 /* for numerical integration */ 11 | #define maxsimpsonpoints 1025 /* change genlib.c if these changed */ 12 | 13 | struct acc 14 | { 15 | int n; 16 | double sum; 17 | double sumsq; 18 | int n2; 19 | double sum2; 20 | double sumsq2; 21 | }; 22 | 23 | struct covacc 24 | { 25 | int n; 26 | double sumxy, sumx, sumy, sumx2, sumy2; 27 | }; 28 | 29 | 30 | extern long seed; 31 | 32 | extern long rseed; 33 | 34 | extern int tracelevel; 35 | 36 | extern int inputcounter; 37 | 38 | extern initcovacc(); 39 | 40 | extern covaccum(); 41 | 42 | extern double covariance(); 43 | 44 | extern double correlation(); 45 | 46 | extern float ranqd2(); 47 | 48 | extern double uniform(); 49 | 50 | extern initacc(struct acc *a); 51 | 52 | extern accum(struct acc *a, double x); 53 | 54 | extern double accmean(struct acc *a); 55 | 56 | extern double accsum(struct acc *a); 57 | 58 | extern double variance(struct acc *a); 59 | 60 | extern getseed(); 61 | 62 | extern getseedquick(); 63 | 64 | extern writeseed(); 65 | 66 | extern double normal(); 67 | 68 | extern quicknormal(); 69 | 70 | extern double doublegamma(); 71 | 72 | extern wishart(); 73 | 74 | extern bivnormal(); 75 | 76 | extern cubenormal(); 77 | 78 | extern double se(); 79 | 80 | extern printmse(); 81 | 82 | extern printmsd(); 83 | 84 | extern printmsefile(); 85 | 86 | extern gabort(); 87 | 88 | extern generatepoissontable (); 89 | 90 | extern int poisson (); 91 | 92 | extern int binarysearchcumulative(); 93 | 94 | extern int discrete(); 95 | 96 | extern int samplewithoutreplacement(); 97 | 98 | extern trap(); 99 | 100 | extern getint(); 101 | 102 | extern getintandskip(); 103 | 104 | extern printint (); 105 | 106 | extern double se2(); 107 | 108 | extern printmse2(); 109 | 110 | extern printtail(); 111 | 112 | extern acc2umulate (); 113 | 114 | extern double acc2umulatedmean(); 115 | 116 | extern double acc2umulatedvariance(); 117 | 118 | extern int cointoss(); 119 | 120 | extern printline (); 121 | 122 | extern spaces(); 123 | 124 | extern getrealandskip(); 125 | 126 | extern double calculaterealmean(); 127 | 128 | extern tracestart(); 129 | 130 | extern trace(); 131 | 132 | extern outputrep(); 133 | 134 | extern dummystart(); 135 | 136 | extern dummyinput(); 137 | 138 | extern double normalheight(); 139 | 140 | extern double simpson(); 141 | 142 | extern int odd(); 143 | 144 | extern int solvequadratic(); 145 | 146 | extern skiptoendofline(); 147 | 148 | extern double aitken(); 149 | 150 | extern int factorial(); 151 | 152 | extern double logfactorial(); 153 | 154 | extern double doublefactorial(); 155 | 156 | extern double gammaht(); 157 | 158 | extern double gammaalpha(); 159 | 160 | extern double numericalinteg(); 161 | 162 | extern FILE *openforread(char *str); 163 | 164 | extern double gamdev(int ia, double epsilon); 165 | 166 | extern double series_gamma(double beta); 167 | 168 | extern quadratic_regression(double n, double sumx, double sumx2, double sumy, 169 | double sumx3, double sumxy, double sumx4, double sumx2y, 170 | double *b1, double *b2, double *b3); 171 | 172 | extern int findtext(char *s, FILE *inptr); 173 | 174 | 175 | /* ***************************************************************************************** */ 176 | /* ***************************************************************************************** */ 177 | /* ****************************** nrutil.h ************************************************* */ 178 | /* ***************************************************************************************** */ 179 | /* ***************************************************************************************** */ 180 | 181 | 182 | #ifndef _NR_UTILS_H_ 183 | #define _NR_UTILS_H_ 184 | 185 | static float sqrarg; 186 | #define SQR(a) ((sqrarg=(a))==0.0?0.0:sqrarg*sqrarg) 187 | static double dsqrarg; 188 | #define DSQR(a) ((dsqrarg=(a))==0.0?0.0:dsqrarg*dsqrarg) 189 | static double dmaxarg1,dmaxarg2; 190 | #define DMAX(a,b) (dmaxarg1=(a),dmaxarg2=(b),(dmaxarg1)>(dmaxarg2)?(dmaxarg1):(dmaxarg2)) 191 | static double dminarg1,dminarg2; 192 | #define DMIN(a,b) (dminarg1=(a),dminarg2=(b),(dminarg1)>(dminarg2)?(dminarg1):(dminarg2)) 193 | static float maxarg1,maxarg2; 194 | #define FMAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1)>(maxarg2)?(maxarg1):(maxarg2)) 195 | static float minarg1,minarg2; 196 | #define FMIN(a,b) (minarg1=(a),minarg2=(b),(minarg1)>(minarg2)?(minarg1):(minarg2)) 197 | static long lmaxarg1,lmaxarg2; 198 | #define LMAX(a,b) (lmaxarg1=(a),lmaxarg2=(b),(lmaxarg1)>(lmaxarg2)?(lmaxarg1):(lmaxarg2)) 199 | static long lminarg1,lminarg2; 200 | #define LMIN(a,b) (lminarg1=(a),lminarg2=(b),(lminarg1)>(lminarg2)?(lminarg1):(lminarg2)) 201 | static int imaxarg1,imaxarg2; 202 | #define IMAX(a,b) (imaxarg1=(a),imaxarg2=(b),(imaxarg1)>(imaxarg2)?(imaxarg1):(imaxarg2)) 203 | static int iminarg1,iminarg2; 204 | #define IMIN(a,b) (iminarg1=(a),iminarg2=(b),(iminarg1)>(iminarg2)?(iminarg1):(iminarg2)) 205 | 206 | #define SIGN(a,b) ((b)>0.0?fabs(a):-fabs(a)) 207 | void nrerror(char error_text[]); 208 | float *vector(long nl,long nh); 209 | int *ivector(long nl,long nh); 210 | unsigned char *cvector(long nl,long nh); 211 | unsigned long *lvector(long nl,long nh); 212 | double *dvector(long nl,long nh); 213 | float **matrix(long nrl,long nrh,long ncl,long nch); 214 | double **dmatrix(long nrl,long nrh,long ncl,long nch); 215 | int **imatrix(long nrl,long nrh,long ncl,long nch); 216 | float **submatrix(float **a,long oldrl,long oldrh,long oldcl,long oldch,long newrl,long newcl); 217 | float **convert_matrix(float **a,long nrl,long nrh,long ncl,long nch); 218 | float **f3tensor(long nrl,long nrh,long ncl,long nch,long ndl,long ndh); 219 | void free_vector(float *v,long nl, long nh); 220 | void free_ivector(int *v,long nl, long nh); 221 | void free_cvector(unsigned char *v,long nl, long nh); 222 | void free_lvector(unsigned long *v,long nl, long nh); 223 | void free_dvector(double *v,long nl, long nh); 224 | void free_matrix(float **m,long nrl,long nrh,long ncl,long nch); 225 | void free_dmatrix(double **m,long nrl,long nrh,long ncl,long nch); 226 | void free_imatrix(int **m,long nrl,long nrh,long ncl,long nch); 227 | void free_submatrix(float **b,long nrl,long nrh,long ncl,long nch); 228 | void free_convert_matrix(float **b,long nrl,long nrh,long ncl,long nch); 229 | void free_f3tensor(float **t,long nrl,long nrh,long ncl,long nch,long ndl, long ndh); 230 | 231 | #endif 232 | 233 | -------------------------------------------------------------------------------- /EXAMPLE/Output_Ne_example: -------------------------------------------------------------------------------- 1 | Ne averages over 40 independent estimates. 2 | Generation Geometric_mean 3 | 1 87.4605 4 | 2 87.4605 5 | 3 87.4605 6 | 4 87.4605 7 | 5 110.202 8 | 6 112.501 9 | 7 112.794 10 | 8 112.845 11 | 9 105.702 12 | 10 102.869 13 | 11 101.179 14 | 12 100.116 15 | 13 92.6519 16 | 14 88.4091 17 | 15 85.6749 18 | 16 84.5377 19 | 17 81.2541 20 | 18 80.7918 21 | 19 80.1952 22 | 20 79.8685 23 | 21 79.9551 24 | 22 83.7367 25 | 23 84.9353 26 | 24 87.1043 27 | 25 95.6229 28 | 26 105.958 29 | 27 119.513 30 | 28 123.212 31 | 29 127.032 32 | 30 131.827 33 | 31 136.239 34 | 32 138.11 35 | 33 142.755 36 | 34 147.427 37 | 35 151.6 38 | 36 157.763 39 | 37 162.121 40 | 38 164.59 41 | 39 172.941 42 | 40 175.476 43 | 41 176.362 44 | 42 180.542 45 | 43 181.37 46 | 44 179.274 47 | 45 177.381 48 | 46 175.134 49 | 47 174.904 50 | 48 172.459 51 | 49 168.328 52 | 50 158.404 53 | 51 151.833 54 | 52 141.044 55 | 53 135.962 56 | 54 133.342 57 | 55 130.848 58 | 56 128.723 59 | 57 126.528 60 | 58 124.577 61 | 59 120.583 62 | 60 118.532 63 | 61 117.025 64 | 62 116.268 65 | 63 114.865 66 | 64 112.623 67 | 65 109.188 68 | 66 103.261 69 | 67 97.2893 70 | 68 92.9823 71 | 69 88.2946 72 | 70 86.8622 73 | 71 82.9882 74 | 72 81.6187 75 | 73 80.3757 76 | 74 78.2326 77 | 75 75.6129 78 | 76 73.3953 79 | 77 70.2881 80 | 78 68.9701 81 | 79 67.661 82 | 80 67.3169 83 | 81 66.4346 84 | 82 64.5465 85 | 83 65.0476 86 | 84 64.867 87 | 85 64.4446 88 | 86 62.5327 89 | 87 60.9513 90 | 88 58.272 91 | 89 57.3413 92 | 90 55.0901 93 | 91 54.6123 94 | 92 53.1215 95 | 93 49.9807 96 | 94 46.8037 97 | 95 46.3342 98 | 96 46.1406 99 | 97 45.6798 100 | 98 45.1372 101 | 99 45.055 102 | 100 45.6994 103 | 101 46.0408 104 | 102 46.6718 105 | 103 47.2798 106 | 104 47.7314 107 | 105 48.4728 108 | 106 49.4047 109 | 107 50.6651 110 | 108 51.2702 111 | 109 50.1788 112 | 110 49.8812 113 | 111 50.4254 114 | 112 50.0776 115 | 113 49.7057 116 | 114 50.542 117 | 115 51.4866 118 | 116 52.8111 119 | 117 53.7297 120 | 118 53.1173 121 | 119 53.1519 122 | 120 53.7709 123 | 121 54.5457 124 | 122 55.8591 125 | 123 56.3288 126 | 124 57.1898 127 | 125 57.9239 128 | 126 58.9361 129 | 127 61.0233 130 | 128 62.6483 131 | 129 64.0246 132 | 130 64.9301 133 | 131 66.3435 134 | 132 67.0383 135 | 133 67.2036 136 | 134 66.9097 137 | 135 66.9701 138 | 136 67.3996 139 | 137 67.3956 140 | 138 68.2164 141 | 139 68.609 142 | 140 68.8425 143 | 141 69.8855 144 | 142 69.939 145 | 143 70.5549 146 | 144 71.3488 147 | 145 74.0631 148 | 146 74.0925 149 | 147 74.005 150 | 148 73.9302 151 | 149 73.6811 152 | 150 74.4374 153 | 151 74.6314 154 | 152 75.3413 155 | 153 74.9482 156 | 154 75.249 157 | 155 75.8721 158 | 156 76.0701 159 | 157 76.327 160 | 158 77.1106 161 | 159 77.8144 162 | 160 78.423 163 | 161 78.6745 164 | 162 78.4518 165 | 163 79.0972 166 | 164 79.2472 167 | 165 79.4598 168 | 166 80.0813 169 | 167 82.5315 170 | 168 82.5059 171 | 169 83.3056 172 | 170 83.2428 173 | 171 83.1574 174 | 172 83.2166 175 | 173 83.7359 176 | 174 84.2384 177 | 175 86.6615 178 | 176 88.488 179 | 177 89.3076 180 | 178 90.1023 181 | 179 90.5911 182 | 180 90.8223 183 | 181 90.5664 184 | 182 90.8774 185 | 183 92.7407 186 | 184 96.384 187 | 185 103.846 188 | 186 105.116 189 | 187 107.031 190 | 188 109.736 191 | 189 113.093 192 | 190 114.933 193 | 191 115.229 194 | 192 117.484 195 | 193 118.327 196 | 194 120.175 197 | 195 120.722 198 | 196 122.804 199 | 197 123.138 200 | 198 126.657 201 | 199 128.491 202 | 200 128.971 203 | 201 130.347 204 | 202 130.036 205 | 203 129.881 206 | 204 129.909 207 | 205 131.694 208 | 206 133.878 209 | 207 134.387 210 | 208 135.317 211 | 209 136.307 212 | 210 135.695 213 | 211 135.638 214 | 212 135.135 215 | 213 134.601 216 | 214 134.675 217 | 215 135.85 218 | 216 136.955 219 | 217 136.843 220 | 218 137.532 221 | 219 137.794 222 | 220 137.299 223 | 221 135.939 224 | 222 134.604 225 | 223 133.915 226 | 224 133.306 227 | 225 132.911 228 | 226 132.894 229 | 227 133.305 230 | 228 134.731 231 | 229 136.641 232 | 230 136.556 233 | 231 136.362 234 | 232 135.778 235 | 233 135.68 236 | 234 135.579 237 | 235 135.024 238 | 236 134.158 239 | 237 133.869 240 | 238 133.097 241 | 239 132.797 242 | 240 131.634 243 | 241 130.878 244 | 242 129.429 245 | 243 129.057 246 | 244 128.743 247 | 245 128.67 248 | 246 129.603 249 | 247 130.374 250 | 248 130.706 251 | 249 129.953 252 | 250 128.875 253 | 251 128.448 254 | 252 128.71 255 | 253 128.88 256 | 254 128.867 257 | 255 129.039 258 | 256 129.032 259 | 257 129.41 260 | 258 129.489 261 | 259 129.444 262 | 260 130.215 263 | 261 131.154 264 | 262 132.008 265 | 263 132.77 266 | 264 133.399 267 | 265 133.641 268 | 266 134.396 269 | 267 134.632 270 | 268 135.248 271 | 269 135.23 272 | 270 135.196 273 | 271 135.092 274 | 272 135.027 275 | 273 135.281 276 | 274 135.398 277 | 275 135.789 278 | 276 136.023 279 | 277 136.116 280 | 278 135.95 281 | 279 135.843 282 | 280 135.564 283 | 281 135.564 284 | 282 135.38 285 | 283 134.815 286 | 284 134.837 287 | 285 134.748 288 | 286 134.667 289 | 287 134.732 290 | 288 134.837 291 | 289 134.85 292 | 290 134.92 293 | 291 135.098 294 | 292 135.003 295 | 293 135.048 296 | 294 135.048 297 | 295 135.048 298 | 296 135.048 299 | 297 135.048 300 | 298 135.16 301 | 299 134.937 302 | 300 134.925 303 | 301 134.211 304 | 302 133.998 305 | 303 133.761 306 | 304 136.31 307 | 305 137.699 308 | 306 139.097 309 | 307 141.916 310 | 308 146.071 311 | 309 146.042 312 | 310 147.284 313 | 311 147.377 314 | 312 146.806 315 | 313 146.672 316 | 314 146.492 317 | 315 146.487 318 | 316 146.411 319 | 317 146.436 320 | 318 146.542 321 | 319 146.616 322 | 320 146.663 323 | 321 146.426 324 | 322 145.288 325 | 323 144.339 326 | 324 143.212 327 | 325 142.705 328 | 326 142.363 329 | 327 141.474 330 | 328 141.13 331 | 329 141.247 332 | 330 141.882 333 | 331 142.286 334 | 332 142.324 335 | 333 142.328 336 | 334 142.179 337 | 335 141.927 338 | 336 141.794 339 | 337 141.326 340 | 338 140.222 341 | 339 139.28 342 | 340 138.75 343 | 341 138.92 344 | 342 137.912 345 | 343 137.647 346 | 344 137.168 347 | 345 137.675 348 | 346 138.19 349 | 347 138.476 350 | 348 137.978 351 | 349 137.571 352 | 350 137.298 353 | 351 137.076 354 | 352 137.055 355 | 353 135.862 356 | 354 135.221 357 | 355 134.822 358 | 356 133.845 359 | 357 133.066 360 | 358 132.427 361 | 359 130.973 362 | 360 130.328 363 | 361 130.289 364 | 362 129.561 365 | 363 128.859 366 | 364 128.524 367 | 365 127.642 368 | 366 127.423 369 | 367 127.148 370 | 368 128.463 371 | 369 128.12 372 | 370 128.305 373 | 371 128.055 374 | 372 127.934 375 | 373 127.946 376 | 374 127.503 377 | 375 127.303 378 | 376 126.728 379 | 377 126.276 380 | 378 125.733 381 | 379 125.439 382 | 380 125.504 383 | 381 125.625 384 | 382 125.48 385 | 383 125.528 386 | 384 125.504 387 | 385 125.717 388 | 386 125.943 389 | 387 126.144 390 | 388 126.251 391 | 389 126.386 392 | 390 126.496 393 | 391 126.654 394 | 392 126.83 395 | 393 126.804 396 | 394 126.945 397 | 395 127.052 398 | 396 127.419 399 | 397 127.859 400 | 398 127.854 401 | 399 128.141 402 | 400 128.07 403 | 401 127.04 404 | 402 127.076 405 | 403 126.757 406 | 404 126.634 407 | 405 126.568 408 | 406 126.452 409 | 407 126.293 410 | 408 126.058 411 | 409 125.699 412 | 410 125.036 413 | 411 124.888 414 | 412 124.629 415 | 413 124.847 416 | 414 124.817 417 | 415 124.765 418 | 416 125.066 419 | 417 126.395 420 | 418 126.791 421 | 419 127.165 422 | 420 127.528 423 | 421 127.687 424 | 422 127.499 425 | 423 127.212 426 | 424 127.053 427 | 425 126.651 428 | 426 126.671 429 | 427 126.671 430 | 428 126.356 431 | 429 126.112 432 | 430 125.559 433 | 431 125.083 434 | 432 124.316 435 | 433 122.922 436 | 434 121.276 437 | 435 120.868 438 | 436 119.309 439 | 437 117.416 440 | 438 114.21 441 | 439 113.26 442 | 440 113.26 443 | 441 112.292 444 | 442 112.344 445 | 443 111.873 446 | 444 111.832 447 | 445 111.536 448 | 446 111.647 449 | 447 111.664 450 | 448 111.917 451 | 449 111.959 452 | 450 112.246 453 | 451 112.494 454 | 452 112.834 455 | 453 112.889 456 | 454 112.884 457 | 455 112.897 458 | 456 112.814 459 | 457 112.9 460 | 458 113.133 461 | 459 113.327 462 | 460 113.489 463 | 461 113.713 464 | 462 113.545 465 | 463 113.434 466 | 464 113.085 467 | 465 112.933 468 | 466 113.131 469 | 467 113.149 470 | 468 113.159 471 | 469 112.793 472 | 470 112.647 473 | 471 112.207 474 | 472 112.178 475 | 473 112.108 476 | 474 111.966 477 | 475 111.698 478 | 476 111.656 479 | 477 111.536 480 | 478 111.397 481 | 479 111.397 482 | 480 110.876 483 | 481 110.357 484 | 482 110.208 485 | 483 110.208 486 | 484 110.208 487 | 485 110.208 488 | 486 110.208 489 | 487 110.208 490 | 488 110.208 491 | 489 110.208 492 | 490 110.208 493 | 491 110.208 494 | 492 110.208 495 | 493 110.208 496 | 494 110.208 497 | 495 110.208 498 | 496 110.208 499 | 497 110.208 500 | 498 110.208 501 | 499 110.208 502 | 500 110.208 503 | 501 110.208 504 | 502 110.208 505 | 503 110.208 506 | 504 110.208 507 | 505 110.208 508 | 506 110.208 509 | 507 110.208 510 | 508 110.208 511 | 509 110.208 512 | 510 110.208 513 | 511 110.208 514 | 512 110.208 515 | 513 110.208 516 | 514 110.208 517 | 515 110.208 518 | 516 110.208 519 | 517 110.208 520 | 518 110.208 521 | 519 110.208 522 | 520 110.208 523 | 521 110.208 524 | 522 110.208 525 | 523 110.208 526 | 524 110.208 527 | 525 110.208 528 | 526 110.208 529 | 527 110.208 530 | 528 110.208 531 | 529 110.208 532 | 530 110.208 533 | 531 110.208 534 | 532 110.208 535 | 533 110.208 536 | 534 110.208 537 | 535 110.208 538 | 536 110.208 539 | 537 110.208 540 | 538 110.208 541 | 539 110.208 542 | 540 110.208 543 | 541 110.208 544 | 542 110.208 545 | 543 110.208 546 | 544 110.208 547 | 545 110.208 548 | 546 110.208 549 | 547 110.208 550 | 548 110.208 551 | 549 110.208 552 | 550 110.208 553 | 551 110.208 554 | 552 110.208 555 | 553 110.208 556 | 554 110.208 557 | 555 110.208 558 | 556 110.208 559 | 557 110.208 560 | 558 110.208 561 | 559 110.208 562 | 560 110.208 563 | 561 110.208 564 | 562 110.208 565 | 563 110.208 566 | 564 110.208 567 | 565 110.208 568 | 566 110.208 569 | 567 110.208 570 | 568 110.208 571 | 569 110.208 572 | 570 110.208 573 | 571 110.208 574 | 572 110.208 575 | 573 110.208 576 | 574 110.208 577 | 575 110.208 578 | 576 110.208 579 | 577 110.208 580 | 578 110.208 581 | 579 110.208 582 | 580 110.208 583 | 581 110.208 584 | 582 110.208 585 | 583 110.208 586 | 584 110.208 587 | 585 110.208 588 | 586 110.208 589 | 587 110.208 590 | 588 110.208 591 | 589 110.208 592 | 590 110.208 593 | 591 110.208 594 | 592 110.208 595 | 593 110.208 596 | 594 110.208 597 | 595 110.208 598 | 596 110.208 599 | 597 110.208 600 | 598 110.208 601 | 599 110.208 602 | 600 110.208 603 | 601 110.208 604 | 602 110.208 605 | 603 110.208 606 | 604 110.208 607 | 605 110.208 608 | 606 110.208 609 | 607 110.208 610 | 608 110.208 611 | 609 110.208 612 | 610 110.208 613 | 611 110.208 614 | 612 110.208 615 | 613 110.208 616 | 614 110.208 617 | 615 110.208 618 | 616 110.208 619 | 617 110.208 620 | 618 110.208 621 | 619 110.208 622 | 620 110.208 623 | 621 110.208 624 | 622 110.208 625 | 623 110.208 626 | 624 110.208 627 | 625 110.208 628 | 626 110.208 629 | 627 110.208 630 | 628 110.208 631 | 629 110.208 632 | 630 110.208 633 | 631 110.208 634 | 632 110.208 635 | 633 110.208 636 | 634 110.208 637 | 635 110.208 638 | 636 110.208 639 | 637 110.208 640 | 638 110.208 641 | 639 110.208 642 | 640 110.208 643 | 641 110.208 644 | 642 110.208 645 | 643 110.208 646 | 644 110.208 647 | 645 110.208 648 | 646 110.208 649 | 647 110.208 650 | 648 110.208 651 | 649 110.208 652 | 650 110.208 653 | 651 110.208 654 | 652 110.208 655 | 653 110.208 656 | 654 110.208 657 | 655 110.208 658 | 656 110.208 659 | 657 110.208 660 | 658 110.208 661 | 659 110.208 662 | 660 110.208 663 | 661 110.208 664 | 662 110.208 665 | 663 110.208 666 | 664 110.208 667 | 665 110.208 668 | 666 110.208 669 | 667 110.208 670 | 668 110.208 671 | 669 110.208 672 | 670 110.208 673 | 671 110.208 674 | 672 110.208 675 | 673 110.208 676 | 674 110.208 677 | 675 110.208 678 | 676 111.566 679 | -------------------------------------------------------------------------------- /EXAMPLE/OUTPUT_example: -------------------------------------------------------------------------------- 1 | TOTAL NUMBER OF SNPs 2 | 73240 3 | 4 | 5 | HARDY-WEINBERG DEVIATION 6 | -0.013669 Hardy-Weinberg deviation (sample) 7 | 0.011976 Hardy-Weinberg deviation (population) 8 | 9 | 10 | CHROMOSOME 1 11 | NIND(real sample)=20 12 | NSNP=10239 13 | NSNP_calculations=7442 14 | NSNP_+2alleles=0 15 | NSNP_zeroes=0 16 | NSNP_monomorphic=2797 17 | NIND_corrected=20.000000 18 | freq_MAF=0.025000 19 | F_dev_HW (sample)=-0.020159 20 | F_dev_HW (pop)=0.005485 21 | Genetic distances available in map file 22 | 23 | CHROMOSOME 2 24 | NIND(real sample)=20 25 | NSNP=9351 26 | NSNP_calculations=6907 27 | NSNP_+2alleles=0 28 | NSNP_zeroes=0 29 | NSNP_monomorphic=2444 30 | NIND_corrected=20.000000 31 | freq_MAF=0.025000 32 | F_dev_HW (sample)=0.016697 33 | F_dev_HW (pop)=0.042320 34 | Genetic distances available in map file 35 | 36 | CHROMOSOME 3 37 | NIND(real sample)=20 38 | NSNP=9377 39 | NSNP_calculations=6915 40 | NSNP_+2alleles=0 41 | NSNP_zeroes=0 42 | NSNP_monomorphic=2462 43 | NIND_corrected=20.000000 44 | freq_MAF=0.025000 45 | F_dev_HW (sample)=0.047199 46 | F_dev_HW (pop)=0.072751 47 | Genetic distances available in map file 48 | 49 | CHROMOSOME 4 50 | NIND(real sample)=20 51 | NSNP=10811 52 | NSNP_calculations=7797 53 | NSNP_+2alleles=0 54 | NSNP_zeroes=0 55 | NSNP_monomorphic=3014 56 | NIND_corrected=20.000000 57 | freq_MAF=0.025000 58 | F_dev_HW (sample)=0.014442 59 | F_dev_HW (pop)=0.040068 60 | Genetic distances available in map file 61 | 62 | CHROMOSOME 5 63 | NIND(real sample)=20 64 | NSNP=10179 65 | NSNP_calculations=7446 66 | NSNP_+2alleles=0 67 | NSNP_zeroes=0 68 | NSNP_monomorphic=2733 69 | NIND_corrected=20.000000 70 | freq_MAF=0.025000 71 | F_dev_HW (sample)=0.055166 72 | F_dev_HW (pop)=0.080693 73 | Genetic distances available in map file 74 | 75 | CHROMOSOME 6 76 | NIND(real sample)=20 77 | NSNP=11697 78 | NSNP_calculations=8688 79 | NSNP_+2alleles=0 80 | NSNP_zeroes=0 81 | NSNP_monomorphic=3009 82 | NIND_corrected=20.000000 83 | freq_MAF=0.025000 84 | F_dev_HW (sample)=-0.041861 85 | F_dev_HW (pop)=-0.016237 86 | Genetic distances available in map file 87 | 88 | CHROMOSOME 7 89 | NIND(real sample)=20 90 | NSNP=9565 91 | NSNP_calculations=7070 92 | NSNP_+2alleles=0 93 | NSNP_zeroes=0 94 | NSNP_monomorphic=2495 95 | NIND_corrected=20.000000 96 | freq_MAF=0.025000 97 | F_dev_HW (sample)=-0.020218 98 | F_dev_HW (pop)=0.005426 99 | Genetic distances available in map file 100 | 101 | CHROMOSOME 8 102 | NIND(real sample)=20 103 | NSNP=9427 104 | NSNP_calculations=6676 105 | NSNP_+2alleles=0 106 | NSNP_zeroes=0 107 | NSNP_monomorphic=2751 108 | NIND_corrected=20.000000 109 | freq_MAF=0.025000 110 | F_dev_HW (sample)=-0.068305 111 | F_dev_HW (pop)=-0.042739 112 | Genetic distances available in map file 113 | 114 | CHROMOSOME 9 115 | NIND(real sample)=20 116 | NSNP=10185 117 | NSNP_calculations=7513 118 | NSNP_+2alleles=0 119 | NSNP_zeroes=0 120 | NSNP_monomorphic=2672 121 | NIND_corrected=20.000000 122 | freq_MAF=0.025000 123 | F_dev_HW (sample)=-0.064737 124 | F_dev_HW (pop)=-0.039161 125 | Genetic distances available in map file 126 | 127 | CHROMOSOME 10 128 | NIND(real sample)=20 129 | NSNP=9182 130 | NSNP_calculations=6786 131 | NSNP_+2alleles=0 132 | NSNP_zeroes=0 133 | NSNP_monomorphic=2396 134 | NIND_corrected=20.000000 135 | freq_MAF=0.025000 136 | F_dev_HW (sample)=-0.054112 137 | F_dev_HW (pop)=-0.028510 138 | Genetic distances available in map file 139 | 140 | 141 | 142 | INPUT FOR GONE 143 | 144 | 145 | 2 Phase (0: pseudohaploids; 1: known phase; 2: unknown phase) 146 | 20.000000 sample size (individuals; corrected for zeroes) 147 | -0.013669 Hardy-Weinberg deviation 148 | 48978984 0.148248 0.066297 4 149 | 60071956 0.101803 0.073132 6 150 | 35649335 0.072247 0.078820 8 151 | 22991196 0.055970 0.086197 10 152 | 32140719 0.041013 0.103651 15 153 | 16820876 0.028953 0.121714 20 154 | 10287768 0.022402 0.134635 25 155 | 6919246 0.018281 0.148388 30 156 | 4984760 0.015443 0.160851 35 157 | 3773479 0.013372 0.170688 40 158 | 2946868 0.011791 0.183412 45 159 | 2366374 0.010545 0.194279 50 160 | 1942615 0.009538 0.204093 55 161 | 1622582 0.008707 0.213159 60 162 | 1373661 0.008008 0.222204 65 163 | 1180061 0.007414 0.230125 70 164 | 1026203 0.006902 0.237902 75 165 | 897746 0.006456 0.245454 80 166 | 794912 0.006064 0.251469 85 167 | 708506 0.005717 0.258854 90 168 | 633903 0.005408 0.263060 95 169 | 573119 0.005130 0.269621 100 170 | 518711 0.004880 0.273914 105 171 | 470679 0.004653 0.278559 110 172 | 432320 0.004446 0.283102 115 173 | 396718 0.004257 0.288537 120 174 | 366165 0.004083 0.290390 125 175 | 336613 0.003923 0.295749 130 176 | 311996 0.003774 0.300927 135 177 | 290749 0.003637 0.303977 140 178 | 270090 0.003509 0.307188 145 179 | 252732 0.003390 0.311405 150 180 | 236559 0.003279 0.312596 155 181 | 221991 0.003175 0.318248 160 182 | 209363 0.003077 0.320143 165 183 | 197254 0.002985 0.323019 170 184 | 186084 0.002899 0.324362 175 185 | 174992 0.002817 0.328337 180 186 | 165752 0.002740 0.329465 185 187 | 157502 0.002667 0.334568 190 188 | 150230 0.002598 0.337281 195 189 | 141810 0.002532 0.339437 200 190 | 135275 0.002469 0.338372 205 191 | 128438 0.002410 0.341822 210 192 | 123306 0.002353 0.346607 215 193 | 117910 0.002299 0.346517 220 194 | 112062 0.002247 0.349473 225 195 | 106890 0.002198 0.348564 230 196 | 103431 0.002151 0.351553 235 197 | 99165 0.002105 0.353702 240 198 | 94333 0.002062 0.356377 245 199 | 91208 0.002020 0.358743 250 200 | 87502 0.001980 0.361342 255 201 | 83590 0.001942 0.363782 260 202 | 81068 0.001905 0.361810 265 203 | 78170 0.001869 0.362118 270 204 | 75440 0.001835 0.366607 275 205 | 72582 0.001802 0.363398 280 206 | 69898 0.001770 0.369777 285 207 | 67300 0.001739 0.373233 290 208 | 65087 0.001709 0.369759 295 209 | 62817 0.001681 0.372583 300 210 | 60935 0.001653 0.371254 305 211 | 59227 0.001626 0.371213 310 212 | 57532 0.001600 0.376458 315 213 | 55681 0.001575 0.367475 320 214 | 53482 0.001550 0.379671 325 215 | 52401 0.001527 0.375204 330 216 | 50682 0.001504 0.382424 335 217 | 49105 0.001482 0.383246 340 218 | 48030 0.001460 0.381765 345 219 | 46386 0.001439 0.381787 350 220 | 45364 0.001419 0.382947 355 221 | 43674 0.001399 0.388241 360 222 | 42635 0.001379 0.383189 365 223 | 41796 0.001361 0.390161 370 224 | 40406 0.001342 0.388163 375 225 | 39578 0.001325 0.383321 380 226 | 38315 0.001307 0.387357 385 227 | 37292 0.001290 0.392508 390 228 | 36700 0.001274 0.393649 395 229 | 35019 0.001258 0.391462 400 230 | 34939 0.001242 0.391068 405 231 | 33649 0.001227 0.391583 410 232 | 32924 0.001212 0.397610 415 233 | 32101 0.001198 0.393862 420 234 | 31516 0.001183 0.395323 425 235 | 30779 0.001170 0.389779 430 236 | 30219 0.001156 0.400325 435 237 | 29398 0.001143 0.394182 440 238 | 28408 0.001130 0.400382 445 239 | 28123 0.001117 0.404707 450 240 | 27658 0.001105 0.404551 455 241 | 26785 0.001093 0.400795 460 242 | 26434 0.001081 0.399625 465 243 | 25791 0.001070 0.396659 470 244 | 25097 0.001058 0.403766 475 245 | 24850 0.001047 0.399793 480 246 | 24199 0.001036 0.398970 485 247 | 23935 0.001026 0.412301 490 248 | 23404 0.001015 0.405571 495 249 | 22788 0.001005 0.404617 500 250 | 22232 0.000995 0.403511 505 251 | 21949 0.000985 0.397962 510 252 | 21666 0.000976 0.399731 515 253 | 21073 0.000966 0.399909 520 254 | 20699 0.000957 0.409454 525 255 | 20278 0.000948 0.408084 530 256 | 19744 0.000939 0.401542 535 257 | 19454 0.000930 0.411107 540 258 | 19440 0.000922 0.409193 545 259 | 18792 0.000913 0.406192 550 260 | 18554 0.000905 0.415962 555 261 | 18315 0.000897 0.414537 560 262 | 17831 0.000889 0.412947 565 263 | 17610 0.000881 0.414412 570 264 | 17177 0.000873 0.408349 575 265 | 16897 0.000866 0.414898 580 266 | 16627 0.000858 0.406096 585 267 | 16392 0.000851 0.412025 590 268 | 16044 0.000844 0.415683 595 269 | 15774 0.000837 0.401765 600 270 | 15730 0.000830 0.412859 605 271 | 15119 0.000823 0.413912 610 272 | 14952 0.000816 0.420875 615 273 | 14796 0.000810 0.406083 620 274 | 14583 0.000803 0.405526 625 275 | 14272 0.000797 0.409890 630 276 | 14075 0.000791 0.412287 635 277 | 13851 0.000784 0.438052 640 278 | 13605 0.000778 0.420220 645 279 | 13420 0.000772 0.422403 650 280 | 13346 0.000766 0.430258 655 281 | 13074 0.000760 0.414554 660 282 | 12795 0.000755 0.418221 665 283 | 12763 0.000749 0.420552 670 284 | 12485 0.000744 0.417796 675 285 | 12220 0.000738 0.416546 680 286 | 11926 0.000733 0.413496 685 287 | 11838 0.000727 0.420057 690 288 | 11597 0.000722 0.406748 695 289 | 11546 0.000717 0.420576 700 290 | 11358 0.000712 0.433893 705 291 | 11330 0.000707 0.425637 710 292 | 11082 0.000702 0.415265 715 293 | 11039 0.000697 0.411965 720 294 | 10649 0.000692 0.432120 725 295 | 10802 0.000687 0.424689 730 296 | 10516 0.000683 0.431711 735 297 | 10252 0.000678 0.421537 740 298 | 10240 0.000673 0.430916 745 299 | 10306 0.000669 0.416936 750 300 | 10313 0.000664 0.414517 755 301 | 9942 0.000660 0.431153 760 302 | 9746 0.000656 0.434430 765 303 | 9572 0.000651 0.419760 770 304 | 9400 0.000647 0.448503 775 305 | 9445 0.000643 0.417501 780 306 | 9178 0.000639 0.425018 785 307 | 9147 0.000635 0.418515 790 308 | 9001 0.000631 0.431798 795 309 | 8967 0.000627 0.429605 800 310 | 8847 0.000623 0.426095 805 311 | 8551 0.000619 0.429290 810 312 | 8562 0.000615 0.427597 815 313 | 8484 0.000612 0.433463 820 314 | 8365 0.000608 0.412323 825 315 | 8480 0.000604 0.438191 830 316 | 8115 0.000601 0.422161 835 317 | 8235 0.000597 0.436339 840 318 | 7983 0.000593 0.430697 845 319 | 7776 0.000590 0.428322 850 320 | 7703 0.000587 0.443838 855 321 | 7779 0.000583 0.428097 860 322 | 7705 0.000580 0.434294 865 323 | 7390 0.000576 0.448307 870 324 | 7425 0.000573 0.442750 875 325 | 7453 0.000570 0.441271 880 326 | 7340 0.000567 0.424905 885 327 | 7097 0.000563 0.429861 890 328 | 7101 0.000560 0.434676 895 329 | 7207 0.000557 0.441400 900 330 | 6936 0.000554 0.432095 905 331 | 6960 0.000551 0.426744 910 332 | 6819 0.000548 0.436585 915 333 | 6788 0.000545 0.436205 920 334 | 6743 0.000542 0.450119 925 335 | 6618 0.000539 0.428561 930 336 | 6496 0.000536 0.430026 935 337 | 6420 0.000533 0.433254 940 338 | 6349 0.000531 0.444787 945 339 | 6216 0.000528 0.443763 950 340 | 6313 0.000525 0.441545 955 341 | 6244 0.000522 0.446143 960 342 | 6214 0.000519 0.435103 965 343 | 6047 0.000517 0.429028 970 344 | 5945 0.000514 0.431032 975 345 | 5963 0.000512 0.426602 980 346 | 5898 0.000509 0.430524 985 347 | 5977 0.000506 0.440057 990 348 | 5789 0.000504 0.427452 995 349 | 5692 0.000501 0.448967 1000 350 | 5619 0.000499 0.437830 1005 351 | 5587 0.000496 0.433661 1010 352 | 5704 0.000494 0.438496 1015 353 | 5470 0.000491 0.429653 1020 354 | 5372 0.000489 0.429888 1025 355 | 5338 0.000487 0.444882 1030 356 | 5406 0.000484 0.450460 1035 357 | 5262 0.000482 0.444401 1040 358 | 5343 0.000480 0.418205 1045 359 | 5272 0.000477 0.433650 1050 360 | 5141 0.000475 0.440033 1055 361 | 5049 0.000473 0.447833 1060 362 | 5056 0.000471 0.448040 1065 363 | 5067 0.000468 0.441808 1070 364 | 4955 0.000466 0.434748 1075 365 | 4871 0.000464 0.416110 1080 366 | 4866 0.000462 0.429302 1085 367 | 4716 0.000460 0.427992 1090 368 | 4616 0.000458 0.449279 1095 369 | 4711 0.000456 0.445748 1100 370 | 4701 0.000454 0.448449 1105 371 | 4482 0.000451 0.454514 1110 372 | 4659 0.000449 0.471809 1115 373 | 4546 0.000447 0.447502 1120 374 | 4447 0.000445 0.425236 1125 375 | 4468 0.000443 0.449102 1130 376 | 4464 0.000441 0.449369 1135 377 | 4431 0.000440 0.445776 1140 378 | 4465 0.000438 0.437185 1145 379 | 4297 0.000436 0.430697 1150 380 | 4308 0.000434 0.449106 1155 381 | 4297 0.000432 0.440028 1160 382 | 4205 0.000430 0.445789 1165 383 | 4214 0.000428 0.456759 1170 384 | 4109 0.000426 0.435403 1175 385 | 4030 0.000425 0.445997 1180 386 | 4045 0.000423 0.454014 1185 387 | 3998 0.000421 0.429554 1190 388 | 3883 0.000419 0.442384 1195 389 | 3958 0.000418 0.416789 1200 390 | 3972 0.000416 0.458325 1205 391 | 3979 0.000414 0.441009 1210 392 | 3914 0.000412 0.436539 1215 393 | 3842 0.000411 0.448425 1220 394 | 3783 0.000409 0.429107 1225 395 | 3784 0.000407 0.438627 1230 396 | 3747 0.000406 0.431626 1235 397 | 3767 0.000404 0.454602 1240 398 | 3681 0.000402 0.451208 1245 399 | 3675 0.000401 0.436894 1250 400 | 3628 0.000399 0.437484 1255 401 | 3611 0.000398 0.470097 1260 402 | 3543 0.000396 0.469238 1265 403 | 3588 0.000394 0.441067 1270 404 | 3559 0.000393 0.461229 1275 405 | 3418 0.000391 0.447415 1280 406 | 3406 0.000390 0.439909 1285 407 | 3485 0.000388 0.440964 1290 408 | 3521 0.000387 0.470326 1295 409 | 3355 0.000385 0.427660 1300 410 | 3398 0.000384 0.447644 1305 411 | 3365 0.000382 0.452333 1310 412 | 3338 0.000381 0.431737 1315 413 | 3243 0.000380 0.445184 1320 414 | 3355 0.000378 0.463302 1325 415 | 3211 0.000377 0.450822 1330 416 | 3093 0.000375 0.433910 1335 417 | 3172 0.000374 0.452598 1340 418 | 3129 0.000372 0.437101 1345 419 | 3241 0.000371 0.434661 1350 420 | 3187 0.000370 0.473570 1355 421 | 3078 0.000368 0.453453 1360 422 | 3163 0.000367 0.451360 1365 423 | 3133 0.000366 0.436625 1370 424 | 3025 0.000364 0.441281 1375 425 | 2945 0.000363 0.447010 1380 426 | 2995 0.000362 0.437872 1385 427 | 2859 0.000360 0.446011 1390 428 | 2969 0.000359 0.434141 1395 429 | 2884 0.000358 0.452339 1400 430 | 2913 0.000357 0.460772 1405 431 | 2859 0.000355 0.454855 1410 432 | 2870 0.000354 0.424668 1415 433 | 2966 0.000353 0.426150 1420 434 | 2753 0.000351 0.428853 1425 435 | 2826 0.000350 0.431789 1430 436 | 2859 0.000349 0.429065 1435 437 | 2784 0.000348 0.458951 1440 438 | 2783 0.000347 0.459529 1445 439 | 2753 0.000345 0.473218 1450 440 | 2641 0.000344 0.466428 1455 441 | 2781 0.000343 0.464263 1460 442 | 2644 0.000342 0.459319 1465 443 | 2680 0.000341 0.432264 1470 444 | 2617 0.000340 0.437248 1475 445 | 2662 0.000338 0.451369 1480 446 | 2581 0.000337 0.456045 1485 447 | 2480 0.000336 0.441830 1490 448 | 2552 0.000335 0.457210 1495 449 | 2649 0.000334 0.448406 1500 450 | 2600 0.000333 0.469138 1505 451 | 2491 0.000332 0.465813 1510 452 | 2445 0.000331 0.480333 1515 453 | 2508 0.000329 0.423263 1520 454 | 2522 0.000328 0.436697 1525 455 | 2381 0.000327 0.449317 1530 456 | 2475 0.000326 0.474569 1535 457 | 2420 0.000325 0.459307 1540 458 | 2411 0.000324 0.442819 1545 459 | 2366 0.000323 0.470675 1550 460 | 2335 0.000322 0.445576 1555 461 | 2316 0.000321 0.463246 1560 462 | 2300 0.000320 0.452802 1565 463 | 2284 0.000319 0.453288 1570 464 | 2241 0.000318 0.427041 1575 465 | 2306 0.000317 0.466367 1580 466 | 2255 0.000316 0.431589 1585 467 | 2282 0.000315 0.457454 1590 468 | 2342 0.000314 0.419913 1595 469 | 2273 0.000313 0.415615 1600 470 | 2202 0.000312 0.472654 1605 471 | 2182 0.000311 0.434415 1610 472 | 2246 0.000310 0.425504 1615 473 | 2226 0.000309 0.471802 1620 474 | 2207 0.000308 0.437546 1625 475 | 2112 0.000307 0.458431 1630 476 | 2136 0.000306 0.445957 1635 477 | 2110 0.000305 0.461624 1640 478 | 2139 0.000304 0.449917 1645 479 | 2157 0.000303 0.444068 1650 480 | 2074 0.000303 0.445612 1655 481 | 2062 0.000302 0.447354 1660 482 | 1996 0.000301 0.452610 1665 483 | 1996 0.000300 0.456683 1670 484 | 2098 0.000299 0.452293 1675 485 | 1975 0.000298 0.457334 1680 486 | 2079 0.000297 0.439905 1685 487 | 1942 0.000296 0.450283 1690 488 | 2003 0.000295 0.424501 1695 489 | 2010 0.000295 0.454752 1700 490 | 1966 0.000294 0.430874 1705 491 | 1915 0.000293 0.435455 1710 492 | 1951 0.000292 0.457814 1715 493 | 1871 0.000291 0.433174 1720 494 | 1975 0.000290 0.458401 1725 495 | 1920 0.000289 0.466729 1730 496 | 1954 0.000289 0.448779 1735 497 | 1903 0.000288 0.429794 1740 498 | 1845 0.000287 0.416023 1745 499 | 1895 0.000286 0.458538 1750 500 | 1799 0.000285 0.445146 1755 501 | 1924 0.000285 0.479679 1760 502 | 1849 0.000284 0.458334 1765 503 | 1778 0.000283 0.419548 1770 504 | 1831 0.000282 0.451717 1775 505 | 1804 0.000281 0.459999 1780 506 | 1812 0.000281 0.442050 1785 507 | 1809 0.000280 0.462513 1790 508 | 1735 0.000279 0.450058 1795 509 | 1763 0.000278 0.453491 1800 510 | 1759 0.000277 0.452160 1805 511 | 1732 0.000277 0.461569 1810 512 | 1724 0.000276 0.460933 1815 513 | 1763 0.000275 0.444397 1820 514 | 1748 0.000274 0.463637 1825 515 | 1763 0.000274 0.456585 1830 516 | 1697 0.000273 0.459552 1835 517 | 1634 0.000272 0.430458 1840 518 | 1680 0.000271 0.449268 1845 519 | 1699 0.000271 0.431236 1850 520 | 1647 0.000270 0.440665 1855 521 | 1649 0.000269 0.462460 1860 522 | 1631 0.000268 0.419932 1865 523 | 1562 0.000268 0.445073 1870 524 | 1661 0.000267 0.455693 1875 525 | 1677 0.000266 0.468114 1880 526 | 1549 0.000266 0.478986 1885 527 | 1667 0.000265 0.427933 1890 528 | 1527 0.000264 0.440410 1895 529 | 1663 0.000264 0.485098 1900 530 | 1658 0.000263 0.451825 1905 531 | 1609 0.000262 0.465330 1910 532 | 1536 0.000261 0.433260 1915 533 | 1508 0.000261 0.476862 1920 534 | 1568 0.000260 0.477580 1925 535 | 1630 0.000259 0.434490 1930 536 | 1498 0.000259 0.456708 1935 537 | 1616 0.000258 0.418090 1940 538 | 1480 0.000257 0.448457 1945 539 | 1559 0.000257 0.433473 1950 540 | 1522 0.000256 0.472437 1955 541 | 1511 0.000255 0.438775 1960 542 | 1474 0.000255 0.435856 1965 543 | 1458 0.000254 0.437269 1970 544 | 1497 0.000253 0.431380 1975 545 | 1461 0.000253 0.469789 1980 546 | 1473 0.000252 0.434803 1985 547 | -------------------------------------------------------------------------------- /CODES_MACOSX/LD_SNP_REAL3.c: -------------------------------------------------------------------------------- 1 | 2 | // LD_SNP_REAL3.c (LD estimates from data.ped, with and without PHASE) 3 | 4 | #include "libhdr" 5 | 6 | #define II 1801 // Maximum N=1800 individuals 7 | #define SS 120001 // Maximum 120000 SNPs segregating 8 | #define BB 1001 // Maximum number of bins (1000) 9 | 10 | unsigned long long int n_[BB]; 11 | int n, b, NGEN, NBIN, snp_m2, snp_mZ, snp_mono, ZERO, maxCEROS, s1, s2, DISTANCE; 12 | int i, j, s, ss, k, x, NIND, NSNP, snp[II][SS][2], all[SS][5], pos[SS]; 13 | int PHASE, SUM_ALLELES[SS], numSNP, numNIND, calc_SNP[SS], mono_SNP[SS], allele[SS]; 14 | int gam11, gam12, gam21, gam22; 15 | 16 | double c, g, MAF, mor, dis[SS], cM, TOTAL_DIS; 17 | double Ne_r2_[BB], D2_[BB], VV_[BB], d2_[BB], d2_s_[BB], Ne_d2_[BB]; 18 | double freq[SS][3], freqs, freqss, freqG11s, freqG11ss, freqG1111, freqG1112, freqG1121, freqG1212; 19 | double D, D2, VV, r2, w, r2_[BB], cc, cc_[BB], qi, freq_p2s, freq_MAF, f, fp; 20 | 21 | char ch, S[100], filename[20]; 22 | 23 | char *x1, *x2, *x3, *x4, *x5, *x6, *x7, *x8, *x9; 24 | 25 | struct acc AVE_D_[BB], AVE_D2_[BB], AVE_VV_[BB], AVE_r2_[BB], AVE_c_[BB], AVE_numNIND; 26 | struct acc P_p2, pq; 27 | 28 | FILE *fped, *fmap, *fout, *fpar; 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | s1 = 1; 33 | s2 = 5; 34 | tracelevel=0; 35 | 36 | x1 = argv[1]; 37 | x2 = argv[2]; 38 | x3 = argv[3]; 39 | x4 = argv[4]; 40 | x5 = argv[5]; 41 | x6 = argv[6]; 42 | x7 = argv[7]; 43 | x8 = argv[8]; 44 | x9 = argv[9]; 45 | 46 | n = atoi(x1); 47 | NIND = atoi(x2); 48 | MAF = atof(x3); 49 | PHASE = atoi(x4); 50 | NGEN = atoi(x5); 51 | NBIN = atoi(x6); 52 | ZERO = atoi(x7); 53 | 54 | if (ZERO==0) maxCEROS = 0; 55 | else maxCEROS = 1000; 56 | 57 | DISTANCE = atoi(x8); 58 | cM = atof(x9); 59 | 60 | sprintf(filename, "outfileLD%d", n); 61 | fout = fopen (filename,"w"); 62 | 63 | sprintf(filename, "parameters%d", n); 64 | fpar = fopen (filename,"w"); 65 | 66 | readfiles(); 67 | LD(); 68 | 69 | return(0); 70 | } 71 | 72 | /* **************************************************************************** */ 73 | 74 | readfiles() 75 | { 76 | // ********** Read data.map file to get SNP positions ********** 77 | 78 | sprintf(filename, "chromosome%d.map", n); 79 | fmap = fopen (filename,"r"); 80 | 81 | while (!feof(fmap)) 82 | { 83 | NSNP ++; 84 | fscanf(fmap,"%d", &x); 85 | fscanf(fmap,"%s", &S); 86 | 87 | fscanf(fmap,"%lf", &w); 88 | dis[NSNP] = w; 89 | TOTAL_DIS += dis[NSNP]; 90 | fscanf(fmap,"%d", &x); 91 | pos[NSNP] = x; 92 | // if (tracelevel != 0) fprintf(fout, "dis=%f pos=%d ", dis[NSNP], pos[NSNP]); 93 | } 94 | NSNP = NSNP-1; 95 | // if (tracelevel != 0) fprintf(fout, "\n\nNSNP=%d\n\n", NSNP); 96 | 97 | fclose(fmap); 98 | 99 | // ********** Read data.ped file to get genotypes ********** 100 | 101 | sprintf(filename, "chromosome%d.ped", n); 102 | fped = fopen (filename,"r"); 103 | 104 | for (i=1; i<=NIND; i++) 105 | { 106 | for (j=1; j<=6; j++) 107 | fscanf(fped,"%s", &S); 108 | 109 | for (s=1; s<=NSNP; s++) 110 | { 111 | fscanf(fped,"%c", &ch); 112 | fscanf(fped,"%c", &ch); 113 | if (ch == '1') ch = 'A'; 114 | if (ch == '2') ch = 'T'; 115 | 116 | if (ch == 'A') snp[i][s][1] = 1; 117 | else if (ch == 'T') snp[i][s][1] = 2; 118 | else if (ch == 'C') snp[i][s][1] = 3; 119 | else if (ch == 'G') snp[i][s][1] = 4; 120 | else if (ch == '0') snp[i][s][1] = 0; 121 | 122 | fscanf(fped,"%c", &ch); 123 | fscanf(fped,"%c", &ch); 124 | if (ch == '1') ch = 'A'; 125 | if (ch == '2') ch = 'T'; 126 | 127 | if (ch == 'A') snp[i][s][2] = 1; 128 | else if (ch == 'T') snp[i][s][2] = 2; 129 | else if (ch == 'C') snp[i][s][2] = 3; 130 | else if (ch == 'G') snp[i][s][2] = 4; 131 | else if (ch == '0') snp[i][s][2] = 0; 132 | } 133 | } 134 | 135 | if (tracelevel != 0) 136 | { 137 | for (s=1; s<=NSNP; s++) 138 | { 139 | if (s == s1) 140 | { 141 | fprintf(fout, "s=%d ", s); 142 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 143 | fprintf(fout, "\n"); 144 | } 145 | if (s == s2) 146 | { 147 | fprintf(fout, "s=%d ", s); 148 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 149 | fprintf(fout, "\n"); 150 | } 151 | } 152 | } 153 | 154 | fclose(fped); 155 | 156 | return(0); 157 | } 158 | 159 | /* **************************************************************************** */ 160 | 161 | LD() 162 | { 163 | /******* Alleles segregating *******/ 164 | 165 | for (s=1; s<=NSNP; s++) 166 | for (i=1; i<=NIND; i++) 167 | for (k=1; k<=2; k++) 168 | { 169 | if (snp[i][s][k] == 1) all[s][1] ++; 170 | else if (snp[i][s][k] == 2) all[s][2] ++; 171 | else if (snp[i][s][k] == 3) all[s][3] ++; 172 | else if (snp[i][s][k] == 4) all[s][4] ++; 173 | else if (snp[i][s][k] == 0) all[s][5] ++; 174 | } 175 | for (s=1; s<=NSNP; s++) SUM_ALLELES[s] = (all[s][1] + all[s][2] + all[s][3] + all[s][4] + all[s][5]); 176 | 177 | for (s=1; s<=NSNP; s++) 178 | { 179 | if (all[s][1] > 0) allele[s]++; 180 | if (all[s][2] > 0) allele[s]++; 181 | if (all[s][3] > 0) allele[s]++; 182 | if (all[s][4] > 0) allele[s]++; 183 | } 184 | 185 | if (tracelevel != 0) 186 | { 187 | fprintf(fout, "\n\n"); 188 | for (s=1; s<=NSNP; s++) if ((s == s1)||(s == s2)) fprintf(fout, "s=%d %d %d %d %d %d\n", s, all[s][1], all[s][2], all[s][3], all[s][4], all[s][5]); 189 | // for (s=1; s<=NSNP; s++) if (allele[s]>2) fprintf(fout, "s=%d %d %d %d %d %d\n", s, all[s][1], all[s][2], all[s][3], all[s][4], all[s][5]); 190 | fprintf(fout, "\n\n"); 191 | } 192 | 193 | /******* Change allele codes to 1 and 2 *******/ 194 | 195 | for (s=1; s<=NSNP; s++) 196 | if (allele[s] <= 2) 197 | if (all[s][5] <= maxCEROS) 198 | { 199 | if ( (all[s][1] != 0) && (all[s][2] != 0) ) 200 | { 201 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 202 | freq[s][2] = all[s][2]/((2.0*NIND)-all[s][5]); 203 | calc_SNP[s] = 1; 204 | numSNP++; 205 | } 206 | else if ( (all[s][1] != 0) && (all[s][3] != 0) ) 207 | { 208 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 209 | freq[s][2] = all[s][3]/((2.0*NIND)-all[s][5]); 210 | 211 | for (i=1; i<=NIND; i++) 212 | for (k=1; k<=2; k++) 213 | if (snp[i][s][k] == 3) snp[i][s][k] = 2; 214 | calc_SNP[s] = 1; 215 | numSNP++; 216 | } 217 | else if ( (all[s][1] != 0) && (all[s][4] != 0) ) 218 | { 219 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 220 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 221 | 222 | for (i=1; i<=NIND; i++) 223 | for (k=1; k<=2; k++) 224 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 225 | calc_SNP[s] = 1; 226 | numSNP++; 227 | } 228 | else if ( (all[s][2] != 0) && (all[s][3] != 0) ) 229 | { 230 | freq[s][1] = all[s][2]/((2.0*NIND)-all[s][5]); 231 | freq[s][2] = all[s][3]/((2.0*NIND)-all[s][5]); 232 | 233 | for (i=1; i<=NIND; i++) 234 | for (k=1; k<=2; k++) 235 | { 236 | if (snp[i][s][k] == 2) snp[i][s][k] = 1; 237 | if (snp[i][s][k] == 3) snp[i][s][k] = 2; 238 | } 239 | calc_SNP[s] = 1; 240 | numSNP++; 241 | } 242 | else if ( (all[s][2] != 0) && (all[s][4] != 0) ) 243 | { 244 | freq[s][1] = all[s][2]/((2.0*NIND)-all[s][5]); 245 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 246 | 247 | for (i=1; i<=NIND; i++) 248 | for (k=1; k<=2; k++) 249 | { 250 | if (snp[i][s][k] == 2) snp[i][s][k] = 1; 251 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 252 | } 253 | calc_SNP[s] = 1; 254 | numSNP++; 255 | } 256 | else if ( (all[s][3] != 0) && (all[s][4] != 0) ) 257 | { 258 | freq[s][1] = all[s][3]/((2.0*NIND)-all[s][5]); 259 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 260 | 261 | for (i=1; i<=NIND; i++) 262 | for (k=1; k<=2; k++) 263 | { 264 | if (snp[i][s][k] == 3) snp[i][s][k] = 1; 265 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 266 | } 267 | calc_SNP[s] = 1; 268 | numSNP++; 269 | } 270 | else 271 | { 272 | snp_mono ++; 273 | mono_SNP[s] = 1; 274 | // printf("s=%d ", s); 275 | } 276 | } 277 | 278 | if (tracelevel != 0) 279 | { 280 | /* fprintf(fout, "\MONO, MORE THAN 2 alleles AND MORE THAN Maxceros\n"); 281 | for (s=1; s<=NSNP; s++) 282 | { 283 | if (mono_SNP[s] == 1) 284 | { 285 | fprintf(fout, "s=%d ", s); 286 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 287 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 288 | } 289 | if (allele[s] > 2) 290 | { 291 | fprintf(fout, "s=%d ", s); 292 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 293 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 294 | } 295 | if (all[s][5] > maxCEROS) 296 | { 297 | fprintf(fout, "s=%d ", s); 298 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 299 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 300 | } 301 | } 302 | fprintf(fout, "\nCHANGED\n"); 303 | */ 304 | for (s=1; s<=NSNP; s++) 305 | { 306 | if (s == s1) 307 | { 308 | fprintf(fout, "s=%d ", s); 309 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 310 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 311 | } 312 | if (s == s2) 313 | { 314 | fprintf(fout, "s=%d ", s); 315 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 316 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 317 | } 318 | } 319 | } 320 | 321 | /******* Major allele is 1 and minor is 2 *******/ 322 | 323 | for (s=1; s<=NSNP; s++) 324 | if (calc_SNP[s] == 1) 325 | { 326 | if (freq[s][1] < freq[s][2]) 327 | { 328 | for (i=1; i<=NIND; i++) 329 | for (k=1; k<=2; k++) 330 | { 331 | if (snp[i][s][k] == 1) snp[i][s][k] = 2; 332 | else if (snp[i][s][k] == 2) snp[i][s][k] = 1; 333 | } 334 | w=freq[s][1]; freq[s][1]=freq[s][2]; freq[s][2]=w; 335 | } 336 | } 337 | 338 | if (tracelevel != 0) 339 | { 340 | fprintf(fout, "\nCHANGED major is 1\n"); 341 | for (s=1; s<=NSNP; s++) 342 | { 343 | if (s == s1) 344 | { 345 | fprintf(fout, "s=%d ", s); 346 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 347 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 348 | } 349 | if (s == s2) 350 | { 351 | fprintf(fout, "s=%d ", s); 352 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 353 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 354 | } 355 | } 356 | } 357 | 358 | /******* Calculation of D, D2, VV and r2 *******/ 359 | 360 | freq_MAF=1.0; 361 | 362 | for (s=1; s MAF) && (freq[ss][2] > MAF)) 367 | { 368 | freqs=0.0; freqss=0.0; freqG11s=0.0; freqG11ss=0.0; 369 | freqG1111=0.0; freqG1112=0.0; freqG1121=0.0; freqG1212=0.0; 370 | freq_p2s=0.0; 371 | 372 | gam11=0; gam12=0; gam21=0; gam22=0; 373 | 374 | if ((ss == s+1) && (freq[s][2] < freq_MAF)) freq_MAF = freq[s][2]; 375 | 376 | numNIND=0; 377 | for (i=1; i<=NIND; i++) 378 | if ( (snp[i][s][1] != 0) && (snp[i][s][2] != 0) && (snp[i][ss][1] != 0) & (snp[i][ss][2] != 0) ) 379 | { 380 | numNIND ++; 381 | 382 | if ((snp[i][s][1] == 1) && (snp[i][s][2] == 1)) qi = 1.0; 383 | if ((snp[i][s][1] == 1) && (snp[i][s][2] == 2)) qi = 0.5; 384 | if ((snp[i][s][1] == 2) && (snp[i][s][2] == 1)) qi = 0.5; 385 | if ((snp[i][s][1] == 2) && (snp[i][s][2] == 2)) qi = 0.0; 386 | 387 | freq_p2s += (qi * qi); 388 | 389 | if (snp[i][s][1] == 1) freqs ++; 390 | if (snp[i][s][2] == 1) freqs ++; 391 | 392 | if (snp[i][ss][1] == 1) freqss ++; 393 | if (snp[i][ss][2] == 1) freqss ++; 394 | 395 | if ( (snp[i][s][1] == 1) && (snp[i][s][2] == 1) ) 396 | freqG11s ++; 397 | 398 | if ( (snp[i][ss][1] == 1) && (snp[i][ss][2] == 1) ) 399 | freqG11ss ++; 400 | 401 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 402 | freqG1111 ++; 403 | 404 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) 405 | freqG1112 ++; 406 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 407 | freqG1112 ++; 408 | 409 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) 410 | freqG1121 ++; 411 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 412 | freqG1121 ++; 413 | 414 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 2) ) 415 | freqG1212 ++; 416 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 417 | freqG1212 ++; 418 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) 419 | freqG1212 ++; 420 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) 421 | freqG1212 ++; 422 | 423 | // PHASE 1 424 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) ) gam11 ++; 425 | else if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) ) gam12 ++; 426 | else if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) ) gam21 ++; 427 | else if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 2) ) gam22 ++; 428 | 429 | if ( (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) gam11 ++; 430 | else if ( (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) gam12 ++; 431 | else if ( (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) gam21 ++; 432 | else if ( (snp[i][s][2] == 2) && (snp[i][ss][2] == 2) ) gam22 ++; 433 | } 434 | 435 | if (numNIND > NIND/2) 436 | { 437 | 438 | accum(&AVE_numNIND, 1.0/numNIND); 439 | 440 | freq_p2s = freq_p2s/numNIND; 441 | freqs = freqs/(2.0*numNIND); 442 | freqss = freqss/(2.0*numNIND); 443 | freqG11s = freqG11s/numNIND; 444 | freqG11ss = freqG11ss/numNIND; 445 | freqG1111 = freqG1111/numNIND; 446 | freqG1112 = freqG1112/numNIND; 447 | freqG1121 = freqG1121/numNIND; 448 | freqG1212 = freqG1212/numNIND; 449 | 450 | if (tracelevel != 0) 451 | { 452 | if ((s == s1) && (ss == s2)) 453 | { 454 | fprintf(fout, "\ns=%d ss=%d numNIND=%d\n", s, ss, numNIND); 455 | fprintf(fout, "freqs=%f freqss=%f\n", freqs, freqss); 456 | fprintf(fout, "freqG11s=%f freqG11ss=%f\n", freqG11s, freqG11ss); 457 | fprintf(fout, "freqG1111=%f\n", freqG1111); 458 | fprintf(fout, "freqG1112=%f\n", freqG1112); 459 | fprintf(fout, "freqG1121=%f\n", freqG1121); 460 | fprintf(fout, "freqG1212=%f\n", freqG1212); 461 | fprintf(fout, "gam11=%d gam12=%d gam21=%d gam22=%d\n", gam11, gam12, gam21, gam22); 462 | fprintf(fout, "\n"); 463 | } 464 | /* if (numNIND < NIND) 465 | { 466 | fprintf(fout, "\ns=%d ss=%d numNIND=%d\n", s, ss, numNIND); 467 | fprintf(fout, "freqs=%f freqss=%f\n", freqs, freqss); 468 | fprintf(fout, "freqG11s=%f freqG11ss=%f\n", freqG11s, freqG11ss); 469 | fprintf(fout, "freqG1111=%f\n", freqG1111); 470 | fprintf(fout, "freqG1112=%f\n", freqG1112); 471 | fprintf(fout, "freqG1121=%f\n", freqG1121); 472 | fprintf(fout, "freqG1212=%f\n", freqG1212); 473 | fprintf(fout, "\n"); 474 | } 475 | */ } 476 | 477 | if ((PHASE == 0)||(PHASE == 1)) D = ( (gam11/(2.0*numNIND)) * (gam22/(2.0*numNIND)) ) - ( (gam12/(2.0*numNIND)) * (gam21/(2.0*numNIND)) ); 478 | else if (PHASE == 2) D = (2.0*freqG1111) + freqG1112 + freqG1121 + (freqG1212/2.0) - (2.0*freqs*freqss); 479 | 480 | D2 = (D * D); 481 | VV = ( freqs * (1.0 - freqs) ) * ( freqss * (1.0 - freqss) ); 482 | r2 = D2 / VV; 483 | 484 | 485 | if (TOTAL_DIS == 0.0) mor = ( abs(pos[ss]-pos[s]) / (1000000/cM) ) * 0.01; 486 | else mor = (dis[ss]-dis[s])*0.01; 487 | 488 | if (DISTANCE == 0) c = mor; 489 | else if (DISTANCE == 1) c = (1.0 - exp(-2.0*mor))/2.0; 490 | else if (DISTANCE == 2) c = 0.5*(exp(4.0*mor)-1)/(exp(4.0*mor)+1); 491 | if (c>0.5) c=0.5; 492 | g = 1.0/(2.0*c); 493 | 494 | if (tracelevel != 0) 495 | { 496 | if ((s == s1) && (ss == s2)) fprintf(fout, "\n\nSNPs %d-%d qs=%f ps=%f qss=%f pss=%f D=%f D2=%f VV=%f r2=%f c=%f g=%f\n\n", 497 | s, ss, freqs, 1.0-freqs, freqss, 1.0-freqss, D, D2, VV, r2, c, g); 498 | } 499 | 500 | if (tracelevel != 0) 501 | { 502 | fprintf(fout, "SNPs %d-%d qs=%f ps=%f qss=%f pss=%f D=%f D2=%f VV=%f r2=%f c=%f g=%f\n", 503 | s, ss, freqs, 1.0-freqs, freqss, 1.0-freqss, D, D2, VV, r2, c, g); 504 | } 505 | 506 | if ( (freqs*(1.0-freqs) != 0.0) && (freqss*(1.0-freqss) != 0.0) ) 507 | { 508 | for (b=1; b<=NBIN; b++) 509 | if (c != 0.0) 510 | { 511 | if (b==1) 512 | { 513 | if ((g > 0) && (g <= 2)) 514 | { 515 | n_[b] ++; 516 | accum(&AVE_D_[b], D); 517 | accum(&AVE_D2_[b], D2); 518 | accum(&AVE_VV_[b], VV); 519 | accum(&AVE_r2_[b], r2); 520 | accum(&AVE_c_[b], 1.0/c); 521 | } 522 | } 523 | else if (b==2) 524 | { 525 | if ((g > 2) && (g <= 4)) 526 | { 527 | n_[b] ++; 528 | accum(&AVE_D_[b], D); 529 | accum(&AVE_D2_[b], D2); 530 | accum(&AVE_VV_[b], VV); 531 | accum(&AVE_r2_[b], r2); 532 | accum(&AVE_c_[b], 1.0/c); 533 | } 534 | } 535 | else if (b==3) 536 | { 537 | if ((g > 4) && (g <= 6)) 538 | { 539 | n_[b] ++; 540 | accum(&AVE_D_[b], D); 541 | accum(&AVE_D2_[b], D2); 542 | accum(&AVE_VV_[b], VV); 543 | accum(&AVE_r2_[b], r2); 544 | accum(&AVE_c_[b], 1.0/c); 545 | } 546 | } 547 | else if (b==4) 548 | { 549 | if ((g > 6) && (g <= 8)) 550 | { 551 | n_[b] ++; 552 | accum(&AVE_D_[b], D); 553 | accum(&AVE_D2_[b], D2); 554 | accum(&AVE_VV_[b], VV); 555 | accum(&AVE_r2_[b], r2); 556 | accum(&AVE_c_[b], 1.0/c); 557 | } 558 | } 559 | else if (b==5) 560 | { 561 | if ((g > 8) && (g <= 10)) 562 | { 563 | n_[b] ++; 564 | accum(&AVE_D_[b], D); 565 | accum(&AVE_D2_[b], D2); 566 | accum(&AVE_VV_[b], VV); 567 | accum(&AVE_r2_[b], r2); 568 | accum(&AVE_c_[b], 1.0/c); 569 | } 570 | } 571 | else 572 | { 573 | if ( (g > ((NGEN/NBIN)*(b-6))+10) && (g <= ((NGEN/NBIN)*(b-5))+10) ) 574 | { 575 | n_[b] ++; 576 | accum(&AVE_D_[b], D); 577 | accum(&AVE_D2_[b], D2); 578 | accum(&AVE_VV_[b], VV); 579 | accum(&AVE_r2_[b], r2); 580 | accum(&AVE_c_[b], 1.0/c); 581 | } 582 | } 583 | } 584 | } 585 | } 586 | } 587 | 588 | /******* Calculation of Hardy-Weinberg deviation *******/ 589 | 590 | for (s=1; s<=NSNP; s++) 591 | if (calc_SNP[s] == 1) 592 | { 593 | freqs=0.0; freqG11s=0.0; 594 | 595 | numNIND=0; 596 | for (i=1; i<=NIND; i++) 597 | if ((snp[i][s][1] != 0) && (snp[i][s][2] != 0)) 598 | { 599 | numNIND ++; 600 | 601 | if (snp[i][s][1] == 1) freqs ++; 602 | if (snp[i][s][2] == 1) freqs ++; 603 | 604 | if ( (snp[i][s][1] == 1) && (snp[i][s][2] == 1) ) 605 | freqG11s ++; 606 | } 607 | 608 | freqs = freqs/(2.0*numNIND); 609 | freqG11s = freqG11s/numNIND; 610 | 611 | if (freqs*(1.0-freqs) != 0.0) 612 | { 613 | accum(&P_p2, freqG11s-(freqs*freqs)); 614 | accum(&pq, freqs*(1.0-freqs)); 615 | 616 | if (tracelevel != 0) 617 | { 618 | fprintf(fout, "\n****** s=%d *******\n", s); 619 | fprintf(fout, "freqs=%f freqs*(1.0-freqs)=%f\n", freqs, freqs*(1.0-freqs)); 620 | fprintf(fout, "freqG11s=%f freqG11s-(freqs*freqs)=%f\n", freqG11s, freqG11s-(freqs*freqs)); 621 | fprintf(fout, "\n"); 622 | } 623 | } 624 | } 625 | 626 | /* **************************************** */ 627 | 628 | // Table of results 629 | 630 | for (b=1; b<=NBIN; b++) 631 | { 632 | cc_[b] = 1.0/accmean(&AVE_c_[b]); 633 | r2_[b] = accmean(&AVE_r2_[b]); 634 | D2_[b] = accmean(&AVE_D2_[b]); 635 | VV_[b] = accmean(&AVE_VV_[b]); 636 | 637 | // if (NIND == 2) d2_[b] = (D2_[b] / VV_[b]); 638 | // else d2_[b] = ( (D2_[b] / (4.0*VV_[b])) ); 639 | 640 | d2_[b] = (D2_[b] / VV_[b]); 641 | 642 | Ne_r2_[b] = (1.0/(4.0*cc_[b]*r2_[b])) - (1.0/(2.0*cc_[b])); 643 | Ne_d2_[b] = (1.0/(4.0*cc_[b]*d2_[b])) - (1.0/(2.0*cc_[b])); 644 | } 645 | 646 | for (s=1; s<=NSNP; s++) 647 | { 648 | if (allele[s] > 2) snp_m2 ++; 649 | if (all[s][5] > maxCEROS) snp_mZ ++; 650 | } 651 | 652 | f = accmean(&P_p2) / accmean(&pq); 653 | fp = (1.0 + (f*(2.0*NIND - 1.0))) / (2.0*NIND - 1.0 + f); 654 | 655 | fprintf(fpar," NIND(real sample)=%d\n NSNP=%d\n NSNP_calculations=%d\n NSNP_+2alleles=%d\n NSNP_zeroes=%d\n NSNP_monomorphic=%d\n NIND_corrected=%f\n freq_MAF=%f\n F_dev_HW (sample)=%f\n F_dev_HW (pop)=%f\n", 656 | NIND, NSNP, numSNP, snp_m2, snp_mZ, snp_mono, 1.0/accmean(&AVE_numNIND), freq_MAF, f, fp); 657 | 658 | if (TOTAL_DIS == 0.0) fprintf(fpar," No genetic distances; using %f cM per Mb\n\n", cM); 659 | else fprintf(fpar," Genetic distances available in map file\n\n"); 660 | 661 | // OUTFILELD 662 | // if (tracelevel != 0) fprintf(fout,"\nn c d2 g D2 VV\n"); 663 | 664 | fprintf(fout,"%d\n", PHASE); 665 | fprintf(fout,"%d\n", NIND); 666 | fprintf(fout,"%d\n", numSNP); 667 | if (accmean(&AVE_numNIND) > 0) fprintf(fout,"%f\n", 1.0/accmean(&AVE_numNIND)); 668 | else fprintf(fout,"-99\n"); 669 | if ((numSNP > 0)&&(accmean(&pq) > 0)) fprintf(fout,"%f\n", f); 670 | else fprintf(fout,"-99\n"); 671 | // if (numSNP > 0) fprintf(fout,"%f\n", fp); 672 | // else fprintf(fout,"-99\n"); 673 | 674 | for (b=1; b<=NBIN; b++) 675 | { 676 | if (n_[b] == 0) 677 | { 678 | if (b <= 5) fprintf(fout,"0 0 0 %d 0 0\n", 2*b); 679 | else fprintf(fout,"0 0 0 %d 0 0\n", ((NGEN/NBIN)*(b-5))+10); 680 | } 681 | else 682 | { 683 | if (b <= 5) fprintf(fout,"%lld %f %f %d %f %f\n", n_[b], cc_[b], d2_[b], 2*b, D2_[b], VV_[b]); 684 | else fprintf(fout,"%lld %f %f %d %f %f\n", n_[b], cc_[b], d2_[b], ((NGEN/NBIN)*(b-5))+10, D2_[b], VV_[b]); 685 | } 686 | } 687 | 688 | return(0); 689 | } 690 | 691 | /* ********************************************************************************************* */ 692 | -------------------------------------------------------------------------------- /CODES_LINUX/LD_SNP_REAL3.c: -------------------------------------------------------------------------------- 1 | 2 | // LD_SNP_REAL3.c (LD estimates from data.ped, with and without PHASE) 3 | 4 | #include "libhdr" 5 | 6 | #define II 1801 // Maximum N=1800 individuals 7 | #define SS 120001 // Maximum 120000 SNPs segregating 8 | #define BB 1001 // Maximum number of bins (1000) 9 | 10 | unsigned long long int n_[BB]; 11 | int n, b, NGEN, NBIN, snp_m2, snp_mZ, snp_mono, ZERO, maxCEROS, s1, s2, DISTANCE; 12 | int i, j, s, ss, k, x, NIND, NSNP, snp[II][SS][2], all[SS][5], pos[SS]; 13 | int PHASE, SUM_ALLELES[SS], numSNP, numNIND, calc_SNP[SS], mono_SNP[SS], allele[SS]; 14 | int gam11, gam12, gam21, gam22; 15 | 16 | double c, g, MAF, mor, dis[SS], cM, TOTAL_DIS; 17 | double Ne_r2_[BB], D2_[BB], VV_[BB], d2_[BB], d2_s_[BB], Ne_d2_[BB]; 18 | double freq[SS][3], freqs, freqss, freqG11s, freqG11ss, freqG1111, freqG1112, freqG1121, freqG1212; 19 | double D, D2, VV, r2, w, r2_[BB], cc, cc_[BB], qi, freq_p2s, freq_MAF, f, fp; 20 | 21 | char ch, S[100], filename[20]; 22 | 23 | char *x1, *x2, *x3, *x4, *x5, *x6, *x7, *x8, *x9; 24 | 25 | struct acc AVE_D_[BB], AVE_D2_[BB], AVE_VV_[BB], AVE_r2_[BB], AVE_c_[BB], AVE_numNIND; 26 | struct acc P_p2, pq; 27 | 28 | FILE *fped, *fmap, *fout, *fpar; 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | s1 = 1; 33 | s2 = 5; 34 | tracelevel=0; 35 | 36 | x1 = argv[1]; 37 | x2 = argv[2]; 38 | x3 = argv[3]; 39 | x4 = argv[4]; 40 | x5 = argv[5]; 41 | x6 = argv[6]; 42 | x7 = argv[7]; 43 | x8 = argv[8]; 44 | x9 = argv[9]; 45 | 46 | n = atoi(x1); 47 | NIND = atoi(x2); 48 | MAF = atof(x3); 49 | PHASE = atoi(x4); 50 | NGEN = atoi(x5); 51 | NBIN = atoi(x6); 52 | ZERO = atoi(x7); 53 | 54 | if (ZERO==0) maxCEROS = 0; 55 | else maxCEROS = 1000; 56 | 57 | DISTANCE = atoi(x8); 58 | cM = atof(x9); 59 | 60 | sprintf(filename, "outfileLD%d", n); 61 | fout = fopen (filename,"w"); 62 | 63 | sprintf(filename, "parameters%d", n); 64 | fpar = fopen (filename,"w"); 65 | 66 | readfiles(); 67 | LD(); 68 | 69 | return(0); 70 | } 71 | 72 | /* **************************************************************************** */ 73 | 74 | readfiles() 75 | { 76 | // ********** Read data.map file to get SNP positions ********** 77 | 78 | sprintf(filename, "chromosome%d.map", n); 79 | fmap = fopen (filename,"r"); 80 | 81 | while (!feof(fmap)) 82 | { 83 | NSNP ++; 84 | fscanf(fmap,"%d", &x); 85 | fscanf(fmap,"%s", &S); 86 | 87 | fscanf(fmap,"%lf", &w); 88 | dis[NSNP] = w; 89 | TOTAL_DIS += dis[NSNP]; 90 | fscanf(fmap,"%d", &x); 91 | pos[NSNP] = x; 92 | // if (tracelevel != 0) fprintf(fout, "dis=%f pos=%d ", dis[NSNP], pos[NSNP]); 93 | } 94 | NSNP = NSNP-1; 95 | // if (tracelevel != 0) fprintf(fout, "\n\nNSNP=%d\n\n", NSNP); 96 | 97 | fclose(fmap); 98 | 99 | // ********** Read data.ped file to get genotypes ********** 100 | 101 | sprintf(filename, "chromosome%d.ped", n); 102 | fped = fopen (filename,"r"); 103 | 104 | for (i=1; i<=NIND; i++) 105 | { 106 | for (j=1; j<=6; j++) 107 | fscanf(fped,"%s", &S); 108 | 109 | for (s=1; s<=NSNP; s++) 110 | { 111 | fscanf(fped,"%c", &ch); 112 | fscanf(fped,"%c", &ch); 113 | if (ch == '1') ch = 'A'; 114 | if (ch == '2') ch = 'T'; 115 | 116 | if (ch == 'A') snp[i][s][1] = 1; 117 | else if (ch == 'T') snp[i][s][1] = 2; 118 | else if (ch == 'C') snp[i][s][1] = 3; 119 | else if (ch == 'G') snp[i][s][1] = 4; 120 | else if (ch == '0') snp[i][s][1] = 0; 121 | 122 | fscanf(fped,"%c", &ch); 123 | fscanf(fped,"%c", &ch); 124 | if (ch == '1') ch = 'A'; 125 | if (ch == '2') ch = 'T'; 126 | 127 | if (ch == 'A') snp[i][s][2] = 1; 128 | else if (ch == 'T') snp[i][s][2] = 2; 129 | else if (ch == 'C') snp[i][s][2] = 3; 130 | else if (ch == 'G') snp[i][s][2] = 4; 131 | else if (ch == '0') snp[i][s][2] = 0; 132 | } 133 | } 134 | 135 | if (tracelevel != 0) 136 | { 137 | for (s=1; s<=NSNP; s++) 138 | { 139 | if (s == s1) 140 | { 141 | fprintf(fout, "s=%d ", s); 142 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 143 | fprintf(fout, "\n"); 144 | } 145 | if (s == s2) 146 | { 147 | fprintf(fout, "s=%d ", s); 148 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 149 | fprintf(fout, "\n"); 150 | } 151 | } 152 | } 153 | 154 | fclose(fped); 155 | 156 | return(0); 157 | } 158 | 159 | /* **************************************************************************** */ 160 | 161 | LD() 162 | { 163 | /******* Alleles segregating *******/ 164 | 165 | for (s=1; s<=NSNP; s++) 166 | for (i=1; i<=NIND; i++) 167 | for (k=1; k<=2; k++) 168 | { 169 | if (snp[i][s][k] == 1) all[s][1] ++; 170 | else if (snp[i][s][k] == 2) all[s][2] ++; 171 | else if (snp[i][s][k] == 3) all[s][3] ++; 172 | else if (snp[i][s][k] == 4) all[s][4] ++; 173 | else if (snp[i][s][k] == 0) all[s][5] ++; 174 | } 175 | for (s=1; s<=NSNP; s++) SUM_ALLELES[s] = (all[s][1] + all[s][2] + all[s][3] + all[s][4] + all[s][5]); 176 | 177 | for (s=1; s<=NSNP; s++) 178 | { 179 | if (all[s][1] > 0) allele[s]++; 180 | if (all[s][2] > 0) allele[s]++; 181 | if (all[s][3] > 0) allele[s]++; 182 | if (all[s][4] > 0) allele[s]++; 183 | } 184 | 185 | if (tracelevel != 0) 186 | { 187 | fprintf(fout, "\n\n"); 188 | for (s=1; s<=NSNP; s++) if ((s == s1)||(s == s2)) fprintf(fout, "s=%d %d %d %d %d %d\n", s, all[s][1], all[s][2], all[s][3], all[s][4], all[s][5]); 189 | // for (s=1; s<=NSNP; s++) if (allele[s]>2) fprintf(fout, "s=%d %d %d %d %d %d\n", s, all[s][1], all[s][2], all[s][3], all[s][4], all[s][5]); 190 | fprintf(fout, "\n\n"); 191 | } 192 | 193 | /******* Change allele codes to 1 and 2 *******/ 194 | 195 | for (s=1; s<=NSNP; s++) 196 | if (allele[s] <= 2) 197 | if (all[s][5] <= maxCEROS) 198 | { 199 | if ( (all[s][1] != 0) && (all[s][2] != 0) ) 200 | { 201 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 202 | freq[s][2] = all[s][2]/((2.0*NIND)-all[s][5]); 203 | calc_SNP[s] = 1; 204 | numSNP++; 205 | } 206 | else if ( (all[s][1] != 0) && (all[s][3] != 0) ) 207 | { 208 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 209 | freq[s][2] = all[s][3]/((2.0*NIND)-all[s][5]); 210 | 211 | for (i=1; i<=NIND; i++) 212 | for (k=1; k<=2; k++) 213 | if (snp[i][s][k] == 3) snp[i][s][k] = 2; 214 | calc_SNP[s] = 1; 215 | numSNP++; 216 | } 217 | else if ( (all[s][1] != 0) && (all[s][4] != 0) ) 218 | { 219 | freq[s][1] = all[s][1]/((2.0*NIND)-all[s][5]); 220 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 221 | 222 | for (i=1; i<=NIND; i++) 223 | for (k=1; k<=2; k++) 224 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 225 | calc_SNP[s] = 1; 226 | numSNP++; 227 | } 228 | else if ( (all[s][2] != 0) && (all[s][3] != 0) ) 229 | { 230 | freq[s][1] = all[s][2]/((2.0*NIND)-all[s][5]); 231 | freq[s][2] = all[s][3]/((2.0*NIND)-all[s][5]); 232 | 233 | for (i=1; i<=NIND; i++) 234 | for (k=1; k<=2; k++) 235 | { 236 | if (snp[i][s][k] == 2) snp[i][s][k] = 1; 237 | if (snp[i][s][k] == 3) snp[i][s][k] = 2; 238 | } 239 | calc_SNP[s] = 1; 240 | numSNP++; 241 | } 242 | else if ( (all[s][2] != 0) && (all[s][4] != 0) ) 243 | { 244 | freq[s][1] = all[s][2]/((2.0*NIND)-all[s][5]); 245 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 246 | 247 | for (i=1; i<=NIND; i++) 248 | for (k=1; k<=2; k++) 249 | { 250 | if (snp[i][s][k] == 2) snp[i][s][k] = 1; 251 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 252 | } 253 | calc_SNP[s] = 1; 254 | numSNP++; 255 | } 256 | else if ( (all[s][3] != 0) && (all[s][4] != 0) ) 257 | { 258 | freq[s][1] = all[s][3]/((2.0*NIND)-all[s][5]); 259 | freq[s][2] = all[s][4]/((2.0*NIND)-all[s][5]); 260 | 261 | for (i=1; i<=NIND; i++) 262 | for (k=1; k<=2; k++) 263 | { 264 | if (snp[i][s][k] == 3) snp[i][s][k] = 1; 265 | if (snp[i][s][k] == 4) snp[i][s][k] = 2; 266 | } 267 | calc_SNP[s] = 1; 268 | numSNP++; 269 | } 270 | else 271 | { 272 | snp_mono ++; 273 | mono_SNP[s] = 1; 274 | // printf("s=%d ", s); 275 | } 276 | } 277 | 278 | if (tracelevel != 0) 279 | { 280 | /* fprintf(fout, "\MONO, MORE THAN 2 alleles AND MORE THAN Maxceros\n"); 281 | for (s=1; s<=NSNP; s++) 282 | { 283 | if (mono_SNP[s] == 1) 284 | { 285 | fprintf(fout, "s=%d ", s); 286 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 287 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 288 | } 289 | if (allele[s] > 2) 290 | { 291 | fprintf(fout, "s=%d ", s); 292 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 293 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 294 | } 295 | if (all[s][5] > maxCEROS) 296 | { 297 | fprintf(fout, "s=%d ", s); 298 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 299 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 300 | } 301 | } 302 | fprintf(fout, "\nCHANGED\n"); 303 | */ 304 | for (s=1; s<=NSNP; s++) 305 | { 306 | if (s == s1) 307 | { 308 | fprintf(fout, "s=%d ", s); 309 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 310 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 311 | } 312 | if (s == s2) 313 | { 314 | fprintf(fout, "s=%d ", s); 315 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 316 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 317 | } 318 | } 319 | } 320 | 321 | /******* Major allele is 1 and minor is 2 *******/ 322 | 323 | for (s=1; s<=NSNP; s++) 324 | if (calc_SNP[s] == 1) 325 | { 326 | if (freq[s][1] < freq[s][2]) 327 | { 328 | for (i=1; i<=NIND; i++) 329 | for (k=1; k<=2; k++) 330 | { 331 | if (snp[i][s][k] == 1) snp[i][s][k] = 2; 332 | else if (snp[i][s][k] == 2) snp[i][s][k] = 1; 333 | } 334 | w=freq[s][1]; freq[s][1]=freq[s][2]; freq[s][2]=w; 335 | } 336 | } 337 | 338 | if (tracelevel != 0) 339 | { 340 | fprintf(fout, "\nCHANGED major is 1\n"); 341 | for (s=1; s<=NSNP; s++) 342 | { 343 | if (s == s1) 344 | { 345 | fprintf(fout, "s=%d ", s); 346 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 347 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 348 | } 349 | if (s == s2) 350 | { 351 | fprintf(fout, "s=%d ", s); 352 | for (i=1; i<=NIND; i++) fprintf(fout, "%d%d ", snp[i][s][1], snp[i][s][2]); 353 | fprintf(fout, "\nqs=%f ps=%f\n\n", freq[s][1], freq[s][2]); 354 | } 355 | } 356 | } 357 | 358 | /******* Calculation of D, D2, VV and r2 *******/ 359 | 360 | freq_MAF=1.0; 361 | 362 | for (s=1; s MAF) && (freq[ss][2] > MAF)) 367 | { 368 | freqs=0.0; freqss=0.0; freqG11s=0.0; freqG11ss=0.0; 369 | freqG1111=0.0; freqG1112=0.0; freqG1121=0.0; freqG1212=0.0; 370 | freq_p2s=0.0; 371 | 372 | gam11=0; gam12=0; gam21=0; gam22=0; 373 | 374 | if ((ss == s+1) && (freq[s][2] < freq_MAF)) freq_MAF = freq[s][2]; 375 | 376 | numNIND=0; 377 | for (i=1; i<=NIND; i++) 378 | if ( (snp[i][s][1] != 0) && (snp[i][s][2] != 0) && (snp[i][ss][1] != 0) & (snp[i][ss][2] != 0) ) 379 | { 380 | numNIND ++; 381 | 382 | if ((snp[i][s][1] == 1) && (snp[i][s][2] == 1)) qi = 1.0; 383 | if ((snp[i][s][1] == 1) && (snp[i][s][2] == 2)) qi = 0.5; 384 | if ((snp[i][s][1] == 2) && (snp[i][s][2] == 1)) qi = 0.5; 385 | if ((snp[i][s][1] == 2) && (snp[i][s][2] == 2)) qi = 0.0; 386 | 387 | freq_p2s += (qi * qi); 388 | 389 | if (snp[i][s][1] == 1) freqs ++; 390 | if (snp[i][s][2] == 1) freqs ++; 391 | 392 | if (snp[i][ss][1] == 1) freqss ++; 393 | if (snp[i][ss][2] == 1) freqss ++; 394 | 395 | if ( (snp[i][s][1] == 1) && (snp[i][s][2] == 1) ) 396 | freqG11s ++; 397 | 398 | if ( (snp[i][ss][1] == 1) && (snp[i][ss][2] == 1) ) 399 | freqG11ss ++; 400 | 401 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 402 | freqG1111 ++; 403 | 404 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) 405 | freqG1112 ++; 406 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 407 | freqG1112 ++; 408 | 409 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) 410 | freqG1121 ++; 411 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 412 | freqG1121 ++; 413 | 414 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 2) ) 415 | freqG1212 ++; 416 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) 417 | freqG1212 ++; 418 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) && (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) 419 | freqG1212 ++; 420 | if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) && (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) 421 | freqG1212 ++; 422 | 423 | // PHASE 1 424 | if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 1) ) gam11 ++; 425 | else if ( (snp[i][s][1] == 1) && (snp[i][ss][1] == 2) ) gam12 ++; 426 | else if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 1) ) gam21 ++; 427 | else if ( (snp[i][s][1] == 2) && (snp[i][ss][1] == 2) ) gam22 ++; 428 | 429 | if ( (snp[i][s][2] == 1) && (snp[i][ss][2] == 1) ) gam11 ++; 430 | else if ( (snp[i][s][2] == 1) && (snp[i][ss][2] == 2) ) gam12 ++; 431 | else if ( (snp[i][s][2] == 2) && (snp[i][ss][2] == 1) ) gam21 ++; 432 | else if ( (snp[i][s][2] == 2) && (snp[i][ss][2] == 2) ) gam22 ++; 433 | } 434 | 435 | if (numNIND > NIND/2) 436 | { 437 | 438 | accum(&AVE_numNIND, 1.0/numNIND); 439 | 440 | freq_p2s = freq_p2s/numNIND; 441 | freqs = freqs/(2.0*numNIND); 442 | freqss = freqss/(2.0*numNIND); 443 | freqG11s = freqG11s/numNIND; 444 | freqG11ss = freqG11ss/numNIND; 445 | freqG1111 = freqG1111/numNIND; 446 | freqG1112 = freqG1112/numNIND; 447 | freqG1121 = freqG1121/numNIND; 448 | freqG1212 = freqG1212/numNIND; 449 | 450 | if (tracelevel != 0) 451 | { 452 | if ((s == s1) && (ss == s2)) 453 | { 454 | fprintf(fout, "\ns=%d ss=%d numNIND=%d\n", s, ss, numNIND); 455 | fprintf(fout, "freqs=%f freqss=%f\n", freqs, freqss); 456 | fprintf(fout, "freqG11s=%f freqG11ss=%f\n", freqG11s, freqG11ss); 457 | fprintf(fout, "freqG1111=%f\n", freqG1111); 458 | fprintf(fout, "freqG1112=%f\n", freqG1112); 459 | fprintf(fout, "freqG1121=%f\n", freqG1121); 460 | fprintf(fout, "freqG1212=%f\n", freqG1212); 461 | fprintf(fout, "gam11=%d gam12=%d gam21=%d gam22=%d\n", gam11, gam12, gam21, gam22); 462 | fprintf(fout, "\n"); 463 | } 464 | /* if (numNIND < NIND) 465 | { 466 | fprintf(fout, "\ns=%d ss=%d numNIND=%d\n", s, ss, numNIND); 467 | fprintf(fout, "freqs=%f freqss=%f\n", freqs, freqss); 468 | fprintf(fout, "freqG11s=%f freqG11ss=%f\n", freqG11s, freqG11ss); 469 | fprintf(fout, "freqG1111=%f\n", freqG1111); 470 | fprintf(fout, "freqG1112=%f\n", freqG1112); 471 | fprintf(fout, "freqG1121=%f\n", freqG1121); 472 | fprintf(fout, "freqG1212=%f\n", freqG1212); 473 | fprintf(fout, "\n"); 474 | } 475 | */ } 476 | 477 | if ((PHASE == 0)||(PHASE == 1)) D = ( (gam11/(2.0*numNIND)) * (gam22/(2.0*numNIND)) ) - ( (gam12/(2.0*numNIND)) * (gam21/(2.0*numNIND)) ); 478 | else if (PHASE == 2) D = (2.0*freqG1111) + freqG1112 + freqG1121 + (freqG1212/2.0) - (2.0*freqs*freqss); 479 | 480 | D2 = (D * D); 481 | VV = ( freqs * (1.0 - freqs) ) * ( freqss * (1.0 - freqss) ); 482 | r2 = D2 / VV; 483 | 484 | 485 | if (TOTAL_DIS == 0.0) mor = ( abs(pos[ss]-pos[s]) / (1000000/cM) ) * 0.01; 486 | else mor = (dis[ss]-dis[s])*0.01; 487 | 488 | if (DISTANCE == 0) c = mor; 489 | else if (DISTANCE == 1) c = (1.0 - exp(-2.0*mor))/2.0; 490 | else if (DISTANCE == 2) c = 0.5*(exp(4.0*mor)-1)/(exp(4.0*mor)+1); 491 | if (c>0.5) c=0.5; 492 | g = 1.0/(2.0*c); 493 | 494 | if (tracelevel != 0) 495 | { 496 | if ((s == s1) && (ss == s2)) fprintf(fout, "\n\nSNPs %d-%d qs=%f ps=%f qss=%f pss=%f D=%f D2=%f VV=%f r2=%f c=%f g=%f\n\n", 497 | s, ss, freqs, 1.0-freqs, freqss, 1.0-freqss, D, D2, VV, r2, c, g); 498 | } 499 | 500 | if (tracelevel != 0) 501 | { 502 | fprintf(fout, "SNPs %d-%d qs=%f ps=%f qss=%f pss=%f D=%f D2=%f VV=%f r2=%f c=%f g=%f\n", 503 | s, ss, freqs, 1.0-freqs, freqss, 1.0-freqss, D, D2, VV, r2, c, g); 504 | } 505 | 506 | if ( (freqs*(1.0-freqs) != 0.0) && (freqss*(1.0-freqss) != 0.0) ) 507 | { 508 | for (b=1; b<=NBIN; b++) 509 | if (c != 0.0) 510 | { 511 | if (b==1) 512 | { 513 | if ((g > 0) && (g <= 2)) 514 | { 515 | n_[b] ++; 516 | accum(&AVE_D_[b], D); 517 | accum(&AVE_D2_[b], D2); 518 | accum(&AVE_VV_[b], VV); 519 | accum(&AVE_r2_[b], r2); 520 | accum(&AVE_c_[b], 1.0/c); 521 | } 522 | } 523 | else if (b==2) 524 | { 525 | if ((g > 2) && (g <= 4)) 526 | { 527 | n_[b] ++; 528 | accum(&AVE_D_[b], D); 529 | accum(&AVE_D2_[b], D2); 530 | accum(&AVE_VV_[b], VV); 531 | accum(&AVE_r2_[b], r2); 532 | accum(&AVE_c_[b], 1.0/c); 533 | } 534 | } 535 | else if (b==3) 536 | { 537 | if ((g > 4) && (g <= 6)) 538 | { 539 | n_[b] ++; 540 | accum(&AVE_D_[b], D); 541 | accum(&AVE_D2_[b], D2); 542 | accum(&AVE_VV_[b], VV); 543 | accum(&AVE_r2_[b], r2); 544 | accum(&AVE_c_[b], 1.0/c); 545 | } 546 | } 547 | else if (b==4) 548 | { 549 | if ((g > 6) && (g <= 8)) 550 | { 551 | n_[b] ++; 552 | accum(&AVE_D_[b], D); 553 | accum(&AVE_D2_[b], D2); 554 | accum(&AVE_VV_[b], VV); 555 | accum(&AVE_r2_[b], r2); 556 | accum(&AVE_c_[b], 1.0/c); 557 | } 558 | } 559 | else if (b==5) 560 | { 561 | if ((g > 8) && (g <= 10)) 562 | { 563 | n_[b] ++; 564 | accum(&AVE_D_[b], D); 565 | accum(&AVE_D2_[b], D2); 566 | accum(&AVE_VV_[b], VV); 567 | accum(&AVE_r2_[b], r2); 568 | accum(&AVE_c_[b], 1.0/c); 569 | } 570 | } 571 | else 572 | { 573 | if ( (g > ((NGEN/NBIN)*(b-6))+10) && (g <= ((NGEN/NBIN)*(b-5))+10) ) 574 | { 575 | n_[b] ++; 576 | accum(&AVE_D_[b], D); 577 | accum(&AVE_D2_[b], D2); 578 | accum(&AVE_VV_[b], VV); 579 | accum(&AVE_r2_[b], r2); 580 | accum(&AVE_c_[b], 1.0/c); 581 | } 582 | } 583 | } 584 | } 585 | } 586 | } 587 | 588 | /******* Calculation of Hardy-Weinberg deviation *******/ 589 | 590 | for (s=1; s<=NSNP; s++) 591 | if (calc_SNP[s] == 1) 592 | { 593 | freqs=0.0; freqG11s=0.0; 594 | 595 | numNIND=0; 596 | for (i=1; i<=NIND; i++) 597 | if ((snp[i][s][1] != 0) && (snp[i][s][2] != 0)) 598 | { 599 | numNIND ++; 600 | 601 | if (snp[i][s][1] == 1) freqs ++; 602 | if (snp[i][s][2] == 1) freqs ++; 603 | 604 | if ( (snp[i][s][1] == 1) && (snp[i][s][2] == 1) ) 605 | freqG11s ++; 606 | } 607 | 608 | freqs = freqs/(2.0*numNIND); 609 | freqG11s = freqG11s/numNIND; 610 | 611 | if (freqs*(1.0-freqs) != 0.0) 612 | { 613 | accum(&P_p2, freqG11s-(freqs*freqs)); 614 | accum(&pq, freqs*(1.0-freqs)); 615 | 616 | if (tracelevel != 0) 617 | { 618 | fprintf(fout, "\n****** s=%d *******\n", s); 619 | fprintf(fout, "freqs=%f freqs*(1.0-freqs)=%f\n", freqs, freqs*(1.0-freqs)); 620 | fprintf(fout, "freqG11s=%f freqG11s-(freqs*freqs)=%f\n", freqG11s, freqG11s-(freqs*freqs)); 621 | fprintf(fout, "\n"); 622 | } 623 | } 624 | } 625 | 626 | /* **************************************** */ 627 | 628 | // Table of results 629 | 630 | for (b=1; b<=NBIN; b++) 631 | { 632 | cc_[b] = 1.0/accmean(&AVE_c_[b]); 633 | r2_[b] = accmean(&AVE_r2_[b]); 634 | D2_[b] = accmean(&AVE_D2_[b]); 635 | VV_[b] = accmean(&AVE_VV_[b]); 636 | 637 | // if (NIND == 2) d2_[b] = (D2_[b] / VV_[b]); 638 | // else d2_[b] = ( (D2_[b] / (4.0*VV_[b])) ); 639 | 640 | d2_[b] = (D2_[b] / VV_[b]); 641 | 642 | Ne_r2_[b] = (1.0/(4.0*cc_[b]*r2_[b])) - (1.0/(2.0*cc_[b])); 643 | Ne_d2_[b] = (1.0/(4.0*cc_[b]*d2_[b])) - (1.0/(2.0*cc_[b])); 644 | } 645 | 646 | for (s=1; s<=NSNP; s++) 647 | { 648 | if (allele[s] > 2) snp_m2 ++; 649 | if (all[s][5] > maxCEROS) snp_mZ ++; 650 | } 651 | 652 | f = accmean(&P_p2) / accmean(&pq); 653 | fp = (1.0 + (f*(2.0*NIND - 1.0))) / (2.0*NIND - 1.0 + f); 654 | 655 | fprintf(fpar," NIND(real sample)=%d\n NSNP=%d\n NSNP_calculations=%d\n NSNP_+2alleles=%d\n NSNP_zeroes=%d\n NSNP_monomorphic=%d\n NIND_corrected=%f\n freq_MAF=%f\n F_dev_HW (sample)=%f\n F_dev_HW (pop)=%f\n", 656 | NIND, NSNP, numSNP, snp_m2, snp_mZ, snp_mono, 1.0/accmean(&AVE_numNIND), freq_MAF, f, fp); 657 | 658 | if (TOTAL_DIS == 0.0) fprintf(fpar," No genetic distances; using %f cM per Mb\n\n", cM); 659 | else fprintf(fpar," Genetic distances available in map file\n\n"); 660 | 661 | // OUTFILELD 662 | // if (tracelevel != 0) fprintf(fout,"\nn c d2 g D2 VV\n"); 663 | 664 | fprintf(fout,"%d\n", PHASE); 665 | fprintf(fout,"%d\n", NIND); 666 | fprintf(fout,"%d\n", numSNP); 667 | if (accmean(&AVE_numNIND) > 0) fprintf(fout,"%f\n", 1.0/accmean(&AVE_numNIND)); 668 | else fprintf(fout,"-99\n"); 669 | if ((numSNP > 0)&&(accmean(&pq) > 0)) fprintf(fout,"%f\n", f); 670 | else fprintf(fout,"-99\n"); 671 | // if (numSNP > 0) fprintf(fout,"%f\n", fp); 672 | // else fprintf(fout,"-99\n"); 673 | 674 | for (b=1; b<=NBIN; b++) 675 | { 676 | if (n_[b] == 0) 677 | { 678 | if (b <= 5) fprintf(fout,"0 0 0 %d 0 0\n", 2*b); 679 | else fprintf(fout,"0 0 0 %d 0 0\n", ((NGEN/NBIN)*(b-5))+10); 680 | } 681 | else 682 | { 683 | if (b <= 5) fprintf(fout,"%lld %11.9f %11.9f %d %f %f\n", n_[b], cc_[b], d2_[b], 2*b, D2_[b], VV_[b]); 684 | else fprintf(fout,"%lld %11.9f %11.9f %d %f %f\n", n_[b], cc_[b], d2_[b], ((NGEN/NBIN)*(b-5))+10, D2_[b], VV_[b]); 685 | } 686 | } 687 | 688 | return(0); 689 | } 690 | 691 | /* ********************************************************************************************* */ 692 | -------------------------------------------------------------------------------- /CODES_LINUX/GONE.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // GONE (Genetic Optimization for Ne Estimation) 4 | // 5 | // Created by Enrique Santiago on 12/11/19. 6 | // Copyright © 2019 Enrique Santiago. All rights reserved. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define nlinmax 500 21 | #define ngenmax 2000 22 | 23 | void CalculaSC(); 24 | 25 | double SC; 26 | double nbin[nlinmax]; 27 | double cval[nlinmax]; 28 | double d2cobs[nlinmax]; 29 | double xnbin[nlinmax]; 30 | double xcval[nlinmax]; 31 | double xd2cobs[nlinmax]; 32 | int indx[nlinmax]; 33 | double cval12[nlinmax]; 34 | double cvalrep[nlinmax]; 35 | double cval1masc2[nlinmax]; 36 | double cval2[nlinmax]; 37 | double d2cprd[nlinmax]; 38 | double Neblock[nlinmax]; 39 | int segdesdehasta[nlinmax]; 40 | double Ne[ngenmax]; 41 | double sumNe[ngenmax]; 42 | double d2c; 43 | double Necons, Nemed; 44 | int nlin, gmax,gmax2,gmax3, nsegmentos; 45 | int muestrasalida=10; 46 | int hp=2; 47 | double fval,fvalsample, correccion=1; 48 | double samplex,sampley,sampleZ2,sampleZ3,sampleZ4; 49 | int conta,conta2; 50 | double sample_size=0, sample_size_h=0; 51 | bool flagporbloques=false, flagsolape=true; 52 | double maxdouble=std::numeric_limits< double >::max(); 53 | unsigned long long int semilla=0; 54 | int resolucion, topeposigen,ndes,gen, maxgen,des, ind1,ind2, ind3, posigen, posiblock, ancho1, ancho2; 55 | int ndesini, indexmaxSC,indexminSC, maxsegmentos, posi1,posi2,posi3, contagen, topeposiinicio, topeposiinicio1,topeposiinicio4; 56 | int tercio1, tercio2, tercio12, nhijos,topeposiinicio2,topeposiinicio3; 57 | double efectomut,efectomutlateral, frecmut, frecrec,frecnorec, frecinversion, frecmutlateral, efecto, maxSC, minSC; 58 | double efectomutsuave, SCmed, SCmed2, nsegmed,nsegmed2, SCbest,nsegbest, SCmedanterior,increfval,frecmutfval; 59 | double tope,topesalto,invtopesalto,topesalto2,invtopesalto2; 60 | bool flag; 61 | struct serie { //++ 62 | double efval; //++ 63 | double SCval; //++ 64 | int nseg; //++ 65 | int segbl[nlinmax]; //++ 66 | double Nebl[nlinmax]; //++ 67 | }; //++ 68 | serie bichoP[1000];//++ Parents 69 | serie bichoH[1000];//++ Offspring 70 | serie bicho;//++ 71 | 72 | std::random_device seed; //used to obtain a seed for the random number engine 73 | std::mt19937_64 genera(seed()); // mersenne_twister_engine 64bit (very good but very big) 74 | std::uniform_real_distribution<> uniforme01(0.0, 1.0); //uses the result of the engine to generate uniform dist 75 | 76 | int main(int argc, char* argv[]){ 77 | double a,aa,b,bb,d,maxc, Ne0, increm, producto=1,mincval; 78 | double clow=0, chigh=0.5, minn, sumnbins=0,dpob; 79 | int i,ii,jj, j,imaxc; 80 | int mini, sizebins=1,nbins=50; 81 | bool resizebins=false, flagdebug=false, flagrep=false,flagne=false; 82 | bool lcflag=false,hcflag=false, flagwrong=false, flagnbins=false; 83 | struct tm *loctime; 84 | long tinicio, tfinal; 85 | clock_t tini, tiniabs, tpas; 86 | 87 | if ((argc<2)){ 88 | std::cerr << " Usage: "<< argv[0]<< " [-lc lowest_c_value] [-hc highest_c_value] [-ne number_of_estimates] [-sd seed] [-sr] [-vb] input_file_name [output_file_name]"<20){ 137 | std::cerr <<" Invalid number of estimates to be averaged. It must be from 1 to 20."<< std::endl; 138 | return 1;}} 139 | if (arg == "-bn"|| arg== "--bin-number") { 140 | flagnbins=true; 141 | nbins=std::atoi(argv[i+1]); 142 | if (nbins<15){ 143 | std::cerr <<" Invalid number of bins. It must be larger than 14."<< std::endl; 144 | return 1;}} 145 | if (arg == "-sr") { 146 | flagrep=true;} 147 | if (arg == "-lc"|| arg== "--lowest-c") { 148 | lcflag=true; 149 | clow=std::atof(argv[i+1]); 150 | if (clow<0 || clow>0.5){ 151 | std::cerr <<" Invalid recombination frequency. It must be between 0 and 0.5."<< std::endl; 152 | return 1;}} 153 | if (arg == "-hc"|| arg== "--highest-c") { 154 | hcflag=true; 155 | chigh=std::atof(argv[i+1]); 156 | if (chigh<0 || chigh>0.5){ 157 | std::cerr <<" Invalid recombination frequency. It must be a number between 0 and 0.5."<< std::endl; 158 | return 1;}} 159 | if (arg == "-sd"|| arg== "--seed") { 160 | semilla=std::atoi(argv[i+1]);} 161 | } 162 | if (chigh<=clow){ 163 | std::cerr <<" Invalid range of recombination frequencies."<< std::endl; 164 | return 1;} 165 | 166 | // *************************************************** 167 | i=1; 168 | if (resizebins){i=i+2;} 169 | if (flagne){i=i+2;} 170 | if (flagnbins){i=i+2;} 171 | if (flagrep){i=i+1;} 172 | if (hcflag){i=i+2;} 173 | if (lcflag){i=i+2;} 174 | if (semilla!=0){i=i+2; 175 | genera.seed(semilla);} 176 | if (flagdebug){i=i+1;} 177 | std::string fichero=argv[i]; 178 | std::string fichsal=argv[i]; 179 | if (argc==(i+2)){ 180 | fichsal=argv[i+1];} 181 | 182 | // std::string fichero="ISLAS_KANK2"; 183 | // std::string fichsal="ISLAS_KANK2"; 184 | 185 | std::string fichero_sal_NeH=fichsal+"_GONE_Nebest"; 186 | std::string fichero_sal_d2=fichsal+"_GONE_d2"; 187 | std::string fichero_sal_log=fichsal+"_GONE_log"; 188 | std::string fichero_sal_rearrange=fichsal+"_GONE_input"; 189 | std::string fichero_sal_evol=fichsal+"_GONE_evol"; // --debug 190 | std::string fichero_caca=fichsal+"_GONE_caca"; // --debug 191 | std::ofstream salida; 192 | 193 | if (!lcflag){clow=0.001;} // 194 | tinicio=time(NULL); 195 | loctime=localtime(&tinicio); 196 | std::ifstream entrada; 197 | entrada.open(fichero, std::ios::in); 198 | if (!(entrada.is_open())){ 199 | std::cerr << " Error opening file "<< fichero <<"\n"; 200 | return 1;} 201 | nlin=-3; 202 | std::string line; 203 | while (getline(entrada, line)){ 204 | if (line[0]!='#' && line[0]!='*' && line[0]!='>' && line[0]!='/'){ 205 | std::istringstream iss(line); 206 | if (nlin==-3){ 207 | if (!(iss >> a)){ 208 | std::cerr << " Format error in file "<< fichero<> a)){ 220 | std::cerr << " Format error in file "<< fichero<> a)){ 232 | std::cerr << " Format error in file "<< fichero<1){ 237 | std::cerr <<" Specify a f value in the range -1 and +1."<< std::endl; 238 | return 1;} 239 | fvalsample=a; 240 | nlin++; 241 | } 242 | else{ 243 | if (!(iss >> a >> b >> d)) { 244 | std::cerr << " Format error in file "<< fichero<0.5)){flagwrong=true;} 249 | if ((b>=clow) && (b<=chigh) && (a>0)){ 250 | xnbin[nlin]=a; 251 | xcval[nlin]=b; 252 | xd2cobs[nlin]=d; 253 | indx[nlin]=nlin; 254 | nlin++;} 255 | } 256 | if (nlin==nlinmax){ 257 | break;} 258 | } 259 | } 260 | 261 | for (i=0;i=nlin){break;} 295 | producto=(1.0-xcval[indx[i]])*(1-xcval[indx[i]]); 296 | Ne0=1/((xd2cobs[indx[i]]-1/sample_size)/producto*(1-producto))-2.2*producto/(1-producto); 297 | if (Ne0>10){ 298 | conta+=1; 299 | Nemed+=(Ne0); 300 | } 301 | } 302 | if (conta>0){Nemed=(Nemed/conta);} 303 | else{Nemed=1000;} 304 | if (Nemed<10){Nemed=10;} 305 | //MIRA LA GENERACION MAXIMA QUE TODAVIA CONTIENE UN 5% DE INFORMACION 306 | gmax=int(log10(0.05)/log10(1.0-1.0/Nemed)+.5); 307 | mincval=clow; 308 | 309 | // VA REDUCIENDO HASTA QUE NO HAYA LINEAS CON MENOS DE UN No DE PAREJAS DE SNPs 310 | if (!resizebins){sizebins=10000;} 311 | while (nlin>18){ 312 | // Busca el mínimo 313 | mini=0; 314 | minn=xnbin[indx[mini]]; 315 | for (i=1;ixnbin[indx[i]]){mini=i;minn=xnbin[indx[i]];}} 317 | if (minn>sizebins){break;} 318 | // Mira cual de los adyacentes es el menor 319 | j=mini-1; 320 | jj=mini+1; 321 | if (j<0){j=jj;} 322 | else{ 323 | if (jj>=nlin){j=j;} 324 | else{ 325 | if (xnbin[indx[j]]>xnbin[indx[jj]]){j=jj;}}} 326 | if (jnlin)){nbins=nlin;} 348 | if((producto<30)){nbins=30;} 349 | if (nbins>60){nbins=60;}} //LIMITE EN EL NUMERO DE LINEAS 350 | 351 | //VA REDUCIENDO HASTA DEJAR EL No DE LINEAS 352 | while(nlin>nbins){ 353 | // Busca el mínimo 354 | mini=0; 355 | minn=xnbin[indx[mini]]; 356 | for (i=1;ixnbin[indx[i]]){mini=i;minn=xnbin[indx[i]];}} 358 | // Mira cual de los adyacentes es el menor 359 | j=mini-1; 360 | jj=mini+1; 361 | if (j<0){j=jj;} 362 | else{ 363 | if (jj>=nlin){j=j;} 364 | else{ 365 | if (xnbin[indx[j]]>xnbin[indx[jj]]){j=jj;}}} 366 | if (j0){ 410 | if (hp==0){dpob=4.0*(d2cobs[i]-sampleZ3)/(cvalrep[i]*sampleZ2);} 411 | else if (hp==1){dpob=(d2cobs[i]-sampleZ4)/(cvalrep[i]);} 412 | else {dpob=(d2cobs[i]/((1+fval)*(1+fval))-sampley)/(samplex*cvalrep[i]);} 413 | Ne0=2*(cval1masc2[i]/(dpob*2*(1-cval12[i]))-1.1*cval12[i]/(1-cval12[i])); 414 | if (Ne0>10){ 415 | Nemed=Nemed+Ne0; 416 | conta=conta+1;}} 417 | } 418 | if (conta>0){Nemed=(Nemed/conta);} 419 | else {Nemed=2000;} 420 | if (Nemed<10){Nemed=10;} 421 | entrada.close(); 422 | tiniabs=clock(); 423 | tpas=clock() - tiniabs; 424 | salida.open(fichero_sal_log, std::ios::out); 425 | salida << "(GONE v1.0)\n\n"; 426 | salida << "Input File: "<< fichero <<"\n\n"; 427 | salida << "Command:"; 428 | for (i=0;i(ngenmax-10)){gmax=ngenmax-10;} 444 | gmax2=int(gmax*26/40); 445 | gmax3=gmax2+int((gmax-gmax2)/2); 446 | 447 | // PARAMETROS DE AJUSTE 448 | //************************************************************************************** 449 | //************************************************************************************** 450 | //************************************************************************************** 451 | flagsolape=true; 452 | flagporbloques=true; 453 | resolucion=3; 454 | topeposigen=gmax2-2*resolucion; 455 | topeposiinicio1=60; 456 | topeposiinicio2=120; 457 | topeposiinicio3=240; 458 | topeposiinicio4=480; 459 | if (topeposiinicio1>topeposigen){topeposiinicio1=topeposigen;} 460 | if (topeposiinicio2>topeposigen){topeposiinicio2=topeposigen;} 461 | if (topeposiinicio3>topeposigen){topeposiinicio3=topeposigen;} 462 | if (topeposiinicio4>topeposigen){topeposiinicio4=topeposigen;} 463 | if (topeposiinicio2>topeposigen){topeposiinicio2=topeposigen;} 464 | topeposiinicio=topeposigen; 465 | topesalto=9.0; 466 | invtopesalto=1.0/topesalto; 467 | topesalto2=50; 468 | invtopesalto2=1.0/topesalto2; 469 | maxgen=750; // 470 | ndesini=3000; 471 | ndes=1000; 472 | increfval=0.001; 473 | frecmutfval=0.0; 474 | efectomutsuave=0.02; 475 | frecinversion=0.3; //INVERSION DE LOS DOS ULTIMOS 476 | tercio1=10; // aqui van los mejores reproductores que no se tocan 477 | tercio2=90; // son los siguientes y se sustituyen por hijos si estos son mejores 478 | tercio12=tercio1+tercio2; 479 | nhijos=tercio12; 480 | 481 | 482 | // PRECARGA ALEATORIA CON SELECCION 483 | bicho.efval=fval; //++ 484 | bicho.nseg=4; //++ 485 | bicho.segbl[0]=0; //++ 486 | bicho.segbl[3]=gmax3; //++ 487 | bicho.segbl[4]=gmax; //++ 488 | for (ii=0;iiposi2){posi3=posi1;posi1=posi2;posi2=posi3;} 502 | if ((posi2-posi1)>5){break;}} 503 | bicho.segbl[1]=posi1; //++ 504 | bicho.segbl[2]=posi2; //++ 505 | bicho.Nebl[0]=Nemed; 506 | tope=uniforme01(genera)*2*topesalto; 507 | // tope=topesalto; // ALTERNATIVA A LA LINEA ANTERIOR 508 | for (jj=1;jj<3;++jj){ 509 | aa=1+uniforme01(genera)*(tope); //ERA2 510 | if (uniforme01(genera)<0.66){aa=1/aa;} //ERA0.5 511 | aa=Nemed*aa; 512 | if (aa>10000000){aa=10000000;} 513 | if (aa<5){aa=5;} 514 | bicho.Nebl[jj]=aa; //++ 515 | } 516 | aa=1.0+uniforme01(genera)*tope/2; //era 0.5 517 | aa=Nemed*aa; 518 | if (aa>10000000){aa=10000000;} 519 | if (aa<5){aa=5;} 520 | bicho.Nebl[3]=aa; //++ 521 | CalculaSC(); 522 | bicho.SCval=SC; //++ 523 | // Selecciona los padres 524 | if (iimaxSC){indexmaxSC=jj;maxSC=bichoP[jj].SCval;} 531 | } 532 | if (bicho.SCval "<< gen<<"\t"<< j<<"\t"<topeposiinicio); 603 | } 604 | else{ 605 | posigen=resolucion+int(uniforme01(genera)*topeposiinicio); 606 | } 607 | if (uniforme01(genera)<.5){ //DENTRO: iguala individuos y centra posigen 608 | ind2=ind1; 609 | } 610 | for (jj=0;jj<=bichoP[ind1].nseg;++jj){ 611 | if (abs(bichoP[ind1].segbl[jj]-posigen)<=resolucion){flag=false;break;} 612 | } 613 | if (flag){ 614 | for (jj=0;jj<=bichoP[ind2].nseg;++jj){ 615 | if (abs(bichoP[ind2].segbl[jj]-posigen)<=resolucion){flag=false;break;} 616 | } 617 | } 618 | if (flag){ 619 | ii=0; 620 | for (jj=0;jjposigen){ 631 | bicho.segbl[ii]=posigen; 632 | bicho.Nebl[ii]=bichoP[ind2].Nebl[jj-1]; 633 | ++ii; 634 | break; 635 | } 636 | } 637 | for (jj=1;jjposigen){ 639 | bicho.segbl[ii]=bichoP[ind2].segbl[jj]; 640 | bicho.Nebl[ii]=bichoP[ind2].Nebl[jj]; 641 | ++ii; 642 | } 643 | } 644 | bicho.nseg=ii; 645 | bicho.segbl[ii]=bichoP[ind2].segbl[bichoP[ind2].nseg]; 646 | } 647 | } 648 | else{bicho=bichoP[ind1];} 649 | if (flag){break;} 650 | } 651 | // Fusion de dos bloques con probabilidad frecnorec haciendo la media harmonica de los Ne 652 | if (bicho.nseg>3){ 653 | if ((uniforme01(genera)maxsegmentos)){ 654 | posiblock=int(uniforme01(genera)*(bicho.nseg-2)); //FUSIONA AL AZAR 655 | ancho1=bicho.segbl[posiblock+1]-bicho.segbl[posiblock]; 656 | ancho2=bicho.segbl[posiblock+2]-bicho.segbl[posiblock+1]; // Media harmonica 657 | aa=(ancho1+ancho2)/(ancho1/bicho.Nebl[posiblock]+ancho2/bicho.Nebl[posiblock+1]); 658 | flag=true; 659 | if (posiblock>0){ 660 | bb=aa/bicho.Nebl[posiblock-1]; 661 | // if (bbtopesalto){flag=false;}} 662 | if (bbtopesalto){flag=false;}} 666 | if (bb>topesalto2){flag=false;}} 667 | if (flag){ 668 | bicho.Nebl[posiblock]=aa; 669 | for (jj=posiblock+1;jj<=bicho.nseg;++jj){ 670 | bicho.Nebl[jj]=bicho.Nebl[jj+1]; 671 | bicho.segbl[jj]=bicho.segbl[jj+1]; 672 | } 673 | --bicho.nseg; 674 | } 675 | } 676 | } 677 | // Control del tope de número de segmentos 678 | flag=true; 679 | if ((bicho.nseg>maxsegmentos) || (bicho.nseg<3)){flag=false;} 680 | if (flag){break;} 681 | } 682 | // Mutación: Cambia el valor de ne de segmentos al azar 683 | for (posiblock=0;posiblock0){ 692 | bb=aa/bicho.Nebl[posiblock-1]; 693 | if (bbtopesalto2){flag=false;}} 697 | if (flag){ 698 | if (aa>10000000){aa=10000000;} 699 | if (aa<5){aa=5;} 700 | bicho.Nebl[posiblock]=aa;} 701 | } 702 | // Iguala dos dos ultimos: 703 | aa=bicho.Nebl[bicho.nseg-1]; 704 | bb=bicho.Nebl[bicho.nseg-2]; 705 | if (aa>(bb*1.2)){bicho.Nebl[bicho.nseg-1]=bb*1.2;} 706 | if (aa<(bb/1.2)){bicho.Nebl[bicho.nseg-1]=bb/1.2;} 707 | 708 | for (posiblock=0;posiblockresolucion+efecto){ 720 | bicho.segbl[posiblock]-=efecto;}} 721 | else{ 722 | if ((bicho.segbl[posiblock+1]-bicho.segbl[posiblock])>resolucion+efecto){ 723 | bicho.segbl[posiblock]+=efecto;}} 724 | } 725 | 726 | bicho.efval=bichoP[ind1].efval; 727 | CalculaSC(); 728 | bicho.SCval=SC; //++ 729 | if (desmaxSC){ 736 | maxSC=bichoH[i].SCval; 737 | indexmaxSC=i;}} 738 | if (SC=4){ 773 | posiblock=bicho.nseg-2; 774 | aa=bicho.Nebl[posiblock+1]; 775 | flag=true; 776 | bb=aa/bicho.Nebl[posiblock-1]; 777 | if (bb>invtopesalto && bbgmax){break;} 842 | } 843 | if (conta>gmax){break;} 844 | } 845 | } 846 | 847 | for (i=0;i1){--hastasegmento;} 910 | for (i=0;i0){ 927 | if (exponente & 1){ 928 | Ne12ancho*=Ne12base; 929 | Ne122ancho*=Ne122base; 930 | Ne102ancho*=Ne102base; 931 | cval12ancho*=cval12base;} 932 | Ne12base*=Ne12base; 933 | Ne122base*=Ne122base; 934 | Ne102base*=Ne102base; 935 | cval12base*=cval12base; 936 | exponente>>=1; 937 | } 938 | A=(1-Ne122ancho*cval12ancho)/(1-(Nec122[i])); 939 | B=(1-Ne12ancho)/(1-Ne12[i]); 940 | SD2+=s1*p1a*B+p1b/Neblock[i]*cval12aa*(Ne12[i]*B-Nec122[i]*A)/(Ne12[i]-Nec122[i]); 941 | SW+=p1a*(1-Ne12ancho)/(2/Neblock[i]); 942 | s1+=r1a*cval12aa/Neblock[i]*(1-Ne102ancho*cval12ancho)/(1-Nec102[i]); 943 | r1a*=Ne102ancho; 944 | p1a*=Ne12ancho; 945 | p1b*=Ne122ancho; 946 | cval12aa*=cval12ancho; 947 | } 948 | Aplus=Nec122[nsegmentos-1]/(1-Nec122[nsegmentos-1]); 949 | Bplus=Ne12[nsegmentos-1]*Necons/2; 950 | SD2+=s1*p1a*Necons/2+p1b/Necons*cval12aa*(Bplus-Aplus)/(Ne12[nsegmentos-1]-Nec122[nsegmentos-1]); 951 | SW+=p1a*Necons/2; 952 | d2c=SD2/SW*(cval1masc2[ii]); // Correccion acumulacion diploides *(1+c^2) 953 | 954 | if (hp==2){ // Correccion diploides unphased 955 | d2cprd[ii]=(d2c*cvalrep[ii]*samplex+cval2[ii]/Necons*samplex+sampley)/(correccion);} 956 | else if (hp==1){ // Correccion diploides phased 957 | d2cprd[ii]=(d2c*cvalrep[ii]+sampleZ4);} 958 | else if (hp==0){ // Correccion pseudohaploides 959 | d2cprd[ii]=(d2c/4*cvalrep[ii]*sampleZ2+sampleZ3);} 960 | 961 | } 962 | for (ii=0;ii 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define nlinmax 500 21 | #define ngenmax 2000 22 | 23 | void CalculaSC(); 24 | 25 | double SC; 26 | double nbin[nlinmax]; 27 | double cval[nlinmax]; 28 | double d2cobs[nlinmax]; 29 | double xnbin[nlinmax]; 30 | double xcval[nlinmax]; 31 | double xd2cobs[nlinmax]; 32 | int indx[nlinmax]; 33 | double cval12[nlinmax]; 34 | double cvalrep[nlinmax]; 35 | double cval1masc2[nlinmax]; 36 | double cval2[nlinmax]; 37 | double d2cprd[nlinmax]; 38 | double Neblock[nlinmax]; 39 | int segdesdehasta[nlinmax]; 40 | double Ne[ngenmax]; 41 | double sumNe[ngenmax]; 42 | double d2c; 43 | double Necons, Nemed; 44 | int nlin, gmax,gmax2,gmax3, nsegmentos; 45 | int muestrasalida=10; 46 | int hp=2; 47 | double fval,fvalsample, correccion=1; 48 | double samplex,sampley,sampleZ2,sampleZ3,sampleZ4; 49 | int conta,conta2; 50 | double sample_size=0, sample_size_h=0; 51 | bool flagporbloques=false, flagsolape=true; 52 | double maxdouble=std::numeric_limits< double >::max(); 53 | unsigned long long int semilla=0; 54 | int resolucion, topeposigen,ndes,gen, maxgen,des, ind1,ind2, ind3, posigen, posiblock, ancho1, ancho2; 55 | int ndesini, indexmaxSC,indexminSC, maxsegmentos, posi1,posi2,posi3, contagen, topeposiinicio, topeposiinicio1,topeposiinicio4; 56 | int tercio1, tercio2, tercio12, nhijos,topeposiinicio2,topeposiinicio3; 57 | double efectomut,efectomutlateral, frecmut, frecrec,frecnorec, frecinversion, frecmutlateral, efecto, maxSC, minSC; 58 | double efectomutsuave, SCmed, SCmed2, nsegmed,nsegmed2, SCbest,nsegbest, SCmedanterior,increfval,frecmutfval; 59 | double tope,topesalto,invtopesalto,topesalto2,invtopesalto2; 60 | bool flag; 61 | struct serie { //++ 62 | double efval; //++ 63 | double SCval; //++ 64 | int nseg; //++ 65 | int segbl[nlinmax]; //++ 66 | double Nebl[nlinmax]; //++ 67 | }; //++ 68 | serie bichoP[1000];//++ Parents 69 | serie bichoH[1000];//++ Offspring 70 | serie bicho;//++ 71 | 72 | std::random_device seed; //used to obtain a seed for the random number engine 73 | std::mt19937_64 genera(seed()); // mersenne_twister_engine 64bit (very good but very big) 74 | std::uniform_real_distribution<> uniforme01(0.0, 1.0); //uses the result of the engine to generate uniform dist 75 | 76 | int main(int argc, char* argv[]){ 77 | double a,aa,b,bb,d,maxc, Ne0, increm, producto=1,mincval; 78 | double clow=0, chigh=0.5, minn, sumnbins=0,dpob; 79 | int i,ii,jj, j,imaxc; 80 | int mini, sizebins=1,nbins=50; 81 | bool resizebins=false, flagdebug=false, flagrep=false,flagne=false; 82 | bool lcflag=false,hcflag=false, flagwrong=false, flagnbins=false; 83 | struct tm *loctime; 84 | long tinicio, tfinal; 85 | clock_t tini, tiniabs, tpas; 86 | 87 | if ((argc<2)){ 88 | std::cerr << " Usage: "<< argv[0]<< " [-lc lowest_c_value] [-hc highest_c_value] [-ne number_of_estimates] [-sd seed] [-sr] [-vb] input_file_name [output_file_name]"<20){ 137 | std::cerr <<" Invalid number of estimates to be averaged. It must be from 1 to 20."<< std::endl; 138 | return 1;}} 139 | if (arg == "-bn"|| arg== "--bin-number") { 140 | flagnbins=true; 141 | nbins=std::atoi(argv[i+1]); 142 | if (nbins<15){ 143 | std::cerr <<" Invalid number of bins. It must be larger than 14."<< std::endl; 144 | return 1;}} 145 | if (arg == "-sr") { 146 | flagrep=true;} 147 | if (arg == "-lc"|| arg== "--lowest-c") { 148 | lcflag=true; 149 | clow=std::atof(argv[i+1]); 150 | if (clow<0 || clow>0.5){ 151 | std::cerr <<" Invalid recombination frequency. It must be between 0 and 0.5."<< std::endl; 152 | return 1;}} 153 | if (arg == "-hc"|| arg== "--highest-c") { 154 | hcflag=true; 155 | chigh=std::atof(argv[i+1]); 156 | if (chigh<0 || chigh>0.5){ 157 | std::cerr <<" Invalid recombination frequency. It must be a number between 0 and 0.5."<< std::endl; 158 | return 1;}} 159 | if (arg == "-sd"|| arg== "--seed") { 160 | semilla=std::atoi(argv[i+1]);} 161 | } 162 | if (chigh<=clow){ 163 | std::cerr <<" Invalid range of recombination frequencies."<< std::endl; 164 | return 1;} 165 | 166 | // *************************************************** 167 | i=1; 168 | if (resizebins){i=i+2;} 169 | if (flagne){i=i+2;} 170 | if (flagnbins){i=i+2;} 171 | if (flagrep){i=i+1;} 172 | if (hcflag){i=i+2;} 173 | if (lcflag){i=i+2;} 174 | if (semilla!=0){i=i+2; 175 | genera.seed(semilla);} 176 | if (flagdebug){i=i+1;} 177 | std::string fichero=argv[i]; 178 | std::string fichsal=argv[i]; 179 | if (argc==(i+2)){ 180 | fichsal=argv[i+1];} 181 | 182 | // std::string fichero="ISLAS_KANK2"; 183 | // std::string fichsal="ISLAS_KANK2"; 184 | 185 | std::string fichero_sal_NeH=fichsal+"_GONE_Nebest"; 186 | std::string fichero_sal_d2=fichsal+"_GONE_d2"; 187 | std::string fichero_sal_log=fichsal+"_GONE_log"; 188 | std::string fichero_sal_rearrange=fichsal+"_GONE_input"; 189 | std::string fichero_sal_evol=fichsal+"_GONE_evol"; // --debug 190 | std::string fichero_caca=fichsal+"_GONE_caca"; // --debug 191 | std::ofstream salida; 192 | 193 | if (!lcflag){clow=0.001;} // 194 | tinicio=time(NULL); 195 | loctime=localtime(&tinicio); 196 | std::ifstream entrada; 197 | entrada.open(fichero, std::ios::in); 198 | if (!(entrada.is_open())){ 199 | std::cerr << " Error opening file "<< fichero <<"\n"; 200 | return 1;} 201 | nlin=-3; 202 | std::string line; 203 | while (getline(entrada, line)){ 204 | if (line[0]!='#' && line[0]!='*' && line[0]!='>' && line[0]!='/'){ 205 | std::istringstream iss(line); 206 | if (nlin==-3){ 207 | if (!(iss >> a)){ 208 | std::cerr << " Format error in file "<< fichero<> a)){ 220 | std::cerr << " Format error in file "<< fichero<> a)){ 232 | std::cerr << " Format error in file "<< fichero<1){ 237 | std::cerr <<" Specify a f value in the range -1 and +1."<< std::endl; 238 | return 1;} 239 | fvalsample=a; 240 | nlin++; 241 | } 242 | else{ 243 | if (!(iss >> a >> b >> d)) { 244 | std::cerr << " Format error in file "<< fichero<0.5)){flagwrong=true;} 249 | if ((b>=clow) && (b<=chigh) && (a>0)){ 250 | xnbin[nlin]=a; 251 | xcval[nlin]=b; 252 | xd2cobs[nlin]=d; 253 | indx[nlin]=nlin; 254 | nlin++;} 255 | } 256 | if (nlin==nlinmax){ 257 | break;} 258 | } 259 | } 260 | 261 | for (i=0;i=nlin){break;} 295 | producto=(1.0-xcval[indx[i]])*(1-xcval[indx[i]]); 296 | Ne0=1/((xd2cobs[indx[i]]-1/sample_size)/producto*(1-producto))-2.2*producto/(1-producto); 297 | if (Ne0>10){ 298 | conta+=1; 299 | Nemed+=(Ne0); 300 | } 301 | } 302 | if (conta>0){Nemed=(Nemed/conta);} 303 | else{Nemed=1000;} 304 | if (Nemed<10){Nemed=10;} 305 | //MIRA LA GENERACION MAXIMA QUE TODAVIA CONTIENE UN 5% DE INFORMACION 306 | gmax=int(log10(0.05)/log10(1.0-1.0/Nemed)+.5); 307 | mincval=clow; 308 | 309 | // VA REDUCIENDO HASTA QUE NO HAYA LINEAS CON MENOS DE UN No DE PAREJAS DE SNPs 310 | if (!resizebins){sizebins=10000;} 311 | while (nlin>18){ 312 | // Busca el mínimo 313 | mini=0; 314 | minn=xnbin[indx[mini]]; 315 | for (i=1;ixnbin[indx[i]]){mini=i;minn=xnbin[indx[i]];}} 317 | if (minn>sizebins){break;} 318 | // Mira cual de los adyacentes es el menor 319 | j=mini-1; 320 | jj=mini+1; 321 | if (j<0){j=jj;} 322 | else{ 323 | if (jj>=nlin){j=j;} 324 | else{ 325 | if (xnbin[indx[j]]>xnbin[indx[jj]]){j=jj;}}} 326 | if (jnlin)){nbins=nlin;} 348 | if((producto<30)){nbins=30;} 349 | if (nbins>60){nbins=60;}} //LIMITE EN EL NUMERO DE LINEAS 350 | 351 | //VA REDUCIENDO HASTA DEJAR EL No DE LINEAS 352 | while(nlin>nbins){ 353 | // Busca el mínimo 354 | mini=0; 355 | minn=xnbin[indx[mini]]; 356 | for (i=1;ixnbin[indx[i]]){mini=i;minn=xnbin[indx[i]];}} 358 | // Mira cual de los adyacentes es el menor 359 | j=mini-1; 360 | jj=mini+1; 361 | if (j<0){j=jj;} 362 | else{ 363 | if (jj>=nlin){j=j;} 364 | else{ 365 | if (xnbin[indx[j]]>xnbin[indx[jj]]){j=jj;}}} 366 | if (j0){ 410 | if (hp==0){dpob=4.0*(d2cobs[i]-sampleZ3)/(cvalrep[i]*sampleZ2);} 411 | else if (hp==1){dpob=(d2cobs[i]-sampleZ4)/(cvalrep[i]);} 412 | else {dpob=(d2cobs[i]/((1+fval)*(1+fval))-sampley)/(samplex*cvalrep[i]);} 413 | Ne0=2*(cval1masc2[i]/(dpob*2*(1-cval12[i]))-1.1*cval12[i]/(1-cval12[i])); 414 | if (Ne0>10){ 415 | Nemed=Nemed+Ne0; 416 | conta=conta+1;}} 417 | } 418 | if (conta>0){Nemed=(Nemed/conta);} 419 | else {Nemed=2000;} 420 | if (Nemed<10){Nemed=10;} 421 | entrada.close(); 422 | tiniabs=clock(); 423 | tpas=clock() - tiniabs; 424 | salida.open(fichero_sal_log, std::ios::out); 425 | salida << "(GONE v1.0)\n\n"; 426 | salida << "Input File: "<< fichero <<"\n\n"; 427 | salida << "Command:"; 428 | for (i=0;i(ngenmax-10)){gmax=ngenmax-10;} 444 | gmax2=int(gmax*26/40); 445 | gmax3=gmax2+int((gmax-gmax2)/2); 446 | 447 | // PARAMETROS DE AJUSTE 448 | //************************************************************************************** 449 | //************************************************************************************** 450 | //************************************************************************************** 451 | flagsolape=true; 452 | flagporbloques=true; 453 | resolucion=3; 454 | topeposigen=gmax2-2*resolucion; 455 | topeposiinicio1=60; 456 | topeposiinicio2=120; 457 | topeposiinicio3=240; 458 | topeposiinicio4=480; 459 | if (topeposiinicio1>topeposigen){topeposiinicio1=topeposigen;} 460 | if (topeposiinicio2>topeposigen){topeposiinicio2=topeposigen;} 461 | if (topeposiinicio3>topeposigen){topeposiinicio3=topeposigen;} 462 | if (topeposiinicio4>topeposigen){topeposiinicio4=topeposigen;} 463 | if (topeposiinicio2>topeposigen){topeposiinicio2=topeposigen;} 464 | topeposiinicio=topeposigen; 465 | topesalto=9.0; 466 | invtopesalto=1.0/topesalto; 467 | topesalto2=50; 468 | invtopesalto2=1.0/topesalto2; 469 | maxgen=750; // 470 | ndesini=3000; 471 | ndes=1000; 472 | increfval=0.001; 473 | frecmutfval=0.0; 474 | efectomutsuave=0.02; 475 | frecinversion=0.3; //INVERSION DE LOS DOS ULTIMOS 476 | tercio1=10; // aqui van los mejores reproductores que no se tocan 477 | tercio2=90; // son los siguientes y se sustituyen por hijos si estos son mejores 478 | tercio12=tercio1+tercio2; 479 | nhijos=tercio12; 480 | 481 | 482 | // PRECARGA ALEATORIA CON SELECCION 483 | bicho.efval=fval; //++ 484 | bicho.nseg=4; //++ 485 | bicho.segbl[0]=0; //++ 486 | bicho.segbl[3]=gmax3; //++ 487 | bicho.segbl[4]=gmax; //++ 488 | for (ii=0;iiposi2){posi3=posi1;posi1=posi2;posi2=posi3;} 502 | if ((posi2-posi1)>5){break;}} 503 | bicho.segbl[1]=posi1; //++ 504 | bicho.segbl[2]=posi2; //++ 505 | bicho.Nebl[0]=Nemed; 506 | tope=uniforme01(genera)*2*topesalto; 507 | // tope=topesalto; // ALTERNATIVA A LA LINEA ANTERIOR 508 | for (jj=1;jj<3;++jj){ 509 | aa=1+uniforme01(genera)*(tope); //ERA2 510 | if (uniforme01(genera)<0.66){aa=1/aa;} //ERA0.5 511 | aa=Nemed*aa; 512 | if (aa>10000000){aa=10000000;} 513 | if (aa<5){aa=5;} 514 | bicho.Nebl[jj]=aa; //++ 515 | } 516 | aa=1.0+uniforme01(genera)*tope/2; //era 0.5 517 | aa=Nemed*aa; 518 | if (aa>10000000){aa=10000000;} 519 | if (aa<5){aa=5;} 520 | bicho.Nebl[3]=aa; //++ 521 | CalculaSC(); 522 | bicho.SCval=SC; //++ 523 | // Selecciona los padres 524 | if (iimaxSC){indexmaxSC=jj;maxSC=bichoP[jj].SCval;} 531 | } 532 | if (bicho.SCval "<< gen<<"\t"<< j<<"\t"<topeposiinicio); 603 | } 604 | else{ 605 | posigen=resolucion+int(uniforme01(genera)*topeposiinicio); 606 | } 607 | if (uniforme01(genera)<.5){ //DENTRO: iguala individuos y centra posigen 608 | ind2=ind1; 609 | } 610 | for (jj=0;jj<=bichoP[ind1].nseg;++jj){ 611 | if (abs(bichoP[ind1].segbl[jj]-posigen)<=resolucion){flag=false;break;} 612 | } 613 | if (flag){ 614 | for (jj=0;jj<=bichoP[ind2].nseg;++jj){ 615 | if (abs(bichoP[ind2].segbl[jj]-posigen)<=resolucion){flag=false;break;} 616 | } 617 | } 618 | if (flag){ 619 | ii=0; 620 | for (jj=0;jjposigen){ 631 | bicho.segbl[ii]=posigen; 632 | bicho.Nebl[ii]=bichoP[ind2].Nebl[jj-1]; 633 | ++ii; 634 | break; 635 | } 636 | } 637 | for (jj=1;jjposigen){ 639 | bicho.segbl[ii]=bichoP[ind2].segbl[jj]; 640 | bicho.Nebl[ii]=bichoP[ind2].Nebl[jj]; 641 | ++ii; 642 | } 643 | } 644 | bicho.nseg=ii; 645 | bicho.segbl[ii]=bichoP[ind2].segbl[bichoP[ind2].nseg]; 646 | } 647 | } 648 | else{bicho=bichoP[ind1];} 649 | if (flag){break;} 650 | } 651 | // Fusion de dos bloques con probabilidad frecnorec haciendo la media harmonica de los Ne 652 | if (bicho.nseg>3){ 653 | if ((uniforme01(genera)maxsegmentos)){ 654 | posiblock=int(uniforme01(genera)*(bicho.nseg-2)); //FUSIONA AL AZAR 655 | ancho1=bicho.segbl[posiblock+1]-bicho.segbl[posiblock]; 656 | ancho2=bicho.segbl[posiblock+2]-bicho.segbl[posiblock+1]; // Media harmonica 657 | aa=(ancho1+ancho2)/(ancho1/bicho.Nebl[posiblock]+ancho2/bicho.Nebl[posiblock+1]); 658 | flag=true; 659 | if (posiblock>0){ 660 | bb=aa/bicho.Nebl[posiblock-1]; 661 | // if (bbtopesalto){flag=false;}} 662 | if (bbtopesalto){flag=false;}} 666 | if (bb>topesalto2){flag=false;}} 667 | if (flag){ 668 | bicho.Nebl[posiblock]=aa; 669 | for (jj=posiblock+1;jj<=bicho.nseg;++jj){ 670 | bicho.Nebl[jj]=bicho.Nebl[jj+1]; 671 | bicho.segbl[jj]=bicho.segbl[jj+1]; 672 | } 673 | --bicho.nseg; 674 | } 675 | } 676 | } 677 | // Control del tope de número de segmentos 678 | flag=true; 679 | if ((bicho.nseg>maxsegmentos) || (bicho.nseg<3)){flag=false;} 680 | if (flag){break;} 681 | } 682 | // Mutación: Cambia el valor de ne de segmentos al azar 683 | for (posiblock=0;posiblock0){ 692 | bb=aa/bicho.Nebl[posiblock-1]; 693 | if (bbtopesalto2){flag=false;}} 697 | if (flag){ 698 | if (aa>10000000){aa=10000000;} 699 | if (aa<5){aa=5;} 700 | bicho.Nebl[posiblock]=aa;} 701 | } 702 | // Iguala dos dos ultimos: 703 | aa=bicho.Nebl[bicho.nseg-1]; 704 | bb=bicho.Nebl[bicho.nseg-2]; 705 | if (aa>(bb*1.2)){bicho.Nebl[bicho.nseg-1]=bb*1.2;} 706 | if (aa<(bb/1.2)){bicho.Nebl[bicho.nseg-1]=bb/1.2;} 707 | 708 | for (posiblock=0;posiblockresolucion+efecto){ 720 | bicho.segbl[posiblock]-=efecto;}} 721 | else{ 722 | if ((bicho.segbl[posiblock+1]-bicho.segbl[posiblock])>resolucion+efecto){ 723 | bicho.segbl[posiblock]+=efecto;}} 724 | } 725 | 726 | bicho.efval=bichoP[ind1].efval; 727 | CalculaSC(); 728 | bicho.SCval=SC; //++ 729 | if (desmaxSC){ 736 | maxSC=bichoH[i].SCval; 737 | indexmaxSC=i;}} 738 | if (SC=4){ 773 | posiblock=bicho.nseg-2; 774 | aa=bicho.Nebl[posiblock+1]; 775 | flag=true; 776 | bb=aa/bicho.Nebl[posiblock-1]; 777 | if (bb>invtopesalto && bbgmax){break;} 842 | } 843 | if (conta>gmax){break;} 844 | } 845 | } 846 | 847 | for (i=0;i1){--hastasegmento;} 910 | for (i=0;i0){ 927 | if (exponente & 1){ 928 | Ne12ancho*=Ne12base; 929 | Ne122ancho*=Ne122base; 930 | Ne102ancho*=Ne102base; 931 | cval12ancho*=cval12base;} 932 | Ne12base*=Ne12base; 933 | Ne122base*=Ne122base; 934 | Ne102base*=Ne102base; 935 | cval12base*=cval12base; 936 | exponente>>=1; 937 | } 938 | A=(1-Ne122ancho*cval12ancho)/(1-(Nec122[i])); 939 | B=(1-Ne12ancho)/(1-Ne12[i]); 940 | SD2+=s1*p1a*B+p1b/Neblock[i]*cval12aa*(Ne12[i]*B-Nec122[i]*A)/(Ne12[i]-Nec122[i]); 941 | SW+=p1a*(1-Ne12ancho)/(2/Neblock[i]); 942 | s1+=r1a*cval12aa/Neblock[i]*(1-Ne102ancho*cval12ancho)/(1-Nec102[i]); 943 | r1a*=Ne102ancho; 944 | p1a*=Ne12ancho; 945 | p1b*=Ne122ancho; 946 | cval12aa*=cval12ancho; 947 | } 948 | Aplus=Nec122[nsegmentos-1]/(1-Nec122[nsegmentos-1]); 949 | Bplus=Ne12[nsegmentos-1]*Necons/2; 950 | SD2+=s1*p1a*Necons/2+p1b/Necons*cval12aa*(Bplus-Aplus)/(Ne12[nsegmentos-1]-Nec122[nsegmentos-1]); 951 | SW+=p1a*Necons/2; 952 | d2c=SD2/SW*(cval1masc2[ii]); // Correccion acumulacion diploides *(1+c^2) 953 | 954 | if (hp==2){ // Correccion diploides unphased 955 | d2cprd[ii]=(d2c*cvalrep[ii]*samplex+cval2[ii]/Necons*samplex+sampley)/(correccion);} 956 | else if (hp==1){ // Correccion diploides phased 957 | d2cprd[ii]=(d2c*cvalrep[ii]+sampleZ4);} 958 | else if (hp==0){ // Correccion pseudohaploides 959 | d2cprd[ii]=(d2c/4*cvalrep[ii]*sampleZ2+sampleZ3);} 960 | 961 | } 962 | for (ii=0;ii