Search in sources :

Example 31 with NewickImporter

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());
    }
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree) Importer(dr.evolution.io.Importer) NewickImporter(dr.evolution.io.NewickImporter)

Example 32 with NewickImporter

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));
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) ARGModel(dr.evomodel.arg.ARGModel)

Example 33 with NewickImporter

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);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter)

Example 34 with NewickImporter

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]);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) StringReader(java.io.StringReader)

Example 35 with NewickImporter

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);
    }
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) IOException(java.io.IOException) Importer(dr.evolution.io.Importer) NewickImporter(dr.evolution.io.NewickImporter)

Aggregations

NewickImporter (dr.evolution.io.NewickImporter)53 Tree (dr.evolution.tree.Tree)32 TreeModel (dr.evomodel.tree.TreeModel)21 ArrayList (java.util.ArrayList)13 Parameter (dr.inference.model.Parameter)12 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)11 IOException (java.io.IOException)10 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)9 Partition (dr.app.beagle.tools.Partition)9 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)9 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)9 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)9 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)9 ImportException (dr.evolution.io.Importer.ImportException)8 NexusImporter (dr.evolution.io.NexusImporter)8 Importer (dr.evolution.io.Importer)7 Taxon (dr.evolution.util.Taxon)7 Taxa (dr.evolution.util.Taxa)6 HKY (dr.evomodel.substmodel.nucleotide.HKY)6 TreeImporter (dr.evolution.io.TreeImporter)5