Search in sources :

Example 61 with Tree

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

the class NexusImporter method importNextTree.

/**
     * import the next tree.
     * return the tree or null if no more trees are available
     */
public Tree importNextTree() throws IOException, ImportException {
    // call hasTree to do the hard work...
    if (!hasTree()) {
        isReadingTreesBlock = false;
        return null;
    }
    Tree tree = nextTree;
    nextTree = null;
    return tree;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree)

Example 62 with Tree

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

the class DataModelImporter method importNexusFile.

// nexus
private void importNexusFile(File file, DateGuesser guesser, Map dataModel) throws IOException, ImportException {
    TaxonList taxa = null;
    SimpleAlignment alignment = null;
    List<Tree> trees = new ArrayList<Tree>();
    List<NexusApplicationImporter.CharSet> charSets = new ArrayList<NexusApplicationImporter.CharSet>();
    try {
        FileReader reader = new FileReader(file);
        NexusApplicationImporter importer = new NexusApplicationImporter(reader);
        boolean done = false;
        while (!done) {
            try {
                NexusBlock block = importer.findNextBlock();
                if (block == NexusImporter.TAXA_BLOCK) {
                    if (taxa != null) {
                        throw new MissingBlockException("TAXA block already defined");
                    }
                    taxa = importer.parseTaxaBlock();
                    dataModel.put("taxa", createTaxonList(taxa));
                } else if (block == NexusImporter.CALIBRATION_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA or DATA block must be defined before a CALIBRATION block");
                    }
                    importer.parseCalibrationBlock(taxa);
                } else if (block == NexusImporter.CHARACTERS_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA block must be defined before a CHARACTERS block");
                    }
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    alignment = (SimpleAlignment) importer.parseCharactersBlock(taxa);
                } else if (block == NexusImporter.DATA_BLOCK) {
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    // A data block doesn't need a taxon block before it
                    // but if one exists then it will use it.
                    alignment = (SimpleAlignment) importer.parseDataBlock(taxa);
                    if (taxa == null) {
                        taxa = alignment;
                    }
                } else if (block == NexusImporter.TREES_BLOCK) {
                    // I guess there is no reason not to allow multiple trees blocks
                    //                        if (trees.size() > 0) {
                    //                            throw new MissingBlockException("TREES block already defined");
                    //                        }
                    Tree[] treeArray = importer.parseTreesBlock(taxa);
                    trees.addAll(Arrays.asList(treeArray));
                    if (taxa == null && trees.size() > 0) {
                        taxa = trees.get(0);
                    }
                } else if (block == NexusApplicationImporter.ASSUMPTIONS_BLOCK) {
                    importer.parseAssumptionsBlock(charSets);
                } else {
                // Ignore the block..
                }
            } catch (EOFException ex) {
                done = true;
            }
        }
        reader.close();
        // Allow the user to load taxa only (perhaps from a tree file) so that they can sample from a prior...
        if (alignment == null && taxa == null) {
            throw new MissingBlockException("TAXON, DATA or CHARACTERS block is missing");
        }
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    //        } catch (Exception e) {
    //            throw new Exception(e.getMessage());
    }
    setData(dataModel, guesser, file.getName(), taxa, null, alignment, charSets, null, trees);
}
Also used : TaxonList(dr.evolution.util.TaxonList) ImportException(dr.evolution.io.Importer.ImportException) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) NexusBlock(dr.evolution.io.NexusImporter.NexusBlock) Tree(dr.evolution.tree.Tree) MissingBlockException(dr.evolution.io.NexusImporter.MissingBlockException)

Example 63 with Tree

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

the class DataModelImporter method importFromTreeFile.

public Map importFromTreeFile(String fileName, Map dataModel) throws IOException, Importer.ImportException {
    Tree tree = null;
    try {
        Reader reader = new FileReader(fileName);
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line = bufferedReader.readLine();
        while (line != null && line.length() == 0) {
            line = bufferedReader.readLine();
        }
        reader = new FileReader(fileName);
        if ((line != null && line.toUpperCase().contains("#NEXUS"))) {
            // is a NEXUS file
            NexusImporter importer = new NexusImporter(reader);
            tree = importer.importNextTree();
        } else {
            NewickImporter importer = new NewickImporter(reader);
            tree = importer.importNextTree();
        }
        bufferedReader.close();
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }
    if (tree != null) {
        dataModel.put("tree", TreeUtils.newick(tree));
    }
    return dataModel;
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree)

Example 64 with Tree

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

the class OldTreesPanel method setOptions.

public void setOptions(BeautiOptions options) {
    this.options = options;
    settingOptions = true;
    //        treePriorCombo.setSelectedItem(options.nodeHeightPrior);
    //
    //        groupCountField.setValue(options.skylineGroupCount);
    //        //samplingProportionField.setValue(options.birthDeathSamplingProportion);
    //
    //        parameterizationCombo.setSelectedIndex(options.parameterization);
    //        bayesianSkylineCombo.setSelectedIndex(options.skylineModel);
    //
    //        extendedBayesianSkylineCombo.setSelectedIndex(options.multiLoci ? 1 : 0);
    //
    //        gmrfBayesianSkyrideCombo.setSelectedIndex(options.skyrideSmoothing);
    //
    //        startingTreeCombo.setSelectedItem(options.startingTreeType);
    userTreeCombo.removeAllItems();
    if (options.userTrees.size() == 0) {
        userTreeCombo.addItem("no trees loaded");
        userTreeCombo.setEnabled(false);
    } else {
        for (Tree tree : options.userTrees) {
            userTreeCombo.addItem(tree.getId());
        }
        userTreeCombo.setEnabled(true);
    }
    setupPanel();
    settingOptions = false;
    validate();
    repaint();
}
Also used : UPGMATree(dr.evolution.tree.UPGMATree) NeighborJoiningTree(dr.evolution.tree.NeighborJoiningTree) Tree(dr.evolution.tree.Tree)

Example 65 with Tree

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

the class PartitionTreeModelPanel method setUserSpecifiedStartingTree.

private void setUserSpecifiedStartingTree() {
    if (userTreeCombo.getSelectedItem() != null && (!userTreeCombo.getSelectedItem().toString().equalsIgnoreCase(NO_TREE))) {
        Tree seleTree = getSelectedUserTree();
        if (seleTree == null || isBifurcatingTree(seleTree, seleTree.getRoot())) {
            partitionTreeModel.setUserStartingTree(seleTree);
        } else {
            JOptionPane.showMessageDialog(parent, "The selected user-specified starting tree " + "is not fully bifurcating.\nBEAST requires rooted, bifurcating (binary) trees.", "Illegal user-specified starting tree", JOptionPane.ERROR_MESSAGE);
            userTreeCombo.setSelectedItem(NO_TREE);
            partitionTreeModel.setUserStartingTree(null);
        }
    }
}
Also used : 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