use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.
the class DebugTreeImporter method main.
//args[0]: saved dump file
//args[1]: new XML file
//args[2]: new tree (Newick format)
//args[3]: output file
//e.g.: dump.trump.160 worobey-con-sc-resume-162-taxa.xml newtree.nwk restart.dump
public static void main(String[] args) {
if (args.length != 4) {
throw new RuntimeException("Incorrect number of arguments.");
}
try {
FileReader fileIn = new FileReader(args[2]);
BufferedReader in = new BufferedReader(fileIn);
String fullTree = in.readLine();
NewickImporter importer = new NewickImporter(fullTree);
Tree tree = importer.importNextTree();
//assume rootHeight in dumpfile is ALWAYS followed by all the nodeHeights
System.out.println("root height: " + tree.getNodeHeight(tree.getRoot()));
FileReader dumpFileIn = new FileReader(args[0]);
BufferedReader dumpIn = new BufferedReader(dumpFileIn);
FileWriter dumpFileOut = new FileWriter(args[3]);
BufferedWriter dumpOut = new BufferedWriter(dumpFileOut);
String original = dumpIn.readLine();
String[] fields = original.split("\t");
//write new rootHeight to new output dump file
while (!fields[0].equals("treeModel.rootHeight")) {
if (DEBUG) {
System.out.println(original);
}
dumpOut.write(original + "\n");
original = dumpIn.readLine();
fields = original.split("\t");
}
fields[2] = Double.toString(tree.getNodeHeight(tree.getRoot()));
for (int i = 0; i < fields.length; i++) {
dumpOut.write(fields[i] + "\t");
}
dumpOut.write("\n");
//write all new node heights to new output dump file
int nodeCount = tree.getNodeCount();
if (DEBUG) {
System.out.println(nodeCount + " nodes found in tree.");
}
for (int i = 0; i < (nodeCount - 1); i++) {
if (DEBUG) {
System.out.println(tree.getNode(i).getNumber() + "\t" + tree.getNodeHeight(tree.getNode(i)));
}
dumpOut.write(tree.getNode(i).getNumber() + "\t1\t" + tree.getNodeHeight(tree.getNode(i)) + "\n");
}
//skip all the node heights in the original dump file
//no clue as to how many there are ...
//best I can tell only node heights have integers as parameter names
original = dumpIn.readLine();
if (DEBUG) {
System.out.println(original);
}
fields = original.split("\t");
while (isInteger(fields[0])) {
original = dumpIn.readLine();
fields = original.split("\t");
}
while (!fields[0].equals("treeModel")) {
dumpOut.write(original + "\n");
original = dumpIn.readLine();
if (DEBUG) {
System.out.println(original);
}
fields = original.split("\t");
}
dumpOut.write(fields[0] + "\t" + fullTree);
dumpOut.flush();
dumpOut.close();
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("Tree file not found.");
} catch (IOException ioe) {
throw new RuntimeException("Unable to read file: " + ioe.getMessage());
} catch (Importer.ImportException ie) {
throw new RuntimeException("Unable to import tree: " + ie.getMessage());
}
}
use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.
the class ARGAddRemoveOperatorTest method setUp.
public void setUp() throws Exception {
super.setUp();
NewickImporter importer = new NewickImporter("(((A:1.0,B:1.0):1.0,C:2.0):1.0,D:3.0);");
arg4 = new ARGModel(importer.importTree(null));
arg4.setupHeightBounds();
arg4.addLikelihoodCalculator(null);
arg4.addLikelihoodCalculator(null);
importer = new NewickImporter("((((A:1.0,B:1.0):1.0,C:2.0):1.0,D:3.0):1.0, E:4.0);");
ARGModel arg5 = new ARGModel(importer.importTree(null));
importer = new NewickImporter("(((((A:1.0,B:1.0):1.0,C:2.0):1.0,D:3.0):1.0, E:4.0),F:5.0);");
ARGModel arg6 = new ARGModel(importer.importTree(null));
}
use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.
the class AncestralStateBeagleTreeLikelihoodTest method setUp.
public void setUp() throws Exception {
super.setUp();
MathUtils.setSeed(666);
NewickImporter importer = new NewickImporter("(0:2.0,(1:1.0,2:1.0):1.0);");
tree = (FlexibleTree) importer.importTree(null);
}
use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.
the class ContinuousTraitLikelihood method main.
public static void main(String[] args) throws Exception {
String testTree = "((A:1, B:1):1,(C:1, D:1):1);";
NewickImporter newickImporter = new NewickImporter(new StringReader(testTree));
MutableTree tree = (MutableTree) newickImporter.importTree(null);
tree.setTaxonAttribute(0, "U1", new Continuous(1.10));
tree.setTaxonAttribute(1, "U1", new Continuous(1.95));
tree.setTaxonAttribute(2, "U1", new Continuous(3.15));
tree.setTaxonAttribute(3, "U1", new Continuous(4.39));
tree.setTaxonAttribute(0, "U2", new Continuous(5.2));
tree.setTaxonAttribute(1, "U2", new Continuous(3.8));
tree.setTaxonAttribute(2, "U2", new Continuous(3.1));
tree.setTaxonAttribute(3, "U2", new Continuous(1.95));
ContinuousTraitLikelihood ctLikelihood = new ContinuousTraitLikelihood();
Contrastable[] mles = new Contrastable[2];
double logL = ctLikelihood.calculateLikelihood(tree, new String[] { "U1", "U2" }, mles, 1.0);
System.out.println("logL = " + logL);
System.out.println("mle(trait1) = " + mles[0]);
System.out.println("mle(trait2) = " + mles[1]);
Contrastable[] mle = new Contrastable[1];
System.out.println("logL (trait1) = " + ctLikelihood.calculateLikelihood(tree, new String[] { "U1" }, mle, 1.0));
System.out.println("mle(trait1) = " + mle[0]);
System.out.println("logL (trait2) = " + ctLikelihood.calculateLikelihood(tree, new String[] { "U2" }, mle, 1.0));
System.out.println("mle(trait2) = " + mle[0]);
}
use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.
the class SPPathDifferenceMetric method main.
public static void main(String[] args) {
try {
NewickImporter importer = new NewickImporter("(('A':1.2,'B':0.8):0.5,('C':0.8,'D':1.0):1.1)");
Tree treeOne = importer.importNextTree();
System.out.println("tree 1: " + treeOne);
importer = new NewickImporter("((('A':0.8,'B':1.4):0.3,'C':0.7):0.9,'D':1.0)");
Tree treeTwo = importer.importNextTree();
System.out.println("tree 2: " + treeTwo + "\n");
double metric = (new SPPathDifferenceMetric().getMetric(treeOne, treeTwo));
System.out.println("path difference = " + metric);
//Additional test for comparing a collection of trees against a (fixed) focal tree
SPPathDifferenceMetric fixed = new SPPathDifferenceMetric(treeOne);
metric = fixed.getMetric(treeTwo);
System.out.println("path difference = " + metric);
} catch (Importer.ImportException ie) {
System.err.println(ie);
} catch (IOException ioe) {
System.err.println(ioe);
}
}
Aggregations