-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.java
114 lines (103 loc) · 5.16 KB
/
App.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.io.*;
import java.util.*;
public class App {
private static ChainHashMap<DNASequence, Integer> map = new ChainHashMap<>();
private static ArrayList<TestEntry> result = new ArrayList<>();
private static int errorThreshold = 6;
private static String dataFile = "data10000.txt";
private static String verifyFile = "verify1000.txt";
private static int numSequencesBucketNotFound = 0;
public static void main(String[] args) {
readData();
verifyData();
computeScore();
}
public static void readData() {
try (Scanner sc = new Scanner(new File(dataFile))) {
while (sc.hasNext()) {
map.put(new DNASequence(sc.next()), null);
}
} catch (FileNotFoundException ex) {
System.out.println("Data File not found");
}
}
public static void verifyData() {
try (Scanner sc = new Scanner(new File(verifyFile))) {
while (sc.hasNext()) {
DNASequence testSequence = new DNASequence(sc.next());
Map<DNASequence, Integer> bucket = map.getObjectsInSameBucket(testSequence);
int numSimilar = 0;
if (bucket != null) {
for (DNASequence dnaSequence : bucket.keySet()) {
numSimilar += computeSimilarity(dnaSequence, testSequence);
}
result.add(new TestEntry(testSequence, numSimilar, bucket.size()));
} else {
numSequencesBucketNotFound++;
}
}
} catch (FileNotFoundException ex) {
System.out.println("Verify File not found");
}
}
public static int computeSimilarity(DNASequence x, DNASequence y) {
String s1 = x.getSequence();
String s2 = y.getSequence();
int numCharMisMatched = 0;
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) != s2.charAt(i)) {
numCharMisMatched++;
}
}
if (numCharMisMatched > errorThreshold) {
return 0;
}
return 1;
}
public static void computeScore() {
double total = 0;
double score = 0;
int size = result.size();
int numTotalSimilarEntries = 0;
int numTotalEntries = 0;
String outputFile = "output_" + dataFile + "_" + verifyFile + "_errorThreshold_" + errorThreshold + ".txt";
try (FileWriter myWriter = new FileWriter(outputFile)) {
for (TestEntry te : result) {
System.out.print(te + " = ");
myWriter.write(te + " = ");
score = (double) (te.getNumSimilar()) / (te.getNumInSameBucket());
System.out.println("Similarity Score : " + score);
myWriter.write("Similarity Score : " + score + "\n");
numTotalSimilarEntries += te.getNumSimilar();
numTotalEntries += te.getNumInSameBucket();
total += score;
}
System.out.println();
System.out.println("-------------------------------------------------------------------");
System.out.println("Summary of Results for " + dataFile + " and " + verifyFile);
System.out.println("-------------------------------------------------------------------");
System.out.println("Total Number of Verify Sequences (bucket found): " + size);
System.out.println("Total Number of Verify Sequences (bucket not found): " + numSequencesBucketNotFound);
System.out.println("Error Threshold : " + errorThreshold);
System.out.print(String.format("Total Similarity Score : %.2f \n", total));
System.out.print(String.format("Quality Indicator (Max 1.00) : %.2f \n", total / size));
System.out.println("Total Number of Similar : " + numTotalSimilarEntries);
System.out.println("Total Number of Sequences (in same Bucket) : " + numTotalEntries);
myWriter.write("-------------------------------------------------------------------" + "\n");
myWriter.write("Summary of Results for " + dataFile + " and " + verifyFile + "\n");
myWriter.write("-------------------------------------------------------------------" + "\n");
myWriter.write("Total Number of Verify Sequences (bucket found): " + size + "\n");
myWriter.write("Total Number of Verify Sequences (bucket not found): " + numSequencesBucketNotFound + "\n");
myWriter.write("Error Threshold : " + errorThreshold + "\n");
myWriter.write(String.format("Total Similarity Score : %.2f \n", total));
myWriter.write(String.format("Quality Indicator (Max 1.00) : %.2f \n", total / size));
myWriter.write("Total Number of Similar : " + numTotalSimilarEntries + "\n");
myWriter.write("Total Number of Sequences (in same Bucket) : " + numTotalEntries + "\n");
System.out.println();
System.out.println("Successfully written to " + outputFile);
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}