Search in sources :

Example 26 with Tree

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

the class RateStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final String name = xo.getAttribute(Statistic.NAME, xo.getId());
    final Tree tree = (Tree) xo.getChild(Tree.class);
    final BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    final boolean internal = xo.getBooleanAttribute("internal");
    final boolean external = xo.getBooleanAttribute("external");
    if (!(internal || external)) {
        throw new XMLParseException("At least one of internal and external must be true!");
    }
    final String mode = xo.getStringAttribute(MODE);
    return new RateStatistic(name, tree, branchRateModel, external, internal, mode);
}
Also used : BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) RateStatistic(dr.evomodel.tree.RateStatistic) Tree(dr.evolution.tree.Tree)

Example 27 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 28 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 29 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 30 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)

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