Search in sources :

Example 6 with FlexibleTree

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

the class TiterImporter method importTrees.

/**
     * importTrees.
     */
public Tree[] importTrees(TaxonList taxonList) throws IOException, ImportException {
    boolean done = false;
    ArrayList<FlexibleTree> array = new ArrayList<FlexibleTree>();
    do {
        try {
            skipUntil("(");
            unreadCharacter('(');
            FlexibleNode root = readInternalNode(taxonList);
            FlexibleTree tree = new FlexibleTree(root, false, true);
            array.add(tree);
            if (taxonList == null) {
                taxonList = tree;
            }
            if (readCharacter() != ';') {
                throw new BadFormatException("Expecting ';' after tree");
            }
        } catch (EOFException e) {
            done = true;
        }
    } while (!done);
    Tree[] trees = new Tree[array.size()];
    array.toArray(trees);
    return trees;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleNode(dr.evolution.tree.FlexibleNode) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree)

Example 7 with FlexibleTree

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

the class TaxaOriginTrait method tabulateOrigins.

private void tabulateOrigins() {
    HashMap<String, Integer> countsMap = new HashMap<String, Integer>();
    int count = 0;
    for (FlexibleTree currentTree : trees) {
        if (count % 1 == 0) {
            System.out.println("Doing tree " + count);
        }
        HashMap<String, String> results = getIncomingJumpOrigins(currentTree);
        for (String key : results.keySet()) {
            int oldCount = countsMap.containsKey(results.get(key)) ? countsMap.get(results.get(key)) : 0;
            countsMap.put(results.get(key), oldCount + 1);
        }
        count++;
    }
    try {
        BufferedWriter outWriter = new BufferedWriter(new FileWriter(fileNameRoot + ".csv"));
        for (String key : countsMap.keySet()) {
            outWriter.write(key + "," + countsMap.get(key) + "\n");
        }
        outWriter.flush();
    } catch (IOException e) {
        System.out.println("Failed to write to file");
    }
}
Also used : HashMap(java.util.HashMap) FlexibleTree(dr.evolution.tree.FlexibleTree)

Example 8 with FlexibleTree

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

the class TaxaOriginTrait method getTraitName.

private String getTraitName() {
    FlexibleTree tree = trees[0];
    String traitName = null;
    for (int i = 0; i < tree.getExternalNodeCount(); i++) {
        NodeRef node = tree.getExternalNode(i);
        for (String taxaName : taxaNames) {
            if (tree.getNodeTaxon(node).getId().equals(taxaName)) {
                String attributeValue = (String) tree.getNodeAttribute(node, attributeName);
                if (traitName != null && !traitName.equals(attributeValue)) {
                    throw new RuntimeException("Not all taxa given have the same trait value");
                } else {
                    traitName = attributeValue;
                }
            }
        }
    }
    return traitName;
}
Also used : NodeRef(dr.evolution.tree.NodeRef) FlexibleTree(dr.evolution.tree.FlexibleTree)

Example 9 with FlexibleTree

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

the class SimulateTrait method simulate.

/**
	 * simulates a trait ona tree.
	 * @param clone if true, use copy of the tree, otherwise use given tree
	 * @return the simulated tree.
	 */
public Tree simulate(Tree tree, double value, boolean clone) {
    Tree binaryTree = null;
    if (clone) {
        binaryTree = new FlexibleTree(tree);
        ((FlexibleTree) binaryTree).resolveTree();
    } else {
        binaryTree = tree;
    }
    simulate((MutableTree) binaryTree, binaryTree.getRoot(), value);
    return binaryTree;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree) MutableTree(dr.evolution.tree.MutableTree)

Example 10 with FlexibleTree

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

the class NewickImporter method importTrees.

/**
     * importTrees.
     */
public Tree[] importTrees(TaxonList taxonList) throws IOException, ImportException {
    boolean done = false;
    ArrayList<FlexibleTree> array = new ArrayList<FlexibleTree>();
    do {
        try {
            skipUntil("(");
            unreadCharacter('(');
            FlexibleNode root = readInternalNode(taxonList);
            FlexibleTree tree = new FlexibleTree(root, false, true);
            array.add(tree);
            if (taxonList == null) {
                taxonList = tree;
            }
            if (readCharacter() != ';') {
                throw new BadFormatException("Expecting ';' after tree");
            }
        } catch (EOFException e) {
            done = true;
        }
    } while (!done);
    Tree[] trees = new Tree[array.size()];
    array.toArray(trees);
    return trees;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleNode(dr.evolution.tree.FlexibleNode) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree)

Aggregations

FlexibleTree (dr.evolution.tree.FlexibleTree)27 FlexibleNode (dr.evolution.tree.FlexibleNode)12 Tree (dr.evolution.tree.Tree)8 NodeRef (dr.evolution.tree.NodeRef)7 EOFException (java.io.EOFException)6 NexusExporter (dr.app.tools.NexusExporter)5 NewickImporter (dr.evolution.io.NewickImporter)3 TreeModel (dr.evomodel.tree.TreeModel)3 IOException (java.io.IOException)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 Importer (dr.evolution.io.Importer)2 NexusImporter (dr.evolution.io.NexusImporter)2 Regression (dr.stats.Regression)2 HashMap (java.util.HashMap)2 TreeExporter (dr.evolution.io.TreeExporter)1 TreeImporter (dr.evolution.io.TreeImporter)1 MutableTree (dr.evolution.tree.MutableTree)1 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)1 ImportancePruneAndRegraft (dr.evomodel.operators.ImportancePruneAndRegraft)1