Debian Codegraph @

metastudentPkg/lib/groupB/pp2/prediction/BestHit.java

raw
1 package pp2.prediction;
2
3 import java.io.*;
4 import pp2.datahandler.blast.*;
5
6 public class BestHit {
7
8 private int maxIterations = 8;
9 private double eValue = 20;
10 private double hValue = 0.001;
11
12 public void run(String trainingSet, String testSet, Writer output) throws IOException, InterruptedException{
13
14 String[] parameters = new String[] {
15 "-h",
16 String.valueOf(hValue),
17 "-e",
18 String.valueOf(eValue),
19 "-j",
20 String.valueOf(maxIterations),
21 "-m",
22 "8",
23 };
24
25 System.err.println("Starting BLAST with parameters h="+hValue+", e="+eValue+", j="+maxIterations+"...");
26
27 // initialize BLAST performer with BLAST database
28 BlastPerformer bp = new BlastPerformer(new File(trainingSet).getAbsolutePath());
29
30 // run BLAST and get ouput in a stream
31 Process blast = bp.startBLAST(new File(testSet), parameters);
32
33 // parse BLAST output from stream
34 System.err.println("Parsing BLAST output...");
35 TabularBlastParser.parseBlast(blast, output);
36 }
37
38
39 public void sethValue(double hValue) {
40 this.hValue = hValue;
41 }
42
43 public void setMaxIter(int maxIter) {
44 this.maxIterations = maxIter;
45 }
46
47 public void seteValue(double eValue) {
48 this.eValue = eValue;
49 }
50
51 public static void main(String[] args) throws Exception {
52 String usage = "Usage: BestHit -t trainingSet -p predictSet " +
53 "[-h value] " +
54 "[-e value] " +
55 "[-j maxIterations]";
56
57 try {
58 if(args.length == 0) {
59 System.out.println(usage);
60 } else {
61 BestHit bhbw = new BestHit();;
62
63 String trainingSet = null;
64 String predictSet = null;
65
66 for(int i=0; i<args.length; i++) {
67
68 if(args[i].equals("-h")) {
69 double h = Double.parseDouble(args[i+1]);
70 bhbw.sethValue(h);
71 i++;
72 } else if(args[i].equals("-e")) {
73 double e = Double.parseDouble(args[i+1]);
74 bhbw.seteValue(e);
75 i++;
76 } else if(args[i].equals("-j")) {
77 int j = Integer.parseInt(args[i+1]);
78 bhbw.setMaxIter(j);
79 i++;
80 } else if(args[i].equals("-t")) {
81 trainingSet = args[i+1];
82 i++;
83 } else if(args[i].equals("-p")) {
84 predictSet = args[i+1];
85 i++;
86 } else {
87 System.out.println(usage);
88 }
89 }
90
91 if(trainingSet == null) throw new Exception("Must specify training set!");
92 if(predictSet == null) throw new Exception("Must specify prediction set!");
93
94 bhbw.run(trainingSet, predictSet, new OutputStreamWriter(System.out));
95
96 }
97 } catch (NumberFormatException e) {
98 System.out.println(usage);
99 }
100 }
101 }