ade09b1a38d8e184e795f8b50f936d931d2164ba
[jalview.git] / src / jalview / util / ProbabilityAnalyserKickstarter.java
1 package jalview.util;
2
3 import java.io.IOException;
4 import java.util.Scanner;
5
6 /**
7  * This class contains the brain of the analyser program, and contains a number
8  * of commands for the processing of data.
9  * 
10  * @author TZVanaalten
11  *
12  */
13
14 public class ProbabilityAnalyserKickstarter
15 {
16
17   public static void main(String[] args)
18           throws IOException, InterruptedException
19   {
20
21     // this does all of the processing
22     HMMProbabilityDistributionAnalyser analyser = new HMMProbabilityDistributionAnalyser();
23
24     boolean running = true;
25     System.out.println("ACTIVATED");
26     while (running)
27     {
28       Scanner keyboard = new Scanner(System.in);
29       String command = keyboard.nextLine();
30
31       Scanner inputScanner = new Scanner(command);
32       // prints family to console. Syntax is printFam <index>
33       if (command.indexOf("printFam") > -1)
34       {
35         try
36         {
37           inputScanner.next();
38           int index = inputScanner.nextInt();
39           analyser.printFam(index);
40           continue;
41         } catch (Exception e)
42         {
43           System.out.println("Command failed");
44         }
45
46       }
47       // prints HMM to console. Syntax is printHMM <index>
48       if (command.indexOf("printHMM") > -1)
49       {
50         try
51         {
52         inputScanner.next();
53         int index = inputScanner.nextInt();
54         analyser.printHMM(index);
55         continue;
56         } catch (Exception e)
57         {
58           System.out.println("Command failed");
59         }
60       }
61       // prints family to file in current folder. Syntax is exportFam <index>.
62       if (command.indexOf("exportFam") > -1)
63       {
64         try
65         {
66         inputScanner.next();
67         int index = inputScanner.nextInt();
68           String location = inputScanner.next();
69           analyser.exportFam(index, location);
70         continue;
71         } catch (Exception e)
72         {
73           System.out.println("Command failed");
74         }
75       }
76       // prints HMM to file in current folder. Syntax is exportHMM <index>.
77       if (command.indexOf("exportHMM") > -1)
78       {
79         try
80         {
81         inputScanner.next();
82         int index = inputScanner.nextInt();
83           String location = inputScanner.next();
84           analyser.exportHMM(index, location);
85         continue;
86         } catch (Exception e)
87         {
88           System.out.println("Command failed");
89         }
90       }
91       // Processes data. Syntax is run <number of loops> <increments>. The
92       // number loops specifies the number of increments the program will run.
93       // After each increment, the data stored currently in the program is
94       // exported and re-read back into the program. This is to ensure that the
95       // program can be terminated without losing a large quantity of data. The
96       // increment is the number of families read per 'save'.
97       if (command.indexOf("run") > -1 && !(command.indexOf("ToEnd") > -1))
98       {
99         try
100         {
101
102         inputScanner.next();
103
104         int loops = inputScanner.nextInt();
105         int increments = inputScanner.nextInt();
106         boolean keepRaw = inputScanner.nextBoolean();
107
108         for (int i = 0; i < loops; i++)
109         {
110           analyser.run(increments, keepRaw);
111           System.out.println("Saved");
112         }
113         System.out.println("Task completed");
114         continue;
115         } catch (Exception e)
116         {
117           System.out.println("Command failed");
118         }
119         continue;
120       }
121       if ((command.indexOf("runToEnd") > -1))
122       {
123         try
124         {
125
126           inputScanner.next();
127           boolean keepRaw = inputScanner.nextBoolean();
128           boolean forClans = inputScanner.nextBoolean();
129           analyser.runToEnd(keepRaw, forClans);
130           System.out.println("Task completed");
131         } catch (Exception e)
132         {
133           System.out.println("Command failed");
134         }
135         continue;
136       }
137       // terminates program. Syntax is terminate.
138       if (command.indexOf("terminate") > -1)
139       {
140         running = false;
141         continue;
142       }
143       // clears files in current directory (Only a specific set of files).
144       // Syntax is clear.
145       if (command.indexOf("clear") > -1)
146       {
147         analyser.clear();
148         continue;
149       }
150       // changes current directory. Syntax is cd <directory>
151       if (command.indexOf("cd") > -1)
152       {
153         try
154         {
155         inputScanner.next();
156         analyser.setFolder(inputScanner.next());
157         } catch (Exception e)
158         {
159           System.out.println("Command failed");
160
161         }
162         continue;
163       }
164
165       if (command.indexOf("getFamName") > -1)
166       {
167         try
168         {
169         inputScanner.next();
170         System.out.println(analyser.getFamilyName(inputScanner.nextInt()));
171
172         } catch (Exception e)
173         {
174           System.out.println("Command failed");
175         }
176         continue;
177       }
178       if (command.indexOf("sortIntoClans") > -1)
179       {
180         inputScanner.next();
181         analyser.sortIntoClans(inputScanner.next());
182           continue;
183
184       }
185       if (command.indexOf("setFamilies") > -1)
186       {
187         inputScanner.next();
188         analyser.setFamilies(inputScanner.next());
189         continue;
190
191       }
192
193       if (command.indexOf("setHMMs") > -1)
194       {
195         inputScanner.next();
196         analyser.setHmms(inputScanner.next());
197         continue;
198
199       }
200
201       if (command.indexOf("alignWithinClans") > -1)
202       {
203         inputScanner.next();
204         String export = inputScanner.next();
205         String clans = inputScanner.next();
206         analyser.alignWithinClan(export, clans);
207         continue;
208
209       }
210
211       System.out.println("Unrecognised command");
212     }
213
214
215
216
217   }
218
219 }