This repository was archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneBankSearch.java
More file actions
130 lines (113 loc) · 3.23 KB
/
GeneBankSearch.java
File metadata and controls
130 lines (113 loc) · 3.23 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
public class GeneBankSearch {
static private Boolean cacheSearch = false;
static private String bTreeFile = "";
static private String queryFile = "";
static private int cacheSizeSearch = 0;
static private int debugLevelSearch = 2;
public static void main(String[] args) {
long startTime = System.nanoTime();
if (args.length > 5 || args.length < 3) {
correctOutput();
}
if (args[0].equals("1")) {
cacheSearch = true;
} else if (!(args[0].equals("0"))) {
correctOutput();
}
bTreeFile = args[1];
queryFile = args[2];
if (args.length > 3 && cacheSearch) {
try {
cacheSizeSearch = Integer.valueOf(args[3]);
}catch(Exception e) {
correctOutput();
}
}
if (args.length > 4 && cacheSearch) {
try {
debugLevelSearch = Integer.valueOf(args[4]);
}catch(Exception e) {
correctOutput();
}
}
if (args.length > 3 && !cacheSearch) {
try {
debugLevelSearch = Integer.valueOf(args[3]);
}catch(Exception e) {
correctOutput();
}
}
if (debugLevelSearch != 0 && debugLevelSearch != 1) {
debugLevelSearch = 0;
}
try {
search();
} catch (Exception e) {
e.printStackTrace();
System.err.println("RUN UNSUCCESSFUL");
System.exit(0);
}
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
double seconds = totalTime/1000000000.0;
double minutes = seconds/60;
System.out.println("Runtime:");
System.out.println("Seconds: "+seconds);
System.out.println("Minutes: "+minutes);
System.out.println("\nRun Successful.");
}
private static void correctOutput() {
System.out.println( "CL arguments: <0/1(no/with Cache> <btree file> <query file> [<cache size>] [<debug level>]");
System.exit(0);
}
private static void search() throws ClassNotFoundException, IOException {
//Create file from query file
File file = new File(queryFile);
//Parse the file
QueryParser parser = new QueryParser(file);
//Get the string from the parser
String[] geneStringArray = parser.getGeneStringArray();
//Create GeneConverter
GeneConverter gc = new GeneConverter();
//Create BTree
BTree bt = new BTree(bTreeFile, debugLevelSearch, cacheSizeSearch);
//Create a dump for query results
BufferedWriter bw = null;
if(debugLevelSearch == 1) {
String dumpFileName = "btree.search."+queryFile+"_result";
File dumpFile = new File(dumpFileName);
if(!dumpFile.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
bw = new BufferedWriter(new FileWriter(dumpFileName));
}
//search btree
for (String queryString: geneStringArray) {
queryString = queryString.toLowerCase();
if(queryString.equals("ttttttt")) {
System.out.print("");;
}
long key = gc.convertStringToLong(queryString);
int frequency = bt.search(key);
if(frequency != 0) {
if(debugLevelSearch == 1) { //make query dump
bw.write(queryString+": "+frequency+"\n");
} else { //print query result to stdout
System.out.println(queryString+": "+frequency);
}
}
}
if(bw != null) {
bw.close();
}
}
}