Search in sources :

Example 11 with FlexibleTree

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

the class NewickImporter method importNextTree.

/**
     * import the next tree.
     * return the tree or null if no more trees are available
     */
public Tree importNextTree() throws IOException, ImportException {
    FlexibleTree tree = null;
    try {
        skipUntil("(");
        unreadCharacter('(');
        FlexibleNode root = readInternalNode(lastTree);
        tree = new FlexibleTree(root, false, true);
    } catch (EOFException e) {
    //
    }
    lastTree = tree;
    return tree;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleNode(dr.evolution.tree.FlexibleNode) EOFException(java.io.EOFException)

Example 12 with FlexibleTree

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

the class NewickImporter method importTree.

/**
     * importTree.
     */
public Tree importTree(TaxonList taxonList) throws IOException, ImportException {
    setCommentDelimiters('[', ']', '\0', '\0', '&');
    try {
        skipUntil("(");
        unreadCharacter('(');
        final FlexibleNode root = readInternalNode(taxonList);
        if (getLastMetaComment() != null) {
            root.setAttribute(COMMENT, getLastMetaComment());
        }
        return new FlexibleTree(root, false, true);
    } catch (EOFException e) {
        throw new ImportException("incomplete tree");
    }
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleNode(dr.evolution.tree.FlexibleNode) EOFException(java.io.EOFException)

Example 13 with FlexibleTree

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

the class PathogenFrame method readFromFile.

protected boolean readFromFile(File file) throws IOException {
    Reader reader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(reader);
    String line = bufferedReader.readLine();
    while (line != null && line.length() == 0) {
        line = bufferedReader.readLine();
    }
    boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS"));
    reader = new FileReader(file);
    Tree tree = null;
    try {
        if (isNexus) {
            NexusImporter importer = new NexusImporter(reader);
            tree = importer.importTree(taxa);
        } else {
            NewickImporter importer = new NewickImporter(reader);
            tree = importer.importTree(taxa);
        }
    } catch (Importer.ImportException ime) {
        JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE);
        ime.printStackTrace();
        return false;
    } catch (IOException ioex) {
        JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
        ioex.printStackTrace();
        return false;
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
        ex.printStackTrace();
        return false;
    }
    if (tree == null) {
        JOptionPane.showMessageDialog(this, "The file is not in a suitable format or contains no trees.", "Error reading file", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    FlexibleTree binaryTree = new FlexibleTree(tree, true);
    binaryTree.resolveTree();
    trees.add(binaryTree);
    if (taxa == null) {
        taxa = binaryTree;
    }
    getExportTreeAction().setEnabled(true);
    getExportDataAction().setEnabled(true);
    return true;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree)

Example 14 with FlexibleTree

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

the class PathogenFrame method writeTimeTreeFile.

protected void writeTimeTreeFile(PrintStream ps) throws IOException {
    FlexibleTree tree = new FlexibleTree(pathogenPanel.getTreeAsViewed());
    Regression r = pathogenPanel.getTemporalRooting().getRootToTipRegression(pathogenPanel.getTreeAsViewed());
    for (int i = 0; i < tree.getInternalNodeCount(); i++) {
        NodeRef node = tree.getInternalNode(i);
        double height = tree.getNodeHeight(node);
        tree.setNodeHeight(node, height / r.getGradient());
    }
    TreeUtils.setHeightsFromDates(tree);
    NexusExporter nexusExporter = new NexusExporter(new PrintStream(ps));
    nexusExporter.exportTree(tree);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) NexusExporter(dr.app.tools.NexusExporter) FlexibleTree(dr.evolution.tree.FlexibleTree) Regression(dr.stats.Regression)

Example 15 with FlexibleTree

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

the class MapperFrame method readFromFile.

protected boolean readFromFile(File file) throws IOException {
    Reader reader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(reader);
    String line = bufferedReader.readLine();
    while (line != null && line.length() == 0) {
        line = bufferedReader.readLine();
    }
    boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS"));
    reader = new FileReader(file);
    Tree tree = null;
    try {
    //            if (isNexus) {
    //                NexusImporter importer = new NexusImporter(reader);
    //                tree = importer.importTree(taxa);
    //            } else {
    //                NewickImporter importer = new NewickImporter(reader);
    //                tree = importer.importTree(taxa);
    //            }
    //        } catch (Importer.ImportException ime) {
    //            JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime,
    //                    "Error reading file",
    //                    JOptionPane.ERROR_MESSAGE);
    //            ime.printStackTrace();
    //            return false;
    //        } catch (IOException ioex) {
    //            JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex,
    //                    "File I/O Error",
    //                    JOptionPane.ERROR_MESSAGE);
    //            ioex.printStackTrace();
    //            return false;
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
        ex.printStackTrace();
        return false;
    }
    if (tree == null) {
        JOptionPane.showMessageDialog(this, "The file is not in a suitable format or contains no trees.", "Error reading file", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    FlexibleTree binaryTree = new FlexibleTree(tree, true);
    binaryTree.resolveTree();
    trees.add(binaryTree);
    //        if (taxa == null) {
    //            taxa = binaryTree;
    //        }
    getExportDataAction().setEnabled(true);
    return true;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree) TraceException(dr.inference.trace.TraceException)

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