Search in sources :

Example 31 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class SpeciesTreeStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Tree speciesTree = (Tree) xo.getElementFirstChild("speciesTree");
    Tree popTree = (Tree) xo.getElementFirstChild("populationTree");
    return new SpeciesTreeStatistic(name, speciesTree, popTree);
}
Also used : Tree(dr.evolution.tree.Tree) SpeciesTreeStatistic(dr.evomodel.tree.SpeciesTreeStatistic)

Example 32 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class TerminalBranchStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Tree tree = (Tree) xo.getChild(Tree.class);
    return new TerminalBranchStatistic(name, tree);
}
Also used : TerminalBranchStatistic(dr.evomodel.tree.TerminalBranchStatistic) Tree(dr.evolution.tree.Tree)

Example 33 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class TimeSlicer method readAndAnalyzeTrees.

//    private List<Tree> importTrees(String treeFileName, int burnin) throws IOException, Importer.ImportException {
//
//        int totalTrees = 10000;
//
//        progressStream.println("Reading trees (bar assumes 10,000 trees)...");
//        progressStream.println("0              25             50             75            100");
//        progressStream.println("|--------------|--------------|--------------|--------------|");
//
//        int stepSize = totalTrees / 60;
//        if (stepSize < 1) stepSize = 1;
//
//        List<Tree> treeList = new ArrayList<Tree>();
//        BufferedReader reader1 = new BufferedReader(new FileReader(treeFileName));
//
//        String line1 = reader1.readLine();
//        TreeImporter importer1;
//        if (line1.toUpperCase().startsWith("#NEXUS")) {
//            importer1 = new NexusImporter(new FileReader(treeFileName));
//        } else {
//            importer1 = new NewickImporter(new FileReader(treeFileName));
//        }
//        totalTrees = 0;
//        while (importer1.hasTree()) {
//            Tree treeTime = importer1.importNextTree();
//
//            if (totalTrees > burnin)
//                treeList.add(treeTime);
//
//            if (totalTrees > 0 && totalTrees % stepSize == 0) {
//                progressStream.print("*");
//                progressStream.flush();
//            }
//            totalTrees++;
//        }
//        return treeList;
//    }
private void readAndAnalyzeTrees(String treeFileName, int burnin, int skipEvery, String[] traits, double[] slices, boolean impute, boolean trueNoise, Normalization normalize, boolean divideByBranchLength, BranchSet branchset, Set taxaSet) throws IOException, Importer.ImportException {
    int totalTrees = 10000;
    int totalStars = 0;
    progressStream.println("Reading and analyzing trees (bar assumes 10,000 trees)...");
    progressStream.println("0              25             50             75            100");
    progressStream.println("|--------------|--------------|--------------|--------------|");
    int stepSize = totalTrees / 60;
    if (stepSize < 1)
        stepSize = 1;
    BufferedReader reader1 = new BufferedReader(new FileReader(treeFileName));
    String line1 = reader1.readLine();
    TreeImporter importer1;
    if (line1.toUpperCase().startsWith("#NEXUS")) {
        importer1 = new NexusImporter(new FileReader(treeFileName));
    } else {
        importer1 = new NewickImporter(new FileReader(treeFileName));
    }
    totalTrees = 0;
    while (importer1.hasTree()) {
        Tree treeTime = importer1.importNextTree();
        if (totalTrees % skipEvery == 0) {
            treesRead++;
            if (totalTrees >= burnin) {
                analyzeTree(treeTime, traits, slices, impute, trueNoise, normalize, divideByBranchLength, branchset, taxaSet);
            }
        }
        if (totalTrees > 0 && totalTrees % stepSize == 0) {
            progressStream.print("*");
            totalStars++;
            if (totalStars % 61 == 0)
                progressStream.print("\n");
            progressStream.flush();
        }
        totalTrees++;
    }
    progressStream.print("\n");
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) NewickImporter(dr.evolution.io.NewickImporter) TreeImporter(dr.evolution.io.TreeImporter) Tree(dr.evolution.tree.Tree)

Example 34 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class GetDateFromTree method getRandomTree.

private static Tree getRandomTree() {
    Random random = new Random();
    // [1, 10]
    int c = random.nextInt(10) + 1;
    // [1000, 10000]
    int tId = random.nextInt(9000) + 1000;
    try {
        System.out.println("randomly get " + tId + "th tree from " + pathInput + c + inputFileName + "\n\n");
        FileReader fileReader = new FileReader(pathInput + c + inputFileName);
        // many trees
        GetDateFromTree getDateFromTree = new GetDateFromTree(fileReader);
        int totalTrees = 0;
        try {
            while (getDateFromTree.hasTree()) {
                Tree tree = getDateFromTree.importNextTree();
                totalTrees++;
                if (totalTrees == tId) {
                    return tree;
                }
            }
        } catch (ImportException e) {
            System.err.println("Error Parsing Input Tree: " + e.getMessage());
            return null;
        }
        fileReader.close();
    } catch (FileNotFoundException e) {
        //To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    } catch (IOException e) {
        //To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
    return null;
}
Also used : Random(java.util.Random) Tree(dr.evolution.tree.Tree)

Example 35 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class GetDateFromTree method getDate.

private static void getDate(String curD, int index, Tree treeOne) throws ImportException {
    // many trees
    double rootHeight;
    DecimalFormat twoDForm = new DecimalFormat("####0.##");
    Tree[] trees = new Tree[combiTrees];
    double[][] tips = new double[combiTrees][treeOne.getExternalNodeCount() + 1];
    double[] origins = new double[trees.length];
    trees[0] = treeOne;
    for (int t = 1; t < combiTrees; t++) {
        trees[t] = getRandomTree();
        if (trees[t] == null)
            throw new ImportException("get null random tree");
    //            System.out.println(t + " => " + trees[t].toString());
    }
    for (int t = 0; t < trees.length; t++) {
        System.out.println(t + " => " + trees[t]);
        for (int i = 0; i < trees[t].getTaxonCount(); i++) {
            FlexibleNode node = (FlexibleNode) trees[t].getExternalNode(i);
            //                System.out.println(node.getTaxon() + " has " + node.getHeight());
            tips[t][Integer.parseInt(node.getTaxon().getId())] = node.getHeight();
        }
        rootHeight = ((FlexibleNode) trees[t].getRoot()).getHeight();
        origins[t] = Double.valueOf(twoDForm.format(rootHeight + 100.0));
        System.out.println("tree " + t + " root height = " + rootHeight + " origin = " + origins[t]);
        System.out.println("\n");
    }
    if (index < 0) {
        printXML(tips[0]);
    } else {
        try {
            outputBDSSXML(curD, index, tips, origins, trees);
        //                outputExponetialXML(curD, index, tips, origins, trees);
        } catch (IOException e) {
            //To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        }
    }
    System.out.println("\n");
}
Also used : DecimalFormat(java.text.DecimalFormat) FlexibleNode(dr.evolution.tree.FlexibleNode) Tree(dr.evolution.tree.Tree)

Aggregations

Tree (dr.evolution.tree.Tree)128 NewickImporter (dr.evolution.io.NewickImporter)32 ArrayList (java.util.ArrayList)31 TreeModel (dr.evomodel.tree.TreeModel)26 Parameter (dr.inference.model.Parameter)26 NexusImporter (dr.evolution.io.NexusImporter)18 TaxonList (dr.evolution.util.TaxonList)18 Taxa (dr.evolution.util.Taxa)17 FlexibleTree (dr.evolution.tree.FlexibleTree)16 Taxon (dr.evolution.util.Taxon)15 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)15 NodeRef (dr.evolution.tree.NodeRef)14 SimpleTree (dr.evolution.tree.SimpleTree)13 ImportException (dr.evolution.io.Importer.ImportException)12 Importer (dr.evolution.io.Importer)11 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)11 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)10 Partition (dr.app.beagle.tools.Partition)10 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)10 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)9