Skip to content

Commit 0708ec0

Browse files
author
neukamm
committed
update
1 parent 14f8dc5 commit 0708ec0

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/IO/writer/Writer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private void addValToString(int linecounter, int i){
184184
* @param distancematrix_d
185185
*/
186186
public void addDistanceMatrixToResult(double[][] distancematrix_d){
187-
printmatrix(distancematrix_d, "DistanceMethods matrix (gamma corrected)" +
187+
printmatrix(distancematrix_d, "DistanceMethods matrix" +
188188
"-----------------------------------------\n");
189189
}
190190

src/Main/FstCalculator.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class FstCalculator {
2020
private final HashMap<String, List<String>> data;
2121
private String distance_method = "Pairwise Difference";
2222
private Writer writer;
23+
private String[] groupnames;
2324

2425

2526
public FstCalculator(HashMap<String, List<String>> data,
@@ -62,7 +63,11 @@ private double[][] runAmova() throws IOException {
6263
standardAMOVA.setData(data);
6364

6465
double[][] fsts_amova = standardAMOVA.calculateFst();
65-
double[][] pvalues = standardAMOVA.calculatePermutatedFst();
66+
double[][] pvalues = null;
67+
if(number_of_permutations > 0){
68+
pvalues = standardAMOVA.calculatePermutatedFst();
69+
}
70+
6671

6772

6873
writer = new Writer(number_of_permutations);
@@ -90,6 +95,8 @@ private double[][] runAmova() throws IOException {
9095

9196
writer.writeResultsToFile("resultsFstStatisticsAMOVA.tsv");
9297

98+
groupnames = standardAMOVA.getGroupnames();
99+
93100
return fsts_amova;
94101

95102
}
@@ -99,5 +106,7 @@ public String getResultString(){
99106
return writer.getResult_as_string();
100107
}
101108

102-
109+
public String[] getGroupnames() {
110+
return groupnames;
111+
}
103112
}

src/fst/FstAMOVA.java

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import methods.UsefulFunctions;
66

77
import java.io.IOException;
8+
import java.math.BigInteger;
89
import java.util.ArrayList;
910
import java.util.Arrays;
1011
import java.util.HashMap;
@@ -47,6 +48,8 @@ public double[][] calculateFst() throws IOException {
4748
fsts = new double[populations.size()][populations.size()];
4849

4950
// iterate over list, calculateWP distance between each pair of individuals
51+
BigInteger totalNumberOfComparisons = choose(populations.size(), 2);
52+
int pairsDone = 0;
5053
for(int i = 0; i < populations.size(); i++){
5154
for(int j = i+1; j < populations.size(); j++){
5255
List<String> pop1 = data.get(populations.get(j));
@@ -56,6 +59,8 @@ public double[][] calculateFst() throws IOException {
5659
pop2.toArray(new String[pop2.size()])
5760
);
5861
fsts[i][j] = fst;
62+
pairsDone++;
63+
System.out.println("("+ pairsDone+"/"+totalNumberOfComparisons+") pairs compared");
5964
}
6065
}
6166
return fsts;
@@ -269,6 +274,21 @@ private double calculatePvalue(double[] fsts_permuted, double fst_original) {
269274
}
270275

271276

277+
public static BigInteger choose(int x, int y) {
278+
if (y < 0 || y > x)
279+
return BigInteger.ZERO;
280+
if (y == 0 || y == x)
281+
return BigInteger.ONE;
282+
283+
BigInteger answer = BigInteger.ONE;
284+
for (int i = x - y + 1; i <= x; i++) {
285+
answer = answer.multiply(BigInteger.valueOf(i));
286+
}
287+
for (int j = 1; j <= y; j++) {
288+
answer = answer.divide(BigInteger.valueOf(j));
289+
}
290+
return answer;
291+
}
272292

273293
/*
274294
Setter and Getter

0 commit comments

Comments
 (0)