annotate genome_diversity/src/Fst_ave.c @ 22:95a05c1ef5d5

update to devshed revision aaece207bd01
author Richard Burhans <burhans@bx.psu.edu>
date Mon, 11 Mar 2013 11:28:06 -0400
parents fa34d259eb8f
children 248b06e86022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
1 /* Fst_ave -- determine four FST values between two specified populations,
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
2 * and optionally between several pairs of random populations
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
3 *
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
4 * argv{1] = a Galaxy SNP table. For each of several individuals, the table
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
5 * has four columns (#A, #B, genotype, quality).
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
6 * argv[2] = 1 if FST is estimated from SAMtools genotypes; 0 means use
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
7 * read-coverage data.
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
8 * argv[3] = lower bound, for individual quality value if argv[2] = 1,
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
9 * or for total number of reads per population if argv[2] = 0.
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
10 * SNPs not satisfying these lower bounds are ignored.
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
11 * argv[4] = 1 to discard SNPs that appear fixed in the two populations
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
12 * argv[5] = k says report the maximum and average FST over k randomly
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
13 * chosen splits into two populations of two original sizes
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
14 * argv[6], argv[7], ..., have the form "13:1", "13:2" or "13:0", meaning
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
15 * that the 13th and 14th columns (base 1) give the allele counts
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
16 * (and column 15 gives the genotype) for an individual that is in
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
17 * population 1, in population 2, or in neither population.
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
18
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
19 What it does on Galaxy
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
20
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
21 The user specifies a SNP table and two "populations" of individuals, both previously defined using the Galaxy tool to specify individuals from a SNP table. No individual can be in both populations. Other choices are as follows.
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
22
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
23 Data source. The allele frequencies of a SNP in the two populations can be estimated either by the total number of reads of each allele, or by adding the frequencies inferred from genotypes of individuals in the populations.
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
24
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
25 After specifying the data source, the user sets lower bounds on amount of data required at a SNP. For estimating the FST using read counts, the bound is the minimum count of reads of the two alleles in a population. For estimations based on genotype, the bound is the minimum reported genotype quality per individual. SMPs not meeting these lower bounds are ignored.
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
26
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
27 The user specifies whether SNPs where both populations appear to be fixed for the same allele should be retained or discarded.
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
28
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
29 Finally, the user decides whether to use randomizations. If so, then the user specifies how many randomly generated population pairs (retaining the numbers of individuals of the originals) to generate, as well as the "population" of additional individuals (not in the first two populations) that can be used in the randomization process.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
30
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
31 The program prints the following measures of FST for the two populations.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
32 1. The formulation by Sewall Wright (average over FSTs for all SNPs).
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
33 2. The Weir-Cockerham estimator (average over FSTs for all SNPs).
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
34 3. The Reich-Patterson estimator (average over FSTs for all SNPs).
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
35 4. The population-based Reich-Patterson estimator.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
36
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
37 If randomizations were requested, it prints a summary for each of the four definitions of FST that includes the maximum and average value, and the highest-scoring population pair (if any scored higher than the two user-specified populations).
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
38
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
39 References:
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
40
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
41 Sewall Wright (1951) The genetical structure of populations. Ann Eugen 15:323-354.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
42
19
fa34d259eb8f Removed unicode from Fst_ave.c
miller-lab
parents: 18
diff changeset
43 B. S. Weir and C. Clark Cockerham (1984) Estimating F-statistics for the analysis of population structure. Evolution 38:1358-1370.
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
44
19
fa34d259eb8f Removed unicode from Fst_ave.c
miller-lab
parents: 18
diff changeset
45 Weir, B.S. 1996. Population substructure. Genetic data analysis II, pp. 161-173. Sinauer Associates, Sunderland, MA.
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
46
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
47 David Reich, Kumarasamy Thangaraj, Nick Patterson, Alkes L. Price, and Lalji Singh (2009) Reconstructing Indian population history. Nature 461:489-494, especially Supplement 2.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
48
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
49 Their effectiveness for computing FSTs when there are many SNPs but few individuals is discussed in the followoing paper.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
50
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
51 Eva-Maria Willing, Christine Dreyer, Cock van Oosterhout (2012) Estimates of genetic differentiation measured by FST do not necessarily require large sample sizes when using many SNP markers. PLoS One 7:e42649.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
52
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
53 */
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
54
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
55 #include "lib.h"
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
56 #include "Fst_lib.h"
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
57
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
58 // maximum length of a line from the table
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
59 #define MOST 5000
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
60
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
61 // information about the specified individuals
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
62 // x is an array of nI values 0, 1, or 2;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
63 // shuffling x creates random "populations"
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
64 int col[MOST], x[MOST];
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
65 int nI, lower_bound, discard, genotypes, nsnp, nfail;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
66 double F_wright, F_weir, F_reich, N_reich, D_reich;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
67
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
68 // each SNP has an array of counts
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
69 struct count {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
70 int A, B;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
71 };
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
72
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
73 // linked list summarizes the Galaxy table
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
74 struct snp {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
75 struct count *c;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
76 struct snp *next;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
77 } *start, *last;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
78
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
79 /* For each of wright, weir and reich, we observe allele counts A1 and A2
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
80 * for one allele in the two populations, and B1 and B2 for the other allele.
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
81 */
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
82
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
83 // given the two populations specified by x[], compute four corresponding FSTs
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
84 void pop_Fst() {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
85 double N, D;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
86 struct snp *s;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
87 int i, A1, B1, A2, B2, too_few;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
88
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
89
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
90 // scan the SNPs
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
91 F_wright = F_weir = F_reich = N_reich = D_reich = 0.0;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
92 nsnp = nfail = 0;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
93 for (s = start; s != NULL; s = s->next) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
94 // get counts for the two populations at this SNP
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
95 for (A1 = B1 = A2 = B2 = i = 0; i < nI; ++i) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
96 if (s->c[i].A < 0) // no genotypes
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
97 continue;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
98 if (x[i] == 1) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
99 A1 += s->c[i].A;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
100 B1 += s->c[i].B;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
101 } else if (x[i] == 2) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
102 A2 += s->c[i].A;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
103 B2 += s->c[i].B;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
104 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
105 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
106 if (discard && ((A1 == 0 && A2 == 0) || (B1 == 0 && B2 == 0)))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
107 continue; // fixed in these two populations
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
108 too_few = (genotypes ? 1 : lower_bound);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
109 if (A1+B1 >= too_few && A2+B2 >= too_few) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
110 ++nsnp;
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
111 wright(A1, A2, B1, B2, &N, &D);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
112 if (D != 0.0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
113 F_wright += N/D;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
114 else
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
115 ++nfail;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
116 weir(A1, A2, B1, B2, &N, &D);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
117 if (D != 0.0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
118 F_weir += N/D;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
119 else
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
120 ++nfail;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
121 reich(A1, A2, B1, B2, &N, &D);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
122 N_reich += N;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
123 D_reich += D;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
124 if (D != 0.0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
125 F_reich += N/D;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
126 else
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
127 ++nfail;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
128 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
129 }
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
130 F_wright /= nsnp;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
131 F_weir /= nsnp;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
132 N_reich /= nsnp;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
133 D_reich /= nsnp;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
134 F_reich /= nsnp;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
135 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
136
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
137 /* shuffle the values x[0], x[1], ... , x[nI-1];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
138 * Uses Algorithm P in page 125 of "The Art of Computer Programming (Vol II)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
139 * Seminumerical Programming", by Donald Knuth, Addison-Wesley, 1971.
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
140 */
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
141 void shuffle() {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
142 int i, j, temp;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
143
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
144 for (i = nI - 1; i > 0; --i) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
145 // swap what's in location i with location j, where 0 <= j <= i
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
146 j = random() % (i+1);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
147 temp = x[i];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
148 x[i] = x[j];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
149 x[j] = temp;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
150 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
151 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
152
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
153 int main(int argc, char **argv) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
154 FILE *fp;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
155 char *p, *z = "\t\n", buf[MOST];
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
156 int X[MOST], nshuff, n, i, j, k, saw[3], larger0, larger1, larger2,
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
157 larger3, best_x0[MOST], best_x1[MOST], best_x2[MOST], best_x3[MOST];
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
158 struct snp *new;
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
159 double F, F0, F1, F2, F3, tot_F0, tot_F1, tot_F2, tot_F3,
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
160 largest_F0, largest_F1, largest_F2, largest_F3;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
161
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
162 if (argc < 7)
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
163 fatal("args: table data-source lower_bound discard? #shuffles n:1 m:2 ...");
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
164
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
165 // handle command-line arguments
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
166 genotypes = atoi(argv[2]);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
167 lower_bound = atoi(argv[3]);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
168 if (!genotypes && lower_bound <= 0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
169 fatal("minimum coverage should exceed 0");
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
170 discard = atoi(argv[4]);
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
171 nshuff = atoi(argv[5]);
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
172 saw[0] = saw[1] = saw[2] = 0;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
173 // populations 1 and 2 must be disjoint
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
174 for (i = 6; i < argc; ++i) {
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
175 if (sscanf(argv[i], "%d:%d", &j, &k) != 2)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
176 fatalf("not like 13:2 : %s", argv[i]);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
177 if (k < 0 || k > 2)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
178 fatalf("not population 0, 1 or 2: %s", argv[i]);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
179 saw[k] = 1;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
180 // seen this individual (i.e., column) before??
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
181 for (n = 0; n < nI && col[n] != j; ++n)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
182 ;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
183 if (n < nI) { // OK if one of the populations is 0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
184 if (k > 0) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
185 if (x[n] > 0 && x[n] != k)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
186 fatalf("column %d is in both populations", j);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
187 x[n] = k;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
188 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
189 } else {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
190 col[nI] = j;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
191 x[nI] = k;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
192 ++nI;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
193 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
194 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
195 if (saw[1] == 0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
196 fatal("population 1 is empty");
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
197 if (saw[2] == 0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
198 fatal("population 2 is empty");
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
199
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
200 // read the table of SNPs and store the essential allele counts
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
201 fp = ckopen(argv[1], "r");
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
202 while (fgets(buf, MOST, fp)) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
203 if (buf[0] == '#')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
204 continue;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
205 new = ckalloc(sizeof(*new));
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
206 new->next = NULL;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
207 new->c = ckalloc(nI*sizeof(struct count));
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
208 // set X[i] = atoi(i-th word of buf), i is base 1
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
209 for (i = 1, p = strtok(buf, z); p != NULL;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
210 ++i, p = strtok(NULL, z))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
211 X[i] = atoi(p);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
212 for (i = 0; i < nI; ++i) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
213 n = col[i];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
214 if (genotypes) {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
215 k = X[n+2];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
216 if (k == -1 || X[n+3] < lower_bound)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
217 new->c[i].A = new->c[i].B = -1;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
218 else {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
219 new->c[i].A = k;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
220 new->c[i].B = 2 - k;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
221 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
222 } else {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
223 new->c[i].A = X[n];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
224 new->c[i].B = X[n+1];
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
225 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
226 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
227 if (start == NULL)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
228 start = new;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
229 else
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
230 last->next = new;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
231 last = new;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
232 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
233 fclose(fp);
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
234
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
235 pop_Fst();
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
236 printf("Using %d SNPs, we compute:\n", nsnp);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
237 printf("Average Reich-Patterson FST is %5.5f.\n", F2 = F_reich);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
238 printf("The population-based Reich-Patterson Fst is %5.5f.\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
239 F3 = N_reich/D_reich);
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents: 19
diff changeset
240 printf("Average Wright FST is %5.5f.\n", F0 = F_wright);
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents: 19
diff changeset
241 printf("Average Weir-Cockerham FST is %5.5f.\n", F1 = F_weir);
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
242 if (nfail > 0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
243 printf("WARNING: %d of %d FSTs could not be computed\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
244 nfail, 3*nsnp);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
245 if (nshuff == 0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
246 return 0;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
247
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
248 // do the following only if randomization is requested
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
249 for (j = 0; j < nI; ++j)
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
250 best_x0[j] = best_x1[j] = best_x2[j] = best_x3[j] = x[j];
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
251 tot_F0 = tot_F1 = tot_F2 = tot_F3 =
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
252 largest_F0 = largest_F1 = largest_F2 = largest_F3 = 0.0;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
253 larger0 = larger1 = larger2 = larger3 = 0;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
254 for (i = 0; i < nshuff; ++i) {
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
255 shuffle();
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
256 pop_Fst();
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
257
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
258 // Wright
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
259 if ((F = F_wright) > F0)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
260 ++larger0;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
261 if (F > largest_F0) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
262 largest_F0 = F;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
263 for (j = 0; j < nI; ++j)
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
264 best_x0[j] = x[j];
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
265 }
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
266 tot_F0 += F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
267 /*
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
268 if (all) // make this optional?
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
269 printf("%d: %f\n", i+1, F);
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
270 */
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
271
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
272 // Weir
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
273 if ((F = F_weir) > F1)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
274 ++larger1;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
275 if (F > largest_F1) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
276 largest_F1 = F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
277 for (j = 0; j < nI; ++j)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
278 best_x1[j] = x[j];
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
279 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
280 tot_F1 += F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
281
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
282 // Riech average
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
283 if ((F = F_reich) > F2)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
284 ++larger2;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
285 if (F > largest_F2) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
286 largest_F2 = F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
287 for (j = 0; j < nI; ++j)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
288 best_x2[j] = x[j];
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
289 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
290 tot_F2 += F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
291
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
292 // Reich population
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
293 if ((F = (N_reich/D_reich)) > F3)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
294 ++larger3;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
295 if (F > largest_F3) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
296 largest_F3 = F;
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
297 for (j = 0; j < nI; ++j)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
298 best_x3[j] = x[j];
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
299 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
300 tot_F3 += F;
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
301 }
18
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
302 printf("\nOf %d random groupings:\n", nshuff);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
303 printf("%d had a larger average Wright FST (max %5.5f, mean %5.5f)\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
304 larger0, largest_F0, tot_F0/nshuff);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
305 if (largest_F0 > F0) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
306 printf("first columns for the best two populations:\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
307 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
308 if (best_x0[i] == 1)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
309 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
310 printf("and\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
311 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
312 if (best_x0[i] == 2)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
313 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
314 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
315 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
316 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
317 printf("%d had a larger average Weir-Cockerham FST (max %5.5f, mean %5.5f)\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
318 larger1, largest_F1, tot_F1/nshuff);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
319 if (largest_F1 > F1) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
320 printf("first columns for the best two populations:\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
321 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
322 if (best_x1[i] == 1)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
323 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
324 printf("and\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
325 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
326 if (best_x1[i] == 2)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
327 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
328 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
329 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
330 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
331 printf("%d had a larger average Reich-Patterson FST (max %5.5f, mean %5.5f)\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
332 larger2, largest_F2, tot_F2/nshuff);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
333 if (largest_F2 > F2) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
334 printf("first columns for the best two populations:\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
335 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
336 if (best_x2[i] == 1)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
337 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
338 printf("and\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
339 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
340 if (best_x2[i] == 2)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
341 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
342 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
343 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
344 }
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
345 printf("%d had a larger Reich-Patterson population FST (max %5.5f, mean %5.5f)\n",
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
346 larger3, largest_F3, tot_F3/nshuff);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
347 if (largest_F3 > F3) {
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
348 printf("first columns for the best two populations:\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
349 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
350 if (best_x3[i] == 1)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
351 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
352 printf("and\n");
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
353 for (i = 0; i < nI; ++i)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
354 if (best_x3[i] == 2)
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
355 printf("%d ", col[i]);
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
356 putchar('\n');
f04f40a36cc8 Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents: 0
diff changeset
357 putchar('\n');
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
358 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
359
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
360 return 0;
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
361 }