Search in sources :

Example 46 with NewickImporter

use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.

the class TreeStatFrame method importFromFile.

protected void importFromFile(File file) throws IOException, Importer.ImportException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String line = reader.readLine();
    Tree tree = null;
    if (line.toUpperCase().startsWith("#NEXUS")) {
        NexusImporter importer = new NexusImporter(reader);
        tree = importer.importTree(null);
    } else {
        reader.close();
        reader = new BufferedReader(new FileReader(file));
        NewickImporter importer = new NewickImporter(reader);
        tree = importer.importTree(null);
    }
    treeStatData.allTaxa = TreeUtils.getLeafSet(tree);
    statusLabel.setText(Integer.toString(treeStatData.allTaxa.size()) + " taxa loaded.");
    reader.close();
    fireDataChanged();
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree)

Example 47 with NewickImporter

use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.

the class KCPathDifferenceMetric method main.

public static void main(String[] args) {
    try {
        //4-taxa example
        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("4-taxa 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("4-taxa tree 2: " + treeTwo + "\n");
        ArrayList<Double> lambdaValues = new ArrayList<Double>();
        lambdaValues.add(0.0);
        lambdaValues.add(0.5);
        lambdaValues.add(1.0);
        List<Double> metric = (new KCPathDifferenceMetric().getMetric(treeOne, treeTwo, lambdaValues));
        List<Double> metric_old = (new KCPathDifferenceMetric().getMetric_old(treeOne, treeTwo, lambdaValues));
        System.out.println("\nPaired trees:");
        System.out.println("lambda (0.0) = " + metric.get(0) + " old = " + metric_old.get(0));
        System.out.println("lambda (0.5) = " + metric.get(1) + " old = " + metric_old.get(1));
        System.out.println("lambda (1.0) = " + metric.get(2) + " old = " + metric_old.get(2));
        //Additional test for comparing a collection of trees against a (fixed) focal tree
        metric = new KCPathDifferenceMetric(treeOne).getMetric(treeTwo, lambdaValues);
        metric_old = new KCPathDifferenceMetric(treeOne).getMetric_old(treeTwo, lambdaValues);
        System.out.println("\nFocal trees:");
        System.out.println("lambda (0.0) = " + metric.get(0) + " old = " + metric_old.get(0));
        System.out.println("lambda (0.5) = " + metric.get(1) + " old = " + metric_old.get(1));
        System.out.println("lambda (1.0) = " + metric.get(2) + " old = " + metric_old.get(2));
        //5-taxa example
        importer = new NewickImporter("(((('A':0.6,'B':0.6):0.1,'C':0.5):0.4,'D':0.7):0.1,'E':1.3)");
        treeOne = importer.importNextTree();
        System.out.println("5-taxa tree 1: " + treeOne);
        importer = new NewickImporter("((('A':0.8,'B':1.4):0.1,'C':0.7):0.2,('D':1.0,'E':0.9):1.3)");
        treeTwo = importer.importNextTree();
        System.out.println("5-taxa tree 2: " + treeTwo + "\n");
        //lambda = 0.0 should yield: sqrt(7) = 2.6457513110645907162
        //lambda = 1.0 should yield: sqrt(2.96) = 1.7204650534085252911
        lambdaValues = new ArrayList<Double>();
        lambdaValues.add(0.0);
        lambdaValues.add(0.5);
        lambdaValues.add(1.0);
        metric = (new KCPathDifferenceMetric().getMetric(treeOne, treeTwo, lambdaValues));
        System.out.println("\nPaired trees:");
        System.out.println("lambda (0.0) = " + metric.get(0) + " old = " + metric_old.get(0));
        System.out.println("lambda (0.5) = " + metric.get(1) + " old = " + metric_old.get(1));
        System.out.println("lambda (1.0) = " + metric.get(2) + " old = " + metric_old.get(2));
        //Additional test for comparing a collection of trees against a (fixed) focal tree
        metric = new KCPathDifferenceMetric(treeOne).getMetric(treeTwo, lambdaValues);
        System.out.println("\nFocal trees:");
        System.out.println("lambda (0.0) = " + metric.get(0) + " old = " + metric_old.get(0));
        System.out.println("lambda (0.5) = " + metric.get(1) + " old = " + metric_old.get(1));
        System.out.println("lambda (1.0) = " + metric.get(2) + " old = " + metric_old.get(2));
        //timings
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            new KCPathDifferenceMetric().getMetric_old(treeOne, treeTwo, lambdaValues);
        }
        System.out.println("Old algorithm: " + (System.currentTimeMillis() - startTime) + " ms");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            new KCPathDifferenceMetric().getMetric(treeOne, treeTwo, lambdaValues);
        }
        System.out.println("New algorithm: " + (System.currentTimeMillis() - startTime) + " ms");
    } 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)

Example 48 with NewickImporter

use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.

the class TreeMetrics method main.

public static final void main(String[] args) throws Exception {
    FileReader reader = new FileReader(args[0]);
    NewickImporter importer = new NewickImporter(reader);
    Tree[] trees = importer.importTrees(null);
    System.out.println("Imported " + trees.length + " trees...");
    analyze(trees, 1000);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) FileReader(java.io.FileReader)

Example 49 with NewickImporter

use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.

the class GMRFFixedGridLikelihood method run.

public static void run() throws Exception {
    NewickImporter importer = new NewickImporter("((((5:0.5,1:0.2):0.5,0:1):0.2,2:0.8):0.2,3:1.4)");
    Tree tree = importer.importNextTree();
    double[] data = new double[15];
    double[] times = new double[15];
    data[0] = 1.0;
    times[0] = 0.05;
    for (int i = 1; i < data.length; i++) {
        data[i] = data[i - 1] + 0.5;
        times[i] = times[i - 1] + 0.1;
    }
    GMRFFixedGridLikelihood like = new GMRFFixedGridLikelihood(tree, new Parameter.Default(data), new Parameter.Default(times), 4);
    System.out.println(like.getLogLikelihood());
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree) Parameter(dr.inference.model.Parameter) MatrixParameter(dr.inference.model.MatrixParameter)

Example 50 with NewickImporter

use of dr.evolution.io.NewickImporter in project beast-mcmc by beast-dev.

the class OperatorAssert method setUp.

public void setUp() throws Exception {
    super.setUp();
    MathUtils.setSeed(666);
    NewickImporter importer = new NewickImporter("((((A:1.0,B:1.0):1.0,C:2.0):1.0,D:3.0):1.0,E:4.0);");
    tree5 = (FlexibleTree) 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);");
    tree6 = (FlexibleTree) importer.importTree(null);
}
Also used : 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