Skip to content

Commit e454a2b

Browse files
JudithNeukammJudithNeukamm
JudithNeukamm
authored and
JudithNeukamm
committed
initial commit - Fst calculation (just in pairwise distance - method)
1 parent 9f772e1 commit e454a2b

9 files changed

+1212
-0
lines changed

build.gradle

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
group 'com.uni-tuebingen.de.it.mitobench.FstCalculator'
2+
version '0.1.20'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
dependencies {
9+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8+'
10+
}
11+
}
12+
13+
allprojects {
14+
repositories {
15+
jcenter()
16+
}
17+
apply plugin: 'maven'
18+
apply plugin: 'maven-publish'
19+
apply plugin: 'java'
20+
apply plugin: 'idea'
21+
apply plugin: 'com.jfrog.bintray'
22+
apply plugin: 'jacoco'
23+
}
24+
25+
sourceCompatibility = 1.8
26+
27+
repositories {
28+
mavenCentral()
29+
}
30+
31+
sourceSets {
32+
main {
33+
java {
34+
srcDir 'src'
35+
}
36+
}
37+
test {
38+
java {
39+
srcDir 'test'
40+
}
41+
}
42+
}
43+
44+
45+
dependencies {
46+
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.+'
47+
compile 'junit:junit:4.+'
48+
testCompile group: 'junit', name: 'junit', version: '4.+'
49+
}
50+
51+
jar {
52+
manifest {
53+
attributes("Implementation-Title": "FstCalculator",
54+
"Implementation-Version": version)
55+
}
56+
doFirst {
57+
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
58+
}
59+
}
60+
61+
task sourcesJar(type: Jar, dependsOn: classes) {
62+
classifier = 'sources'
63+
from sourceSets.main.allSource
64+
}
65+
66+
67+
artifacts {
68+
archives sourcesJar //, javadocJar
69+
}
70+
71+
72+
73+
publishing {
74+
publications {
75+
MyPublication(MavenPublication) {
76+
from components.java
77+
groupId 'com.uni-tuebingen.de.it.mitobench'
78+
artifactId 'FstCalculator'
79+
artifact sourcesJar {
80+
classifier "sources"
81+
}
82+
}
83+
}
84+
}
85+
86+
jacocoTestReport {
87+
reports {
88+
xml.enabled true
89+
}
90+
}
91+
92+
93+
bintray {
94+
user = System.getenv('BINTRAY_USER')
95+
key = System.getenv('BINTRAY_API_KEY')
96+
publications = ['MyPublication']
97+
publish = true
98+
override = true
99+
pkg {
100+
repo = 'Mitobench'
101+
name = 'FstCalculator'
102+
licenses = ['GPL-3.0']
103+
vcsUrl = "https://github.com/JudithNeukamm/FstCalculator"
104+
version {
105+
name = project.version
106+
desc = 'Calculating pairwise Fst values.'
107+
released = new Date()
108+
vcsTag = project.version
109+
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
110+
}
111+
112+
}
113+
}

settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'FstCalculator'
2+

src/FstCalculator.java

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import IO.reader.DistanceTypeParser;
2+
import IO.writer.Writer;
3+
import fst.FstAMOVA;
4+
import fst.Linearization;
5+
import methods.Filter;
6+
7+
import java.io.IOException;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
11+
public class FstCalculator {
12+
13+
private static double gamma = 0.5;
14+
private static double level_missing_data = 0.05;
15+
private static double significance = 0.05;
16+
private static int number_of_permutations = 0;
17+
private static String missing_data = "N";
18+
private final HashMap<String, List<String>> data;
19+
private String distance_method = "Pairwise Difference";
20+
21+
22+
public FstCalculator(HashMap<String, List<String>> data,
23+
String missing_data,
24+
double level_missing_data,
25+
String distance_method,
26+
int number_of_permutations,
27+
double gamma
28+
29+
) {
30+
31+
this.data = data;
32+
this.missing_data = missing_data;
33+
this.distance_method = distance_method;
34+
this.level_missing_data = level_missing_data;
35+
this.number_of_permutations = number_of_permutations;
36+
this.gamma = gamma;
37+
}
38+
39+
public double[][] runCaclulations() throws IOException {
40+
return runAmova();
41+
}
42+
43+
private double[][] runAmova() throws IOException {
44+
45+
Linearization linearization = new Linearization();
46+
47+
DistanceTypeParser distanceTypeParser = new DistanceTypeParser();
48+
Filter filter = new Filter();
49+
List<Integer> usableLoci = filter.getUsableLoci(data, missing_data, level_missing_data);
50+
51+
FstAMOVA standardAMOVA = new FstAMOVA(
52+
usableLoci,
53+
number_of_permutations,
54+
distanceTypeParser.parse(distance_method),
55+
gamma);
56+
57+
standardAMOVA.setData(data);
58+
59+
double[][] fsts_amova = standardAMOVA.calculateFst();
60+
double[][] pvalues = standardAMOVA.calculatePermutatedFst();
61+
62+
63+
Writer writer = new Writer(number_of_permutations);
64+
65+
writer.writeResultsFstToString(
66+
fsts_amova,
67+
pvalues,
68+
standardAMOVA.getGroupnames(),
69+
usableLoci,
70+
level_missing_data,
71+
significance
72+
);
73+
writer.addDistanceMatrixToResult(
74+
standardAMOVA.getDistanceCalculator().getDistancematrix_d()
75+
);
76+
77+
writer.addLinerarizedFstMatrix(
78+
linearization.linearizeWithSlatkin(fsts_amova),
79+
"# Linearized Fst values (Slatkin)."
80+
);
81+
writer.addLinerarizedFstMatrix(
82+
linearization.linearizeWithReynolds(fsts_amova),
83+
"# Linearized Fst values (Reynold)."
84+
);
85+
86+
writer.writeResultsToFile("resultsFstStatisticsAMOVA.tsv");
87+
88+
return fsts_amova;
89+
90+
}
91+
92+
93+
94+
}

src/IO/reader/DistanceTypeParser.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package IO.reader;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
/**
8+
* Created by neukamm on 08.06.17.
9+
*/
10+
public class DistanceTypeParser {
11+
12+
List<String> types = new ArrayList<>();
13+
14+
public DistanceTypeParser(){
15+
16+
types.add("Pairwise Difference");
17+
types.add("Percentage Difference");
18+
types.add("Jukes and Cantor");
19+
types.add("Kimura 2-parameters");
20+
types.add("Tamura");
21+
22+
23+
}
24+
25+
public int parse(String type){
26+
return types.indexOf(type);
27+
}
28+
}

0 commit comments

Comments
 (0)