| 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 |
package dr.app.checkpoint; |
| 27 |
|
| 28 |
import dr.evolution.io.Importer; |
| 29 |
import dr.evolution.io.NewickImporter; |
| 30 |
import dr.evolution.tree.Tree; |
| 31 |
|
| 32 |
import java.io.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class DebugTreeImporter { |
| 38 |
|
| 39 |
private static final boolean DEBUG = true; |
| 40 |
|
| 41 |
|
| 42 |
public static boolean isInteger(String s) { |
| 43 |
try { |
| 44 |
Integer.parseInt(s); |
| 45 |
} catch(NumberFormatException e) { |
| 46 |
return false; |
| 47 |
} catch(NullPointerException e) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static void main (String[] args) { |
| 60 |
|
| 61 |
if (args.length != 4) { |
| 62 |
throw new RuntimeException("Incorrect number of arguments."); |
| 63 |
} |
| 64 |
|
| 65 |
try { |
| 66 |
FileReader fileIn = new FileReader(args[2]); |
| 67 |
BufferedReader in = new BufferedReader(fileIn); |
| 68 |
|
| 69 |
String fullTree = in.readLine(); |
| 70 |
|
| 71 |
NewickImporter importer = new NewickImporter(fullTree); |
| 72 |
Tree tree = importer.importNextTree(); |
| 73 |
|
| 74 |
|
| 75 |
System.out.println("root height: " + tree.getNodeHeight(tree.getRoot())); |
| 76 |
|
| 77 |
FileReader dumpFileIn = new FileReader(args[0]); |
| 78 |
BufferedReader dumpIn = new BufferedReader(dumpFileIn); |
| 79 |
|
| 80 |
FileWriter dumpFileOut = new FileWriter(args[3]); |
| 81 |
BufferedWriter dumpOut = new BufferedWriter(dumpFileOut); |
| 82 |
|
| 83 |
String original = dumpIn.readLine(); |
| 84 |
String[] fields = original.split("\t"); |
| 85 |
|
| 86 |
|
| 87 |
while (!fields[0].equals("treeModel.rootHeight")) { |
| 88 |
if (DEBUG) { |
| 89 |
System.out.println(original); |
| 90 |
} |
| 91 |
dumpOut.write(original + "\n"); |
| 92 |
|
| 93 |
original = dumpIn.readLine(); |
| 94 |
fields = original.split("\t"); |
| 95 |
} |
| 96 |
|
| 97 |
fields[2] = Double.toString(tree.getNodeHeight(tree.getRoot())); |
| 98 |
for (int i = 0; i < fields.length; i++) { |
| 99 |
dumpOut.write(fields[i] + "\t"); |
| 100 |
} |
| 101 |
dumpOut.write("\n"); |
| 102 |
|
| 103 |
|
| 104 |
int nodeCount = tree.getNodeCount(); |
| 105 |
if (DEBUG) { |
| 106 |
System.out.println(nodeCount + " nodes found in tree."); |
| 107 |
} |
| 108 |
for (int i = 0; i < (nodeCount-1); i++) { |
| 109 |
if (DEBUG) { |
| 110 |
System.out.println(tree.getNode(i).getNumber() + "\t" + tree.getNodeHeight(tree.getNode(i))); |
| 111 |
} |
| 112 |
dumpOut.write(tree.getNode(i).getNumber() + "\t1\t" + tree.getNodeHeight(tree.getNode(i)) + "\n"); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
original = dumpIn.readLine(); |
| 119 |
if (DEBUG) { |
| 120 |
System.out.println(original); |
| 121 |
} |
| 122 |
fields = original.split("\t"); |
| 123 |
while (isInteger(fields[0])) { |
| 124 |
original = dumpIn.readLine(); |
| 125 |
fields = original.split("\t"); |
| 126 |
} |
| 127 |
|
| 128 |
while (!fields[0].equals("treeModel")) { |
| 129 |
dumpOut.write(original + "\n"); |
| 130 |
original = dumpIn.readLine(); |
| 131 |
if (DEBUG) { |
| 132 |
System.out.println(original); |
| 133 |
} |
| 134 |
fields = original.split("\t"); |
| 135 |
} |
| 136 |
|
| 137 |
dumpOut.write(fields[0] + "\t" + fullTree); |
| 138 |
|
| 139 |
dumpOut.flush(); |
| 140 |
dumpOut.close(); |
| 141 |
|
| 142 |
} catch (FileNotFoundException fnfe) { |
| 143 |
throw new RuntimeException("Tree file not found."); |
| 144 |
} catch (IOException ioe) { |
| 145 |
throw new RuntimeException("Unable to read file: " + ioe.getMessage()); |
| 146 |
} catch (Importer.ImportException ie) { |
| 147 |
throw new RuntimeException("Unable to import tree: " + ie.getMessage()); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
} |