import java.io.IOException;
import java.util.Scanner;
+/**
+ * This class contains the brain of the analyser program, and contains a number
+ * of commands for the processing of data.
+ *
+ * @author TZVanaalten
+ *
+ */
+
public class ProbabilityAnalyserKickstarter
{
throws IOException, InterruptedException
{
+ // this does all of the processing
HMMProbabilityDistributionAnalyser analyser = new HMMProbabilityDistributionAnalyser();
boolean running = true;
String command = keyboard.nextLine();
Scanner inputScanner = new Scanner(command);
+ // prints family to console. Syntax is printFam <index>
if (command.indexOf("printFam") > -1)
{
- inputScanner.next();
- int index = inputScanner.nextInt();
- analyser.printFam(index);
- continue;
- }
+ try
+ {
+ inputScanner.next();
+ int index = inputScanner.nextInt();
+ analyser.printFam(index);
+ continue;
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
+ }
+ // prints HMM to console. Syntax is printHMM <index>
if (command.indexOf("printHMM") > -1)
{
-
+ try
+ {
inputScanner.next();
int index = inputScanner.nextInt();
analyser.printHMM(index);
continue;
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
}
-
+ // prints family to file in current folder. Syntax is exportFam <index>.
if (command.indexOf("exportFam") > -1)
{
-
+ try
+ {
inputScanner.next();
int index = inputScanner.nextInt();
- String location = inputScanner.next();
- analyser.printFamToFile(index);
+ String location = inputScanner.next();
+ analyser.exportFam(index, location);
continue;
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
}
-
+ // prints HMM to file in current folder. Syntax is exportHMM <index>.
if (command.indexOf("exportHMM") > -1)
{
-
+ try
+ {
inputScanner.next();
int index = inputScanner.nextInt();
- String location = inputScanner.next();
- analyser.printHMMToFile(index);
+ String location = inputScanner.next();
+ analyser.exportHMM(index, location);
continue;
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
}
-
- if (command.indexOf("run") > -1)
+ // Processes data. Syntax is run <number of loops> <increments>. The
+ // number loops specifies the number of increments the program will run.
+ // After each increment, the data stored currently in the program is
+ // exported and re-read back into the program. This is to ensure that the
+ // program can be terminated without losing a large quantity of data. The
+ // increment is the number of families read per 'save'.
+ if (command.indexOf("run") > -1 && !(command.indexOf("ToEnd") > -1))
{
+ try
+ {
+
inputScanner.next();
int loops = inputScanner.nextInt();
int increments = inputScanner.nextInt();
+ boolean keepRaw = inputScanner.nextBoolean();
for (int i = 0; i < loops; i++)
{
- analyser.run(increments);
+ analyser.run(increments, keepRaw);
+ System.out.println("Saved");
+ }
+ System.out.println("Task completed");
+ continue;
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
}
continue;
}
+ if ((command.indexOf("runToEnd") > -1))
+ {
+ try
+ {
+ inputScanner.next();
+ int minCount = inputScanner.nextInt();
+ int maxCount = inputScanner.nextInt();
+ boolean keepRaw = inputScanner.nextBoolean();
+ boolean forClans = inputScanner.nextBoolean();
+ analyser.runToEnd(minCount, maxCount, keepRaw, forClans);
+ System.out.println("Task completed");
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
+ continue;
+ }
+ // terminates program. Syntax is terminate.
if (command.indexOf("terminate") > -1)
{
running = false;
continue;
}
-
+ // clears files in current directory (Only a specific set of files).
+ // Syntax is clear.
if (command.indexOf("clear") > -1)
{
analyser.clear();
continue;
}
-
+ // changes current directory. Syntax is cd <directory>
if (command.indexOf("cd") > -1)
{
+ try
+ {
inputScanner.next();
analyser.setFolder(inputScanner.next());
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+
+ }
+ continue;
+ }
+
+ if (command.indexOf("getFamName") > -1)
+ {
+ try
+ {
+ inputScanner.next();
+ System.out.println(analyser.getFamilyName(inputScanner.nextInt()));
+
+ } catch (Exception e)
+ {
+ System.out.println("Command failed");
+ }
+ continue;
+ }
+ if (command.indexOf("sortIntoClans") > -1)
+ {
+ inputScanner.next();
+ analyser.sortIntoClans(inputScanner.next());
+ continue;
+
}
- inputScanner.close();
- continue;
+ if (command.indexOf("setFamilies") > -1)
+ {
+ inputScanner.next();
+ analyser.setFamilies(inputScanner.next());
+ continue;
+
+ }
+
+ if (command.indexOf("setHMMs") > -1)
+ {
+ inputScanner.next();
+ analyser.setHmms(inputScanner.next());
+ continue;
+
+ }
+
+ if (command.indexOf("alignWithinClans") > -1)
+ {
+ inputScanner.next();
+ String export = inputScanner.next();
+ String clans = inputScanner.next();
+ analyser.alignWithinClan(export, clans);
+ continue;
+
+ }
+
+ System.out.println("Unrecognised command");
}