-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoExtensionSpaces.java
162 lines (130 loc) · 6.99 KB
/
DemoExtensionSpaces.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import java.util.*;
import distanceAlg1.*;
import BHVExtMinDistance.*;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
public class DemoExtensionSpaces{
private static PhyloTree FirstTree;
private static PhyloTree SecondTree;
private static Vector<String> completeLeafSet;
public static void main(String[] args){
Scanner input = new Scanner(System.in);
PhyloNicePrinter nicePrint = new PhyloNicePrinter();
if(args.length == 0){
System.out.println("Please input the first tree in Newick format:");
String StringFirstTree = input.nextLine();
FirstTree = new PhyloTree(StringFirstTree,false);
System.out.println("\n The first tree is: \n"+ nicePrint.toString(FirstTree));
System.out.println("\n \n Please input the second tree in Newick format:");
String StringSecondTree = input.nextLine();
SecondTree = new PhyloTree(StringSecondTree,false);
System.out.println("\n The second tree is: \n"+ nicePrint.toString(SecondTree));
System.out.println("\n \n Press enter if you want to use the union of the leaf sets of both trees. \n If not, please input the complete leaf set, separated by commas without blank spaces:");
String CLSstring = input.nextLine();
if (CLSstring.equals("") || CLSstring.equals(" ")){
completeLeafSet = new Vector<String>();
completeLeafSet.addAll(FirstTree.getLeaf2NumMap());
for (String s : SecondTree.getLeaf2NumMap()){
if (!completeLeafSet.contains(s)){
completeLeafSet.add(s);
}
}
Collections.sort(completeLeafSet);
} else {
String[] temp = CLSstring.split(",");
completeLeafSet = new Vector<String>();
for(String s : temp){
completeLeafSet.add(s);
}
}
System.out.println("\n The complete leaf set is: "+ completeLeafSet);
} else if (args.length == 1){
try {
File myFile = new File(args[0]);
Scanner myReader = new Scanner(myFile);
String StringFirstTree = myReader.nextLine();
System.out.println("\n The Newick format for the first tree is: \n"+ StringFirstTree);
FirstTree = new PhyloTree(StringFirstTree,false);
System.out.println("\n The first tree is: \n"+ nicePrint.toString(FirstTree));
String StringSecondTree = myReader.nextLine();
SecondTree = new PhyloTree(StringSecondTree,false);
System.out.println("\n The second tree is: \n"+ nicePrint.toString(SecondTree));
String CLSstring = myReader.nextLine();
String[] temp = CLSstring.split(",");
completeLeafSet = new Vector<String>();
for(String s : temp){
completeLeafSet.add(s);
}
System.out.println("\n The complete leaf set is: "+ completeLeafSet);
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
} else if(args.length == 2){
try {
System.out.println("It entered the correct if");
File myFile1 = new File(args[0]);
Scanner myReader1 = new Scanner(myFile1);
String StringFirstTree = myReader1.nextLine();
System.out.println("About to create first tree");
FirstTree = new PhyloTree(StringFirstTree,false);
System.out.println("\n The first tree is: \n"+ nicePrint.toString(FirstTree));
myReader1.close();
File myFile2 = new File(args[1]);
Scanner myReader2 = new Scanner(myFile2);
String StringSecondTree = myReader2.nextLine();
System.out.println("About to create second tree with: " + StringSecondTree);
SecondTree = new PhyloTree(StringSecondTree,false);
System.out.println("\n The second tree is: \n"+ nicePrint.toString(SecondTree));
myReader2.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
completeLeafSet = new Vector<String>();
completeLeafSet.addAll(FirstTree.getLeaf2NumMap());
for (String s : SecondTree.getLeaf2NumMap()){
if (!completeLeafSet.contains(s)){
completeLeafSet.add(s);
}
}
Collections.sort(completeLeafSet);
System.out.println("\n The complete leaf set is: "+ completeLeafSet);
System.out.println("Continue? Press enter");
String NonImportant = input.nextLine();
} else if (args.length == 3){
System.out.println("We are in the case where things were already inputed manually");
} else {
System.out.println("Error: Format for data entry not correct");
System.exit(1);
}
ExtensionSpace firstES = new ExtensionSpace(FirstTree, completeLeafSet, false);
System.out.println("Would you like to see the Extension Space of the first tree?");
String Ans1 = input.nextLine();
if (Ans1.equals("Yes") || Ans1.equals("yes")){
firstES.PrintSummary(true);
System.out.println("\n \n");
}
ExtensionSpace secondES = new ExtensionSpace(SecondTree, completeLeafSet, false);
System.out.println("Would you like to see the Extension Space of the second tree?");
String Ans2 = input.nextLine();
if (Ans2.equals("Yes") || Ans2.equals("yes") || Ans2.equals("y") || Ans2.equals("Y")){
secondES.PrintSummary(true);
System.out.println("\n \n");
}
ExtensionSpaceDistance Distance = new ExtensionSpaceDistance(firstES, secondES, false);
System.out.println("The results are: ");
Distance.PrintSummary(true);
System.out.println("\n Would you like to print this summary on a text file?");
String Ans3 = input.nextLine();
if (Ans3.equals("Yes") || Ans3.equals("yes") || Ans3.equals("y") || Ans3.equals("Y")){
System.out.println("What name would you like to use in result file?");
String FileName = input.nextLine();
Distance.PrintSummary(true, FileName);
}
}
}